6
我正在使用OpenCV和Python構建一個自動化電力/燃氣表讀取器。據我得爲拍攝時帶有攝像頭:如何以編程方式查找圖像中特定要素的像素位置?
然後我可以使用仿射變換來unwarp圖像(的this example改編):..這使
def unwarp_image(img):
rows,cols = img.shape[:2]
# Source points
left_top = 12
left_bottom = left_top+2
top_left = 24
top_right = 13
bottom = 47
right = 180
srcTri = np.array([(left_top,top_left),(right,top_right),(left_bottom,bottom)], np.float32)
# Corresponding Destination Points. Remember, both sets are of float32 type
dst_height=30
dstTri = np.array([(0,0),(cols-1,0),(0,dst_height)],np.float32)
# Affine Transformation
warp_mat = cv2.getAffineTransform(srcTri,dstTri) # Generating affine transform matrix of size 2x3
dst = cv2.warpAffine(img,warp_mat,(cols,dst_height)) # Now transform the image, notice dst_size=(cols,rows), not (rows,cols)
#cv2.imshow("crop_img", dst)
#cv2.waitKey(0)
return dst
我的形象是這樣的:
我還需要使用一些提取文本一種OCR例程,但首先我想自動化識別應用仿射變換的像素位置的部分。所以如果有人敲網絡攝像頭,它不會停止軟件的工作。
你有一個如何使用'單應性'的基於python的例子。 OpenCV網站上的例子是針對C++版本的,我很難將其翻譯成Python ... –
不,我只使用C++調用。如果你不能直接在python中工作,你可以用python wrapper將它作爲C擴展。 – Diana