Algomorph/pyboostcvconverter

python interpreter is ok but python script crush

Closed this issue · 1 comments

Hi, I met some problems.

I add one function in src/python_module.cpp and add it in BOOST_PYTHON_MODULE

cv::Mat get_edges(char* filename) {
    cv::Mat img, gray, canny;
    img = cv::imread(filename, CV_LOAD_IMAGE_COLOR);
    cv::cvtColor(img, gray, CV_BGR2GRAY);
    cv::Canny(gray, canny, 50, 150, 3);
    return canny;
}

...

def("get_edges", get_edges);

Then make & sudo make install. I can use this function in python interpreter, but when I create a new python script such as test.py which only contains:

import pbcvt
pbcvt.get_edges('xxxx') # xxxx is the path to an image

It raises an error:
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /data1/Softwares/opencv-3.2.0/modules/imgproc/src/color.cpp, line 9748
Traceback (most recent call last):
File "test.py", line 5, in
a = pbcvt.get_edges('/data1/Datasets/hand-test/iamges/image1.jpg')
RuntimeError: /data1/Softwares/opencv-3.2.0/modules/imgproc/src/color.cpp:9748: error: (-215) scn == 3 || scn == 4 in function cvtColor

Why it happens?

Sorry, the image path is error. Change it to the correct path then everything is ok.