Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 2088

Need find Convex Hull in Python for already found Convex Hull point , draw outer most Convex Hull and get it's X and Y co-ordinates

$
0
0
Below is my program, I am trying to find the Convex Hull of the image and send that convex Hull points again to OpenCV Convex Hull to find the outermost Convex Hull of it . import cv2 import numpy as np # Load the image img1 = cv2.imread(r'test.tif') # Convert it to greyscale img = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY) # Threshold the image ret, thresh = cv2.threshold(img,50,255,0) # Find the contours contours, hierarchy = cv2.findContours(thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) cv2.drawContours(img1, contours, -1, (255, 0, 0), 2) hull=np.array([]) for i in range(len(contours)): hullv=cv2.convexHull(contours[i]) hull=np.append(hull,hullv) cv2.drawContours(img1, [hullv], 0, (255, 0, 0), 2) conv2=cv2.convexHull(hull) cv2.drawContours(img1, conv2, -1, (255, 0, 0), 2) cv2.imwrite(r"contours2.png",img1) I am seeing below error when I do this. Traceback (most recent call last): File "C:/TestCode/DocumentLayoutDetection/ConvexHull.py", line 17, in conv2=cv2.convexHull(hull) cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\convhull.cpp:137: error: (-215:Assertion failed) total >= 0 && (depth == CV_32F || depth == CV_32S) in function 'cv::convexHull'

Viewing all articles
Browse latest Browse all 2088

Trending Articles