繁体   English   中英

OpenCV / Python:图像轮廓不显示

[英]OpenCV/Python: Image contours don't appear

我正在用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]")

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

因为您编写了imgSrc

隐蔽的跟随线

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

进入

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM