5
votes

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.

1
Yeah, I've encountered this error myself. I love OpenCV, but I hate their error messages. This one's incredibly unhelpful, especially for novices, but basically it means your source and destination images don't have the same format (e.g. different pixel dimensions or different number of channels).Cerin

1 Answers

5
votes

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.