tags:

views:

383

answers:

1

Hello

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?

Cheers,

Neil

A: 

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.

jeff7
hello thanks for that - I indeed needed to convert the loaded image to greyscale and then it worked fine for me - onto the next challenge :)
Neil Benn