python-opencv2利用cv2.findContours()函数来查找检测物体的轮廓

参考:https://blog.csdn.net/hjxu2016/article/details/77833336

import cv2

img=cv2.imread("female49kg.jpg")

gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,binary=cv2.threshold(gray,127,255,cv2.THRESH_BINARY)

contours,hierarchy=cv2.findContours(binary,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img,contours,-1,(0,0,255),3)

cv2.imshow("img",img)
cv2.waitKey(0)


效果如下
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_21237549/article/details/121162246