Найти общие точки между контуром и выпуклой оболочкой изображения - PullRequest
0 голосов
/ 05 ноября 2019

Мне нужно получить общие точки между контуром и выпуклым корпусом изображения руки с помощью python opencv.

Я вычислил контур и выпуклый корпус обоих. И не понимаю, как я буду вычислять общие точки между этими двумя.

#import numpy;
import cv2
# -*- coding: utf-8 -*-
"""
Spyder Editor



"""

#import imutils
from PIL import Image
import cv2
import numpy as np

# load the image, convert it to grayscale, and blur it slightly
image = cv2.imread('D:\SHROUTI\Miscellaneous\hand_01.png')

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (5, 5), 0)

# threshold the image, then perform a series of erosions +
# dilations to remove any small regions of noise
thresh = cv2.threshold(gray, 45, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.erode(thresh, None, iterations=2)
thresh = cv2.dilate(thresh, None, iterations=2)

# find contours in thresholded image, then grab the largest
# one
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] 
c = max(cnts, key=cv2.contourArea)
#sorting contours wrt contour area
cnt = sorted(cnts, key=cv2.contourArea, reverse=True)
#getting the largest contour
#largestcontour = cnt[0][1]
#for c in cnts:(this was in the original)
    # compute the center of the contour
M = cv2.moments(c)
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])

    # draw the contour and center of the shape on the image
cv2.drawContours(image, cnt[0], -1, (0, 255, 0), 2)

cv2.circle(image, (cX, cY), 7, (255, 255, 255), -1)
cv2.putText(image, "center", (cX - 20, cY - 20),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)
 # create hull array for convex hull points
hull = []
hull=cv2.convexHull(cnt[0], returnPoints=False)
Cnt = cnt[0]
pts = np.array(hull)
#defects = cv2.convexityDefects(cnt[0],pts)  
#cv2.drawContours(image, hull, -1, (0, 255, 0), 2)   
#cv2.polylines(image, hull, True, (0, 255, 255), 2)

cv2.imshow("Image", image)
cv2.waitKey(0)
...