Ask Your Question

TheCakeLover's profile - activity

2020-12-02 21:52:43 -0600 marked best answer convexityDefects errors

Dear all,

I am constantly running into problems using convexityDefects(). I have created an example image (see below), and OpenCV correctly finds all contours and convex hulls, but still, when running the line of code I commented out it throws the error

error: (-215:Assertion failed) hpoints > 0 in function 'cv::convexityDefects'

Where is the error? Is it related to the image depth?

import cv2
import imutils
import numpy as np

black = np.zeros((500,500), dtype=np.uint8)
cv2.rectangle(black, (60,60), (440, 440), (255,255,255), 4)
poly = np.array([[80,80], [110, 110], [80, 200], [300, 110]])
cv2.drawContours(black, [poly], 0, (255, 255, 255), 3)
cnts = cv2.findContours(black, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)



for c in cnts:
    toShow = cv2.cvtColor(black.copy(), cv2.COLOR_GRAY2BGR)
    cv2.drawContours(toShow, [c], 0, (0,255,0), 2)
    hull = cv2.convexHull(c)
    cv2.drawContours(toShow, [hull], 0, (0,0,255), 1)

  # print("conv defects", cv2.convexityDefects(c, hull))

    cv2.imshow("cont", toShow)
    cv2.waitKey()

test image

test image

convex hull

inner contour with correct convex hull

2020-04-16 12:29:55 -0600 asked a question drawContours() minimum line thickness

drawContours() minimum line thickness Dear all, is there a way to reduce the thickness of drawContours() further than 0

2020-04-10 01:54:59 -0600 commented answer convexityDefects errors

Oh god, you can't imagine how often I read the documentation...thank you very much!

2020-04-10 01:53:24 -0600 received badge  Enthusiast
2020-04-08 03:47:43 -0600 asked a question convexityDefects errors

convexityDefects errors Dear all, I am constantly running into problems using convexityDefects(). I have created an exa

2020-04-07 09:40:54 -0600 asked a question hpoints > 0: Error using convexityDefects()

hpoints > 0: Error using convexityDefects() Dear all, I am grabbing the hull of a contour by using the convexHull()

2020-04-03 13:45:46 -0600 commented answer Is the output of approxPolyDP(c) a subset of the input contour c?

Thank you very much! May I follow up with a slightly unrelated question? As I have feared, my code has to be wrong at so

2020-04-03 03:32:11 -0600 received badge  Student (source)
2020-04-02 12:02:21 -0600 commented answer Is the output of approxPolyDP(c) a subset of the input contour c?

Thank you very much! May I follow up with a slightly unrelated question? As I have feared, my code has to be wrong at so

2020-04-02 12:00:03 -0600 received badge  Supporter (source)
2020-04-02 11:59:47 -0600 marked best answer Is the output of approxPolyDP(c) a subset of the input contour c?

I'm determining corner points using an approximated version of contour c, then try to find the index of the found corner in the original contour using numpy.where(). But for some points no index can be found, meaning the point seems not to be in the original contour.

As I understand the underlying DP-algorithm, no new points are added, is that correct?

Cheers!

2020-04-02 11:59:47 -0600 received badge  Scholar (source)
2020-04-02 11:00:22 -0600 asked a question Is the output of approxPolyDP(c) a subset of the input contour c?

Is the output of approxPolyDP(c) a subset of the input contour c? I'm determining corner points using an approximated ve