개정판 1b1d50ff
Apply blur when loading image file
DTI_PID/DTI_PID/AppDocData.py | ||
---|---|---|
224 | 224 |
import cv2 |
225 | 225 |
|
226 | 226 |
if self._imgSrc is None and self._imgFilePath is not None and os.path.isfile(self._imgFilePath): |
227 |
self._imgSrc = cv2.threshold(cv2.cvtColor(cv2.imread(self._imgFilePath, 1), cv2.COLOR_BGR2GRAY), 127, 255, cv2.THRESH_BINARY)[1] |
|
227 |
self._imgSrc = cv2.cvtColor(cv2.imread(self._imgFilePath), cv2.COLOR_BGR2GRAY) |
|
228 |
blur = cv2.GaussianBlur(self._imgSrc , (5,5),0) |
|
229 |
self._imgSrc = cv2.threshold(self._imgSrc , 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1] |
|
228 | 230 |
|
229 | 231 |
return self._imgSrc |
230 | 232 |
|
DTI_PID/DTI_PID/Commands/FitImageCommand.py | ||
---|---|---|
67 | 67 |
black = 0 |
68 | 68 |
|
69 | 69 |
image = self.convertQImageToMat(self.imageViewer.image()) |
70 |
image = cv2.threshold(cv2.cvtColor(image, cv2.COLOR_BGR2GRAY), 127, 255, cv2.THRESH_BINARY)[1]
|
|
70 |
image = cv2.threshold(cv2.cvtColor(image, cv2.COLOR_BGR2GRAY), 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]
|
|
71 | 71 |
width, height = image.shape[::-1] |
72 | 72 |
|
73 | 73 |
minX = sys.maxsize |
DTI_PID/DTI_PID/DTI_PID.py | ||
---|---|---|
336 | 336 |
return |
337 | 337 |
# up to here |
338 | 338 |
|
339 |
sym = cv2.imread(symbolPath, 1) |
|
340 |
symGray = cvtGrayImage(sym) |
|
339 |
symGray = cvtGrayImage(cv2.imread(symbolPath, 1)) |
|
341 | 340 |
## TODO: 이진화 시켰을때 심볼이 검출되지 않음 |
342 | 341 |
## symGray = cv2.threshold(cvtGrayImage(sym), 127, 255, cv2.THRESH_BINARY)[1] |
343 | 342 |
## cv2.imshow('symbol', symGray) |
DTI_PID/DTI_PID/QSymbolEditorDialog.py | ||
---|---|---|
462 | 462 |
@brief Hand Tool Button Clicked |
463 | 463 |
''' |
464 | 464 |
def handToolClickEvent(self, event): |
465 |
print("hand tool clicked") |
|
466 | 465 |
self.ui.imageView.command = HandCommand.HandCommand(self.ui.imageView) |
467 | 466 |
|
468 | 467 |
''' |
DTI_PID/DTI_PID/QtImageViewer.py | ||
---|---|---|
186 | 186 |
Without any arguments, loadImageFromFile() will popup a file dialog to choose the image file. |
187 | 187 |
With a fileName argument, loadImageFromFile(fileName) will attempt to load the specified image file directly. |
188 | 188 |
""" |
189 |
|
|
190 |
if len(fileName) == 0: |
|
191 |
options = QFileDialog.Options() |
|
192 |
options |= QFileDialog.DontUseNativeDialog |
|
193 |
if QT_VERSION_STR[0] == '4': |
|
194 |
fileName = QFileDialog.getOpenFileName(self, "Open image file", os.getcwd() if folder == '' else folder, "Image files(*.png *.jpg)", options=options) |
|
195 |
elif QT_VERSION_STR[0] == '5': |
|
196 |
fileName, dummy = QFileDialog.getOpenFileName(self, "Open image file", os.getcwd() if folder == '' else folder, "Image files(*.png *.jpg)", options=options) |
|
197 |
if len(fileName) and os.path.isfile(fileName): |
|
198 |
'''TODO: TEST CODE |
|
199 |
cvImg = cv2.imread(fileName) |
|
200 |
cvImg = cv2.threshold(cvImg, 127, 255, cv2.THRESH_BINARY)[1]#|cv2.THRESH_OTSU)[1] |
|
201 |
cv2.imwrite('d:/temp/temp.png', cvImg) |
|
202 |
#image = QImage(cvImg, cvImg.shape[1],\ |
|
203 |
# cvImg.shape[0], cvImg.shape[1],QImage.Format_Mono) |
|
204 |
''' |
|
205 |
image = QImage(fileName) |
|
206 |
self.setImage(image) |
|
189 |
try: |
|
190 |
if len(fileName) == 0: |
|
191 |
options = QFileDialog.Options() |
|
192 |
options |= QFileDialog.DontUseNativeDialog |
|
193 |
if QT_VERSION_STR[0] == '4': |
|
194 |
fileName = QFileDialog.getOpenFileName(self, "Open image file", os.getcwd() if folder == '' else folder, "Image files(*.png *.jpg)", options=options) |
|
195 |
elif QT_VERSION_STR[0] == '5': |
|
196 |
fileName, dummy = QFileDialog.getOpenFileName(self, "Open image file", os.getcwd() if folder == '' else folder, "Image files(*.png *.jpg)", options=options) |
|
197 |
if len(fileName) and os.path.isfile(fileName): |
|
198 |
cvImg = cv2.cvtColor(cv2.imread(fileName), cv2.COLOR_BGR2GRAY) |
|
199 |
blur = cv2.GaussianBlur(cvImg, (5,5),0) |
|
200 |
cvImg = cv2.threshold(cvImg, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1] |
|
201 |
bytesPerLine = cvImg.shape[1] |
|
202 |
image = QImage(cvImg.data, cvImg.shape[1], cvImg.shape[0], bytesPerLine, QImage.Format_Indexed8) |
|
203 |
self.setImage(image) |
|
204 |
except Exception as ex: |
|
205 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
207 | 206 |
|
208 | 207 |
return fileName |
209 | 208 |
|
... | ... | |
363 | 362 |
else: |
364 | 363 |
if self.command is not None: |
365 | 364 |
self.command.execute(['keyPressEvent', event, []]) |
366 |
|
|
367 | 365 |
|
368 | 366 |
QGraphicsView.keyPressEvent(self, event) |
369 | 367 |
except Exception as ex: |
내보내기 Unified diff