简体   繁体   中英

OpenCV/Python: Image contours don't appear

I'm developing a script in OpenCV/Python that adding Tesseract reads something from an image. At the moment, I'm trying to implement the use of the function drawContours, but in the output, it simply don't appear the contours like I asked.

Before saying something about my question, keep in mind that I've searched in Stack, all the questions before asking this one. I've tried many alternative ways to do the contours (like shown in the official documentation of OpenCV) and none of them seems to solve my problem.

Without futher to do, here's my code:

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]")

Thanks for the attention. Have a nice day.

Because you write imgSrc .

covert following line

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

into

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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