python - 如何以编程方式查找图像中特定特征的像素位置?

标签 python opencv image-processing

我正在使用 OpenCV 和 Python 构建一个自动电表/煤气表读取器。我已经知道用网络摄像头拍照了:

enter image description here

然后我可以使用精细变换来展开图像(改编自 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

..这给了我这样的图像:

enter image description here

我仍然需要使用某种 OCR 例程来提取文本,但首先我想自动化识别要应用仿射变换的像素位置的部分。因此,即使有人敲了网络摄像头,软件也不会停止运行。

最佳答案

由于您的图像几乎是平面的,您可以考虑寻找 homography在您从网络摄像头获得的图像和所需图像(在直立位置)之间。

编辑:这会将图像旋转到直立位置。一旦你注册了你的图像(将它放在直立位置),你可以进行行向或列向投影(将列上的所有像素相加得到一个向量,将行中的所有像素相加得到一个向量向量)。您可以使用这些矢量找出颜色跳跃的位置,并在那里进行裁剪。

或者,您可以使用 Hough 变换,它会在图像中生成线条。如果这样做,您可能可以不注册图像而逃脱。

关于python - 如何以编程方式查找图像中特定特征的像素位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17259232/

相关文章:

c++ - boost/ python : How can I use/convert extracted objects?

python - 按第二个元素对元组列表进行分组,取第一个元素的平均值

python - 从包含字符串和 float 的 pandas 列中删除科学记数法

java - 如何减少位平面代码的计算时间

opencv - 如何将opencv添加到Turbo C++?

java 内存溢出错误 : memory usage is too high: physicalBytes > maxPhysicalBytes javacpp Pointer deallocator()

image-processing - 如何在 Swift for iOS 中加载和编辑像素级别的位图文件?

python - 在Python中缩小图像的一部分

python - 使用 Scipy 进行卡方检验的 P 值

python - 如何摆脱轮廓线以外的骨架线?