Jon*_*age 6 python opencv image-processing
我正在使用OpenCV和Python构建自动电/气表读数器.我已经使用网络摄像头拍摄:

然后我可以使用afine变换来取消图像的变形(这个例子的改编):
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
Run Code Online (Sandbox Code Playgroud)
..这给我一个像这样的图像:

我仍然需要使用某种OCR例程来提取文本,但首先我想自动化识别应用仿射变换的像素位置的部分.因此,如果有人敲击网络摄像头,它不会阻止软件正常工作.