1

I get this error:

OpenCV Error: Unsupported format or combination of formats() in unknown function, file C:\slave\WinInstallerMegaPack\src\opencv\modules\imgproc\src\canny.cpp, line 67 Traceback (most recent call last): edges= cv2.Canny(frame,100,100) cv2.error : C:\ slave\WinInstallerMegaPack\srx\opencv\modules\imgproc\src\canny.cpp:67: error: (-210)

When I run this code:

import cv2 import numpy as np cap = cv2.VideoCapture(0) while(1): _, frame = cap.read() cv2.imshow('Original',frame) edges = cv2.Canny(frame,100,100) cv2.imshow('Edges',edges) k = cv2.waitKey(5) & 0xFF if k == 27: break cv2.destroyAllWindows() cap.release() 
3
  • Please I need the information, it's urgent ! thank you Commented May 18, 2016 at 11:34
  • frame must be grayscale. Use cv2.cvtColor(... cv2.COLOR_BGR2GRAY), before calling Canny Commented May 18, 2016 at 11:46
  • thank you so much !! perfect ! Commented May 18, 2016 at 12:08

1 Answer 1

2

Canny need a grayscale image as input, but your frame is a 3 channel (BGR) image. You need to convert it to grayscale before passing it to Canny:

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) edges = cv2.Canny(gray, 100, 100) 

As a sidenote, remember that Canny thresholds are used for hysteresis, so you may want to set the first_threshold to be something like [0.25 - 0.5] * second_threshold

edges = cv2.Canny(gray, 100, 200) 
Sign up to request clarification or add additional context in comments.

3 Comments

Just a question that doesn't necessarily pertain to this question, but do you know of a way to fill the insides of the detected edges, as opposed to tracing the outside of the detected edges? Should I start another thread?
drawContours(... cv2. FILLED... ) or fillPoly. There are already a lot of questions/answer on this
Thank you. So, I am wanting to find the biggest contour, and remove the background from it. I've seen the function to find contours, but I don't know how to distinguish between the contour, the contents inside of the contour, and the background. I am also concerned that the biggest contour might be the contents and not the bounding box. Consider a box. Inside the box, I draw one continuous line back and forth across the page such that the lines never cross and I end at the starting point (line wraps back). That contour would be longer than the bounding box. Unlikely? Not for what I need it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.