Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Opencv Face detection not work at Linux

I'm coding at Win10. and run the project at Linux. It's worked fine at win10 env, and got some problem with Linux system (centos 7). and got same problem in 2 different linux server. env: java8 + opencv2.4.13 + tomcat8.

1.Throw exception when runing cvtColor() in Linux. like this:

Mat image = Highgui.imread(inputimg);  //Only have 1 channel in Linux. and the same pic have 3 channels in win.
Imgproc.cvtColor(image, image , Imgproc.COLOR_RGB2GRAY); //throw exception at this line

It's throwing this:

throws java.io.FileNotFoundException]: CvException [org.opencv.core.CvException: cv::Exception: /home/qh/opencv/opencv-2.4.13/modules/imgproc/src/color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function cvtColor]
CvException [org.opencv.core.CvException: cv::Exception: /home/qh/opencv/opencv-2.4.13/modules/imgproc/src/color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function cvtColor

The same picture. have 3 channels in windows. only have 1 channel in Linux.(I print Mat.channels() in java. It shows only 1 channel in linux. ). (scn means count of image channels in c++ source code. and COLOR_RGB2GRAY need input image file have 3 or 4 channels. )

2.Then I delete cvtColor() from my code. now it look like this. and got anthor situation.

Mat image = Highgui.imread(inputimg);
        CascadeClassifier faceDetector =  new CascadeClassifier(dataxml);
        MatOfRect faceDetections = new MatOfRect();
        faceDetector.detectMultiScale(image, faceDetections);

I'm using the same code , same picture. And the program can correctly detect faces in windows. but always detect 0 faces in linux.

Why same code , same picture got different result.

Opencv Face detection not work at Linuxshow different result between win and linux

I'm coding at Win10. and run the project at Linux. It's worked fine at win10 env, and got some problem with Linux system (centos 7). and got same problem in 2 different linux server. env: java8 + opencv2.4.13 + tomcat8.

1.Throw exception when runing cvtColor() in Linux. like this:

Mat image = Highgui.imread(inputimg);  //Only have 1 channel in Linux. and the same pic have 3 channels in win.
Imgproc.cvtColor(image, image , Imgproc.COLOR_RGB2GRAY); //throw exception at this line

It's throwing this:

throws java.io.FileNotFoundException]: CvException [org.opencv.core.CvException: cv::Exception: /home/qh/opencv/opencv-2.4.13/modules/imgproc/src/color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function cvtColor]
CvException [org.opencv.core.CvException: cv::Exception: /home/qh/opencv/opencv-2.4.13/modules/imgproc/src/color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function cvtColor

The same picture. have 3 channels in windows. only have 1 channel in Linux.(I print Mat.channels() in java. It shows only 1 channel in linux. ). (scn means count of image channels in c++ source code. and COLOR_RGB2GRAY need input image file have 3 or 4 channels. )

2.Then I delete cvtColor() from my code. now it look like this. and got anthor situation.

Mat image = Highgui.imread(inputimg);
        CascadeClassifier faceDetector =  new CascadeClassifier(dataxml);
        MatOfRect faceDetections = new MatOfRect();
        faceDetector.detectMultiScale(image, faceDetections);

I'm using the same code , same picture. And the program can correctly detect faces in windows. but always detect 0 faces in linux.

Why same code , same picture got different result.