Answer the question
In order to leave comments, you need to log in
How to fix bug when approximating contours in OpenCV?
You need to find rectangles in the image. After the contours are closed, I try to approximate each of them, but an error occurs. How to fix and what is the problem?
#Отрывок кода
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (7, 7))
closed = cv2.morphologyEx(canny, cv2.MORPH_CLOSE, kernel)
cnts = cv2.findContours(closed.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in cnts:
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
#Вот ошибка
peri = cv2.arcLength(c, True)
cv2.error: OpenCV(3.4.4) C:\projects\opencv-python\opencv\modules\imgproc\src\shapedescr.cpp:237: error: (-215:Assertion failed) count >= 0 && (depth == CV_32F || depth == CV_32S) in function 'cv::arcLength'
Answer the question
In order to leave comments, you need to log in
Must not be used
But this line to define an array with the coordinates of the contours
_, cont, hier = cv2.findContours(closed.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question