Ask Your Question
0

Opencv Face detection show different result between win and linux

asked 2017-04-27 03:35:43 -0600

Owen1991 gravatar image

updated 2017-04-27 18:55:57 -0600

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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-04-28 03:37:04 -0600

berak gravatar image

updated 2017-04-28 03:37:47 -0600

  • make sure, you image is loaded. this is your actual problem here !
  • cvtColor() will complain, if it was fed an invalid/empty image, the other functions is your java pipeline unfortunately won't , so removing the cvtColor line will just suppress the problem, not solve it.

so, please check your resources, carefully:

Mat image = Highgui.imread(inputimg); 
if (image.empty()) {
      // path problem, image not read. throw some error. 
}

CascadeClassifier faceDetector =  new CascadeClassifier(dataxml);
if (faceDetector.empty()) {
       // path to xml is broken, throw error !
}
edit flag offensive delete link more

Comments

Thanks for your reply . I figured this out at Friday. I think two sever had two different reason . First reason: two server have different folder path. Throw FileNotFound cause I copied file path from anthor server then loaded a null path. Second one I'm not sure why. certainly file path not null. After recompile Opencv and replace all .so file . It's just worked fine. And thanks for your help. wish you have a nice day.

Owen1991 gravatar imageOwen1991 ( 2017-05-01 20:35:32 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-04-27 03:18:41 -0600

Seen: 668 times

Last updated: Apr 28 '17