我正在使用OpenCV和Python构建一个自动化的电力/燃气仪表读取器。目前已经成功使用网络摄像头拍摄到了图像:
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程序提取文本,但首先我想自动化识别哪些像素位置应用仿射变换的部分。这样,如果有人碰到网络摄像头,它不会停止软件的工作。
homography
的基于Python的示例吗?OpenCV网站上的示例是针对C++版本的,我很难将其翻译成Python... - Jon Cage