개정판 0f542e23
...
DTI_PID/DTI_PID/QSymbolEditorDialog.py | ||
---|---|---|
31 | 31 |
QDialog.__init__(self, parent) |
32 | 32 |
|
33 | 33 |
try: |
34 |
''' |
|
35 |
#cvImage = self.convertQImageToMat(image) |
|
36 |
cvImage = cv2.cvtColor(self.convertQImageToMat(image), cv2.COLOR_BGR2GRAY) |
|
37 |
binaryImg,mask = cv2.threshold(cvImage, 127, 255, cv2.THRESH_BINARY)# + cv2.THRESH_OTSU) |
|
38 |
|
|
39 |
contourImg = np.ones(cvImage.shape, np.uint8) |
|
40 |
|
|
41 |
_image, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) |
|
42 |
maxArea = None |
|
43 |
maxAreaContour = None |
|
44 |
for contour in contours: |
|
45 |
area = cv2.contourArea(contour, True) |
|
46 |
#cv2.drawContours(contourImg, [contour], -1, 0, -1) |
|
47 |
cv2.drawContours(contourImg, [contour], -1, 255, -1) |
|
48 |
#maxArea = area |
|
49 |
#maxAreaContour = contour |
|
50 |
|
|
51 |
for contour in contours: |
|
52 |
area = cv2.contourArea(contour, True) |
|
53 |
if area < 0: |
|
54 |
cv2.drawContours(contourImg, [contour], -1, 255, -1) |
|
55 |
|
|
56 |
cv2.imwrite('d:/temp/temp.png', contourImg) |
|
57 |
|
|
58 |
self.image = QImage(contourImg, contourImg.shape[1],\ |
|
59 |
contourImg.shape[0], contourImg.shape[1], QImage.Format_Mono) |
|
60 |
|
|
61 |
#self.image = QImage(contourImg, contourImg.shape[1],\ |
|
62 |
# contourImg.shape[0], contourImg.shape[1] * 3, QImage.Format_RGB888) |
|
63 |
''' |
|
64 |
|
|
65 | 34 |
self.image = image |
66 | 35 |
self.selectedSymbol = selectedSymbol |
67 | 36 |
self.project = project |
... | ... | |
402 | 371 |
if not os.path.exists(imageLocation): |
403 | 372 |
os.makedirs(imageLocation) |
404 | 373 |
|
374 |
''' |
|
375 |
arr = self.convertQImageToMat(image) |
|
405 | 376 |
b = image.bits() |
406 | 377 |
# sip.voidptr must know size to support python buffer interface |
407 | 378 |
b.setsize(image.height() * image.width() * image.depth()) |
408 | 379 |
arr = np.frombuffer(b, np.uint8).reshape((image.height(), image.width(), image.bitPlaneCount())) |
409 | 380 |
img = cv2.threshold(cv2.cvtColor(arr, cv2.COLOR_BGR2GRAY), 127, 255, cv2.THRESH_BINARY)[0] |
410 | 381 |
cv2.imwrite(imagePath, img) |
382 |
''' |
|
411 | 383 |
|
412 |
#image.save(imagePath, 'PNG')
|
|
384 |
image.save(imagePath, 'PNG') |
|
413 | 385 |
|
414 | 386 |
svgLocation = os.path.join(self.project.getSvgFilePath(), fileType) |
415 | 387 |
if not os.path.exists(svgLocation): |
내보내기 Unified diff