1
我們從邏輯電路的正確繪製圖的掃描圖像開始,我們能夠將邏輯門與電路的掃描圖像分開,但是我們無法檢測到以及如何進一步操作,因此我們使用了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結果圖像鏈接現已修復。我們首先要檢測門電路,然後分析電路的表達式。 –