Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openCV: Sobel edge detection gives me assertion error

I am using python-openCV. When using the Sobel edge detection I get the following assertion error:

src.size() == dst.size() && src.channels() == dst.channels() && ((src.depth() == CV_8U && (dst.depth() == CV_16S || dst.depth() == CV_32F)) || (src.depth() == CV_32F && dst.depth() == CV_32F))

I create the dest using CreateImage() and it has same size and channels as src. Also the depth of both src and dest is IPL_DEPTH_8U. I also tried loading image using LoadImageM() so that the constants are of kind CV_* but that didn't help.

I also happen to find out that IPL_DEPTH_8U == CV_8U is false.

like image 500
Xolve Avatar asked Jun 03 '11 10:06

Xolve


1 Answers

I found the solution a bit tricky for novices to openCV:

src = cv.LoadImageM('src.png', cv.CV_LOAD_IMAGE_GRAYSCALE)
dest = cv.CreateMat(src.height, src.width, cv.CV_16S)
cv.Sobel(src, dest, 1, 1)

The important thing to note is that the image formats required for operations are not clearly documented in API references and one should pay very careful attention to errors generated.

like image 145
Xolve Avatar answered Nov 17 '22 21:11

Xolve