Re: [問題] 圖像辨識轉換matrix問題

作者: neil987 (R5大小姐-EX人品崩壞)   2017-06-13 18:07:46
※ 引述《sariel0322 (sariel)》之銘言:
: 如圖
: http://i.imgur.com/3BlTd3Q.jpg
: 我想針對左上、左下、右上右下的圖塊做圖形辨識
: 每一個圖塊中的黑點面積大小做Normalize後
: 每一個圖塊各轉成一個matrix
: 並且可以忽略中間的黑色大十字
: 我原本想要利用PIL搭配座標與像素來計算
: 但發現好像每一個座標為單位的話量會太多
: 因此想請問一下,要怎麼做才能達到我的目的
作者: neil987 (R5大小姐-EX人品崩壞) 看板: Test
標題: [測試] 123
時間: Tue Jun 13 11:47:32 2017
其實我的步驟是反過來
先做找到要辨識的4塊區域,就可以忽略掉中間的大十字
我這邊用python2.7 + opencv3.2 作法給你參考一下
img_r = cv2.resize(img,(0,0),fx=0.3,fy=0.3)
gray = cv2.cvtColor(img_r, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (5,5), 1)
ret, binary = cv2.threshold(blur, 127, 255, cv2.THRESH_BINARY)
c_image,contours, hierarchy = cv2.findContours(binary, cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
##findContours裡參數的意義請自己找
##img1 = img_r.copy()
##cv2.drawContours(img1, contours, -1, (0,0,255), 2)
##cv2.imshow('contours0', img1)
##觀察第一次找到的輪廓
## http://i.imgur.com/cLN30Ct.jpg
##這裡找到的contours太複雜,需要做第二次處理
new = []
##輪廓簡化,函數與參數自己找
for i in range(len(contours)):
cnt = contours[i]
area = cv2.contourArea(cnt)
if(area < 500):
continue
epsilon = 0.09 * cv2.arcLength(cnt, True)
approx = cv2.approxPolyDP(cnt, epsilon, True)
hull = cv2.convexHull(approx)
rect = cv2.minAreaRect(hull)
box = cv2.boxPoints(rect)
box = np.int0(box)
new.append(box)
cv2.drawContours(img_r, new, -1, (0,0,255), 2)
cv2.imshow('contours1', img_r)
##觀察簡化過的輪廓
##http://i.imgur.com/L0P8bgf.jpg
##print new
##new裡面有四個框框各自對應到的四個座標點
##cv2.imwrite('contour1.jpg',img_r)
cv2.waitKey(0)
cv2.destroyAllWindows()
取得4個roi後,可以再把座標往內縮,減少邊框的干擾
roi = img2[y1+b1:y2+b2, x1+a1:x2+a2]
##http://i.imgur.com/L1Ppbhd.jpg
剩下的找面積就很簡單了
正規化就把所有圓面積除以最大的圓面積
讓所有面積介於0~1之間
自行發揮

Links booklink

Contact Us: admin [ a t ] ucptt.com