How do I display the contours of an image using OpenCV Python?

前端 未结 3 893
逝去的感伤
逝去的感伤 2020-12-31 09:23

I followed this tutorial from official documentation. I run their code:

import numpy as np
import cv2

im = cv2.imread(\'test.jpg\')
imgray = cv2.cvtColor(im         


        
3条回答
  •  一个人的身影
    2020-12-31 09:57

    You should add cv2.imshow("Title", img) at the end of your code. It should look like this:

    import numpy as np
    import cv2
    
    im = cv2.imread('test.jpg')
    imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
    ret,thresh = cv2.threshold(imgray,127,255,0)
    contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    cv2.drawContours(im, contours, -1, (0,255,0), 3)
    cv2.imshow("title", im)
    cv2.waitKey()
    

提交回复
热议问题