开发者

Adaptive Threshold in OpenCV (Version 1 - the swig version)

I'm trying to get adaptive thresholding working in the python binding to opencv (the swig one - cannot get opencv 2.0 working as I am using a beagleboard as the cross compiling is not working yet). I have a greyscale image (ccg.jpg) and the following code

import opencv
from opencv import highgui
img = highgui.cvLoadImage("ccg.png")
img_bw = opencv.cvCreateImage(opencv.cvGetSize(img), opencv.IPL_DEPTH_8U, 1)
opencv.cvAdaptiveThreshold(img, img_bw, 125, opencv.CV_开发者_如何学编程ADAPTIVE_THRESH_MEAN_C, opencv.CV_THRESH_BINARY, 7, 10)

When I run this I get the error:

RuntimeError:  openCV Error:
    Status=Formats of input arguments do not match
    function name=cvAdaptiveThreshold
    error messgae=
    file_name=cvadapthresh.cpp
    line=122

I've also tried having both the source and dest arguments both the same (greyscale) and I get the error

Unsupported format or combination of formats

Does anyone have any clues as to where I could be going wrong?


I'm not a user of the swig interface, but in C the cvLoadImage function loads an image as 3 channel RGB by default, so if that's true for swig as well, then you're going to need to either change your code to load img as grayscale (CV_LOAD_IMAGE_GRAYSCALE) or do an intermediate step to convert it to grayscale with cvCvtColor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜