代码拉取完成,页面将自动刷新
import cv2
import imutils
import numpy as np
img = cv2.imread('/home/niangu/桌面/答题卡识别/test3/A10.png')
#for i in range(1 ,10):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0.4)#调0.4
dilate = cv2.dilate(blurred, cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3)))
edged = cv2.Canny(dilate, 50, 250, 3)#调100, 250 # 边缘检测
mask = np.zeros(edged.shape, np.uint8)
img2 = img[166:690, 0:500]
edged2 =edged[120:500, 0:700]
for j in range(0, 12):
if j==1:
A = img2[0:400, 5+j*57:38+j*57]
Amask = mask[0:400, 5+j*57:38+j*57]
edged3 = edged2[0:400, 5+j*57:38+j*57]
for i in range(0, 9):
B = A[11+i*39:34+i*39, 0:33]
Bmask = Amask[11+i*39:34+i*39, 0:33]
edged4 = edged3[11+i*39:34+i*39, 0:33]
dif = cv2.subtract(edged4, Bmask)
result = not np.any(dif) # if difference is all zeros it will return False
if result is True:
pass
else:
print(i)
else:
A = img2[0:400, 5 + j * 59:38 + j * 59]
Amask = mask[0:400, 5 + j * 59:38 + j * 59]
edged3 = edged2[0:400, 5 + j * 59:38 + j * 59]
for i in range(0, 9):
B = A[11 + (i * 39):34 + (i * 39), 0:33]
Bmask = Amask[11 + (i * 39):34 + (i * 39), 0:33]
edged4 = edged3[11 + (i * 39):34 + (i * 39), 0:33]
dif = cv2.subtract(edged4, Bmask)
dif = cv2.subtract(edged4, Bmask)
result = not np.any(dif) # if difference is all zeros it will return False
if result is True:
pass
else:
print(i)
cv2.namedWindow('D1', cv2.WINDOW_NORMAL)
cv2.imshow('D1', edged)
cv2.namedWindow('D1A', cv2.WINDOW_NORMAL)
cv2.imshow('D1A', img2)
cv2.waitKey(0)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。