Contour Perimeter Failed - Type Error ( curve is not a numpy array, neither a scalar)

asked 2017-10-25 04:41:01 -0500

glukon gravatar image

I'm trying to find Contours with Python OpenCV 2.4.3.link

The next step is to find Contour Perimeter and Contour Approximation. Here is my Code:

c_blue, h_blue = cv2.findContours(edges_blue, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
conts_blue = sorted(c_blue, key = cv2.contourArea, reverse = True)[:self.MAX_SUM_OF_DET_CNTS]
c_yell, h_yell = cv2.findContours(edges_yell, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
conts_yell = sorted(c_yell, key = cv2.contourArea, reverse = True)[:self.MAX_SUM_OF_DET_CNTS]

for blueContour in conts_blue:
    if (cv2.contourArea(blueContour) > 10000):
        conts_blue.remove(blueContour)
for yellowContour in conts_yell:
    if (cv2.contourArea(yellowContour) > 10000):
        conts_yell.remove(yellowContour)

self.perim_blue = cv2.arcLength(conts_blue, True)
self.appro_blue = cv2.approxPolyDP(conts_blue, 0.1 * perim_blue, True)
self.perim_yell = cv2.arcLength(conts_yell, True)
self.appro_yell = cv2.approxPolyDP(conts_yell, 0.1 * perim_yell, True)

cv2.drawContours(self.image, conts_blue, 0, (255,255,0), 1)
cv2.drawContours(self.image, conts_yell, 0, (0,0,255), 1)

cv2.imshow("Result", self.image)
cv2.waitKey(0)

I get following Error after running:

self.perim_blue = cv2.arcLength(conts_blue, True)
TypeError: curve is not a numpy array, neither a scalar

In my case, conts_blue is of len 3, conts_yell is of len 2 So I'm working with arrays here, arcLength wants an InputArray curve but what does the documentation means with curve. I'm bit confused so please help me to understand this, maybe give me a good solution. Btw.. To change line 2 and 4 into conts_blue without [:MaxVal], I don't know if this would be nice because I need this upper bound of max contours detected.

Thanks :-)

edit retag flag offensive close merge delete

Comments

print (np.shape(conts_blue), np.shape(conts_yell)) gives ((3,), (3,))

PS: import numpy as np

glukon gravatar imageglukon ( 2017-10-25 04:47:08 -0500 )edit

I need to see edges_blue.

supra56 gravatar imagesupra56 ( 2017-10-26 07:40:36 -0500 )edit