Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python opencv error in Emacs when running cv2.Canny()

I encountered a very strange issue when using OpenCV's cv2.Canny() function in the python shell in Emacs. When I run cv2.Canny(img, thresh1, thresh2), I got error message

OpenCV Error: Assertion failed (depth == CV_8U) in cv::Canny, file D:\Build\OpenCV\opencv-3.2.0\modules\imgproc\src\canny.cpp, line 845 Traceback (most recent call last): File "", line 1, in File "../myscript.py", line 34, in lines = cv2.HoughLines(edges,1,np.pi/180,200) cv2.error: D:\Build\OpenCV\opencv-3.2.0\modules\imgproc\src\canny.cpp:845: error: (-215) depth == CV_8U in function cv::Canny

I don't even have a D drive on my computer, and why the source code has issue with this? it should already been compiled..

I haven't observe any other functions in python-opencv cause this issue. I also tried to install different versions, and same error for this particular function call, but the line number varies because the canny.cpp file is of different versions.

However, everything is fine, when I run the same line in System Python Shell...

my system environment:

windows7 64bit
python 3.5
python-opencv: 3.1, or 3.2
emacs 25.1.1
like image 623
shelper Avatar asked Feb 22 '17 22:02

shelper


1 Answers

The issue is that your image (or one of your images) is not in 8 bit format (8 bit format means each of three channels is in [0,255]).

You can change this by adding:

img = img.astype(np.uint8)

before you call cv2.Canny.

like image 171
Megan Hardy Avatar answered Nov 11 '22 19:11

Megan Hardy