Question: OpenCV/Python: Image contours don't appear


OpenCV/Python: Image contours don't appear

Answers 1
Added at 2016-12-01 06:12

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)

Thanks for the attention. Have a nice day.

Answers to

OpenCV/Python: Image contours don't appear

nr: #1 dodano: 2016-12-01 06:12

Because you write imgSrc.

covert following line

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


cv2.imwrite("image_test_contours.jpg", imgDstn)
Source Show
◀ Wstecz