OpenCV / Python:图像轮廓不会出现

时间:2016-12-01 05:30:43

标签: python opencv python-2.x

我正在OpenCV / Python中开发一个脚本,添加Tesseract从图像中读取内容。目前,我正在尝试使用drawContours函数,但在输出中,它根本不像我问的那样出现轮廓。

在谈论我的问题之前,请记住我在Stack中搜索了所有问题,然后再问这个问题。我已经尝试了许多替代方法来完成轮廓(如OpenCV的官方文档中所示),但它们似乎都没有解决我的问题。

如果没有进一步做,这是我的代码:

import numpy as np
import cv2

if __name__ == '__main__':

    gsFactor = 0
    imgSrc = cv2.imread('image_template_match.jpg', gsFactor)
    thresh = 127
    maxValue = 255
    th, imgDstn = cv2.threshold(imgSrc, thresh, maxValue, cv2.THRESH_BINARY)
    imgTemp, contours, hierarchy = cv2.findContours(imgDstn, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    cv2.drawContours(imgDstn, contours, -1, (0, 255, 0), 3)
    cv2.imwrite("image_test_contours.jpg", imgSrc)
    print("[Done]")

感谢您的关注。祝你有愉快的一天。

1 个答案:

答案 0 :(得分:0)

因为你写了imgSrc

隐蔽后续行

cv2.imwrite("image_test_contours.jpg", imgSrc)

进入

cv2.imwrite("image_test_contours.jpg", imgDstn)
相关问题