代码拉取完成,页面将自动刷新
import cv2
import imutils
import numpy as np
img = cv2.imread('/home/niangu/桌面/答题卡识别/a答题卡特征提取检测24.png')
#for i in range(1 ,10):
print(img.shape)
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, 60, 250, 3)#调100, 250 # 边缘检测
mask = np.zeros(edged.shape, np.uint8)
img2 = img[47:200, 0:200]
edged2 =edged[47:200, 0:200]
for i in range(0, 1):
if i<6:
B = img2[0:153, 3+i*16+i:13+16*i+i]
Amask = mask[0:153, 3+i*16+i:13+16*i+i]
edged3 = edged2[0:153, 3+i*16+i:13+16*i+i]
#cv2.namedWindow('D%d'%(i), cv2.WINDOW_NORMAL)
#cv2.imshow('D%d'%(i), B)
if i>5 and i!=11:
B = img2[0:153, 3 + i * 16 +i-1+1:13 + 16 * i + i-2-3]
Amask = mask[0:153, 3 + i * 16 +i-1+1:13 + 16 * i + i-2-3]
edged3 = edged2[0:153, 3 + i * 16 +i-1+1:13 + 16 * i + i-2-3]
#cv2.namedWindow('D%d' % (i), cv2.WINDOW_NORMAL)
#cv2.imshow('D%d' % (i), B)
if i == 11:
B = img2[0:153, 186+1:198]
Amask = mask[0:153, 186+1:198]
edged3 = edged2[0:153, 186+1:198]
cv2.namedWindow('D%d' % (i), cv2.WINDOW_NORMAL)
cv2.imshow('D%d' % (i), B)
for j in range(0, 10):
C = B[2+j*15:8+j*15, 0:9]
print("AAAAAAAAAAAA:", 2+j*15, 8+j*15)
Cmask = AmaskC = B[2+j*15:8+j*15, 0:9]
edged4 = edged3C = B[2+j*15:8+j*15, 0:9]
#cv2.namedWindow('D%d%d' % (i, j), cv2.WINDOW_NORMAL)
#cv2.imshow('D%d%d' % (i, j), C)
dif = cv2.subtract(edged4, Cmask)
result = not np.any(dif) # if difference is all zeros it will return False
if result is True:
pass
else:
cv2.rectangle(B, (0, 2+j*16), (9, 8+j*16), (0, 255, 0), 2)
if i == 0:
print(j)
else:
print(j)
# cv2.namedWindow('D%d%d' % (i,j), cv2.WINDOW_NORMAL)
# cv2.imshow('D%d%d' % (i,j), C)
cv2.namedWindow('D1', cv2.WINDOW_NORMAL)
cv2.imshow('D1', edged)
cv2.namedWindow('D1A', cv2.WINDOW_NORMAL)
cv2.imshow('D1A', img)
cv2.namedWindow('D1A1', cv2.WINDOW_NORMAL)
cv2.imshow('D1A1', img2)
cv2.waitKey(0)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。