I have an issue in my code and can't find a proper solution for it. I am using Python 2.7.10 and OpenCV 3.0. I read two images and want to match one of the pictures(a template) with the contours from the other but I get the following error:
error: (-215) count >= 0 && (depth == CV_32F || depth == CV_32S) in function cv::arcLength
My code looks like this:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.bilateralFilter(gray, 11, 10, 17)
edges = cv2.Canny(gray, 100, 20)
contours,hierarchy, _ = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
ret = cv2.matchShapes(c, compare, 1, 0.0)
if ret < 0.5:
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
Both gray and compare images are grayscale. The error is obviously saying that I need my array to be of floats or double, but I got no idea how to convert it in python and I've found many examples with the function working and the code seems almost the same.
Furthermore, in most applications I've noticed that on most examples the findContours() functions returns 2 values, but I get an error if I don't give it 3.
Please help me find the issue!