我正在使用OpenCV Python来检测和提取图像中的外部人体轮廓。 有什么方法可以在图像中绘制外部轮廓? Input Image,我得到了输出Output image
import cv2 as cv
import numpy as np
from scipy import ndimage
kernel5x5 = np.full((5, 5), 0.04, dtype = 'float64')
bgrImg = cv.imread('/home/sagar/Image Processing/OpenCV/man1.jpg')
grayImg = cv.cvtColor(bgrImg, cv.COLOR_BGR2GRAY)
height, width = grayImg.shape
resizeImage = cv.resize(bgrImg, (int(height/6), int(width/3)), interpolation = cv.INTER_NEAREST)
grayBlurred = cv.pyrMeanShiftFiltering(resizeImage, 7, 7)
#grayBlurred1 = ndimage.convolve(resizeImage, kernel5x5)
gray = cv.cvtColor(grayBlurred, cv.COLOR_BGR2GRAY)
kernel = np.ones((3, 3), np.uint8)
erode1 = cv.erode(gray, kernel, iterations = 2)
dilate1 = cv.dilate(erode1, kernel, iterations = 2)
ret, thresh = cv.threshold(dilate1, 90, 197, cv.THRESH_BINARY)
_, contours,_ = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_NONE)
mask = np.zeros(resizeImage.shape, dtype="uint8")
for contour in contours:
area = cv.contourArea(contour)
if area > 40:
cv.drawContours(resizeImage, contour, -1,(0, 0, 255), 2)
print("Contours Length is %d " % len(contours))
#cv.imshow(" Gray Image ", gray)
cv.imshow(" Resize Image ", resizeImage)
#cv.imshow(" Blurred Image Edge ", blurredImg)
cv.waitKey()
cv.destroyAllWindows()