使用python OpenCv从手绘逻辑门图中获取布尔表达式

时间:2019-01-31 13:27:09

标签: python-3.x opencv image-processing

Input hand drawn logic gate diagram

通过使用张量流,我确定了所有的门,字母和节点。 在识别上述所有组件时,它将在每个组件周围绘制一个矩形框。

因此,在下面的数组中,它包含所有检测到的组件的列表。每个列表按以下顺序组成。

Name of component 

X, Y coordinates of top  left corner of rectangle 

X, Y coordinates of right bottom of rectangle 

节点(黑点)用于指示一条线上的桥梁,但不交叉。

所有上述组件的数组。

labels =[['NODE',(1002.9702758789062, 896.4686675071716), (1220.212585389614, 1067.1142654418945)], ['NODE',(1032.444071739912, 635.7160077095032),(1211.6839590370655, 763.4382424354553)],['M', (57.093908578157425,607.6229677200317),(311.9765570014715,833.807623386383)],['NODE', (344.5295810997486, 806.3690414428711), (501.8982524871826, 930.6454839706421)], ['Z', (21.986433800309896, 1327.9791088104248), (266.36098374426365, 1565.158670425415)], ['OR', (476.0066536962986, 574.401759147644), (918.3125713765621, 1177.1423168182373)], ['NODE', (333.50814148783684, 1058.0092916488647), (497.6142471432686, 1202.9034795761108)], ['K', (37.06201596558094, 870.0414619445801), (311.77860628068447, 1105.8665227890015)], ['AND', (665.9987451732159, 1227.940999031067), (1062.7052736580372, 1594.6843948364258)],['AND', (1373.9987451732159, 204.940999031067), (1703.7052736580372, 612.6843948364258)], ['NOT', (694.2882044911385, 260.5083291530609), (1027.812717139721, 450.35294365882874)], ['XOR', (2027.6711627840996, 593.0362477302551), (2457.9011510014534, 1093.9836854934692)], ['J', (85.69029207900167, 253.8458535671234), (334.48535946011543, 456.5887498855591)], ['OUTPUT', (2657.3825285434723, 670.8418045043945), (2929.8974316120148, 975.4852895736694)]]

然后,通过使用线路检测算法,我确定了连接每个组件的所有17条线路。 Image of all the lines (17 pink color lines). 以上所有17条线都作为数组列表,这些线的顺序不正确,每条线都有2个端点。

lines = [[(60, 1502), (787, 1467)], [(125, 1031), (691, 988)], [(128, 772), (685, 758)], [(131, 336),(709,347)], [(927,350),(1455, 348)],  [(400, 1361), (792, 1369)], [(834, 843), (2343, 939)], [(915, 1430), (1119, 1424)], [(1125, 468), (1453, 470)],  [(1587, 399), (1911, 405)], [(1884, 755), (2245, 814)],[(2372, 831), (2918, 859)], [(1891, 397), (1901, 767)],  [(1138, 457), (1128, 738)], [(441, 738), (421, 903)], [(1125, 946), (1101, 1437)], [(420, 1098), (408, 1373)]] 

Lines explain diagram 连接这些线路时,必须考虑以下情形。 Scenario to consider when connecting lines 这意味着节点用于指示没有交叉线的桥梁。

M是与门的输入,(M.Z)是另一个与门的输入。

那么如何使用上述2个数组和上述情况来生成以下布尔表达式? 而且,它可以为所有七个逻辑门导出。

可以假设图像总是从左到右读取。 enter image description here

0 个答案:

没有答案