日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 扫描仪_基于Opencv和Python的多选扫描仪

發(fā)布時間:2025/3/8 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 扫描仪_基于Opencv和Python的多选扫描仪 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

首先,我檢測到圖像右側(cè)的20個黑框,然后將x和寬度添加到列表中:image = cv2.imread(args["image"])

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

(_, thresh) = cv2.threshold(gray, 220, 255,cv2.THRESH_BINARY)

kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1, 1))

closed = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)

dilation = cv2.dilate(closed,None,iterations = 5)

(_,contours,_)=cv2.findContours(dilation.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)

sorted_rows = sorted(contours, key = cv2.contourArea, reverse = True)[1:21]

for idx,row in enumerate(sorted_rows):

(_x,y,w,h) = cv2.boundingRect(row)

rows.append([(y),(y+h)])

然后我檢測到五列:(_, thresh) = cv2.threshold(gray, 127, 255,cv2.THRESH_BINARY)

closed = cv2.erode(thresh, None, iterations = 4)

(_,contours,_)=cv2.findContours(closed.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)

sorted_cols = sorted(contours, key = cv2.contourArea, reverse = True)[1:6]

for col in sorted_cols:

# add to list

(x,y,w,h) = cv2.boundingRect(col)

cols.append([(x),(x+w)])

接下來,我分別按照x和y的位置對這兩個列表進行排序:cols = sorted(cols, key = lambda x: x[0])

rows = sorted(rows, key = lambda x: x[0])

然后我遍歷columns列表和rows列表來構(gòu)建交叉點的坐標,在那里我可以找到五個復(fù)選框count_iterations = 0

for col in cols:

for row in rows:

count_iterations +=1

crop = image[row[0]:row[1], col[0]: col[1]]

denoised = cv2.fastNlMeansDenoisingColored(crop,None,10,10,7,21)

edges = cv2.Canny(denoised,220,250)

closed = cv2.dilate(edges, None, iterations = 1)

(_,contours,_)= cv2.findContours(closed.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)

checkboxes = sorted(contours, key = cv2.contourArea, reverse = True)[:5]

crdn_checkboxes = []

for check_box in checkboxes:

crdn_checkboxes.append(cv2.boundingRect(check_box))

最后,我按像素的位置對它們進行排序,最后選中它們的一個:crdn_checkboxes = sorted(crdn_checkboxes, key = lambda x: x[0])

for idx, crdn in enumerate(crdn_checkboxes):

x,y,w,h = crdn

check_box = crop[y:y+h,x:x+w]

check_box_img_gray = cv2.cvtColor(check_box, cv2.COLOR_BGR2GRAY)

(_, thresh) = cv2.threshold(check_box_img_gray,200,255,cv2.THRESH_BINARY)

height,width = thresh.shape[:2]

tot_px = height * width

checked_box = cv2.countNonZero(thresh) / float(tot_px)

if checked_box < 0.6:

print "Found"

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的python 扫描仪_基于Opencv和Python的多选扫描仪的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。