如何从手绘电路的扫描图像中检测逻辑门?
Posted
技术标签:
【中文标题】如何从手绘电路的扫描图像中检测逻辑门?【英文标题】:How to detect logic gates from scanned images of hand drawn circuits? 【发布时间】:2017-01-27 03:56:36 【问题描述】:我们从正确绘制的逻辑电路图的扫描图像开始,我们能够将逻辑门从电路的扫描图像中分离出来,但是我们无法检测到以及如何进一步进行,为此我们使用了 python open cv ,我们上面的代码是
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('logic.png',0)
ret,img2 = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV) # converting the image into binary image.
kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(100,3)) # kernel to detect vertical lines
vertical = cv2.morphologyEx(img2, cv2.MORPH_OPEN, kernel) # applying morphological opening operation to detect vertical lines
vertical = cv2.dilate(vertical,kernel,iterations = 1) #dilate the vertical lines obtained
kernel2 = cv2.getStructuringElement(cv2.MORPH_RECT,(3,100)) # kernel to detect horizontal lines
horizontal = cv2.morphologyEx(img2, cv2.MORPH_OPEN, kernel2) # applying morphological opening operation to detect horizontal lines
horizontal = cv2.dilate(horizontal,kernel2,iterations = 1) #dilate the horizontal lines obtained
cv2.imshow('d',vertical) # show the vertical imag
cv2.imshow('b',horizontal) # show the horizontal image
img = img2 -horizontal - vertical # subtracting horizontal and vertical lines from original image
cv2.imwrite('horizontal.png',horizontal)
cv2.imwrite('vertical.png',vertical)
cv2.imwrite('result.png',img)
cv2.imshow('last',img) # show the resulted image after subtraction
kerne = np.ones((3,3),np.uint8) # kernel to remove the noise from the last image
opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kerne) # applying opening morphological operation to remove the noise from the image
cv2.imshow('opening',opening) # show the resulted image after removing noise
cv2.imwrite('noise_removal.png',opening)
cv2.waitKey(0)
检查下面的结果并建议如何进一步从手绘电路的扫描图像中检测逻辑门?
代码结果如下:
1) 输入图片:
2) 输出图像(代码结果):
【问题讨论】:
链接上看不到结果图片 您想只检测门的类型并将它们放入数组中,或者您想通过图像分析创建图形(树)? @Anatoly 结果图像链接现已修复。我们想先检测门,然后分析电路的表达式。 结果图像仍然不可见。 @krok 结果图片已经重新上传,结果图片的链接是Result,它是根据上面应用的操作组合的四张图片。 【参考方案1】:逻辑门都具有相同的大小。我会这样做:
-
白色区域的连接组件标签。
分离/隔离
按大小过滤标签。
(可选)所有逻辑门都会接触到右侧的微小白色图案/标签。
【讨论】:
以上是关于如何从手绘电路的扫描图像中检测逻辑门?的主要内容,如果未能解决你的问题,请参考以下文章