Python,OpenCVともに使うのが初めてです。
現在、類似画像検索のようなものを作っています。
そこで、画像の一部(円弧型)にある処理(ただ白いpixelを数えるだけ)をしたいと思っています。
どなたか、教えていただけるとありがたいです...
参考までに現在のコードを置いておきます。
python
1import cv2 2import numpy as np 3import sys 4 5def showImage(img): 6 cv2.imshow('result', img) 7 cv2.waitKey(0) 8 cv2.destroyAllWindows() 9 10def getLocalFeature(img): 11 eight_bit = 0 12 for (line, row, i) in [(x+1, y, 0), (x+1, y-1, 1), (x, y-1, 2), (x-1, y-1, 3), (x-1, y, 4), (x-1, y+1, 5), (x, y+1, 6), (x+1, y+1, 7)]: 13 if img[line, row] == 255: 14 eight_bit += 2**i 15 return eight_bit 16 17#def getGlabalFeature(img): 18 19 20################################################# 21local_feature = [] 22global_feature = [] 23 24#画像の読み込み 25img = cv2.imread('./images/s01.png') 26#平滑化 27g_img = cv2.bilateralFilter(img, 9, 75, 75) 28#canny edge 29c_img = cv2.Canny(g_img, 50, 150) 30 31for y in range(0, c_img.shape[1] - 1): 32 for x in range(0, c_img.shape[0] - 1): 33 local_feature.append(getLocalFeature(c_img)) 34 35 36#この円弧にだけ処理をしたい 37#画像,中心座標,(長径・短径),回転角度,円弧開始角度,円弧終了角度,色 38cv2.ellipse(c_img, (50, 100), (100, 100), 0, 0, -22.5, (255, 255, 0)) 39 40#この処理 41#cv2.countNonZero(c_img) 42 43 44 45
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/01/03 02:38