Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

CalcHist on java

Hello,

I use calcHist function to learn colors (HSV) of sky images using svm. The learning process is coded in c++, I tested result and the precision is about 80%. Then I try to use the svm file in an android application. But all prediction are -1. I check my program but all seems ok. I think maybe the result of the calcHist function is different in c++ and java. Can someone check if I use same function in c++ and java ?

C++ code

int hbins = 30, sbins = 32; 
int histSize[] = {hbins, sbins};
float hranges[] = { 0, 180 };
float sranges[] = { 0, 256 };
const float* ranges[] = { hranges, sranges };
MatND hist; int channels[] = {0, 1};
calcHist( &imageHSV, 1, channels, Mat(),  hist, 2, histSize, ranges, true, false);

Java code

int hbins = 30, sbins = 32;
MatOfInt histSize = new MatOfInt(hbins, sbins);
MatOfFloat histRange = new MatOfFloat(0f, 180f, 0f, 256f);
List<Mat> imageList = new ArrayList<>();
imageList.add(smallMat);
Mat hsvHist = new Mat();
Imgproc.calcHist(imageList, new MatOfInt(0, 1), new Mat(), hsvHist, histSize, histRange);

Thank you!

CalcHist on java

Hello,

I use calcHist function to learn colors (HSV) of sky images using svm. The learning process is coded in c++, I tested result and the precision is about 80%. Then I try to use the svm file in an android application. But all prediction are -1. I check my program but all seems ok. I think maybe the result of the calcHist function is different in c++ and java. Can someone check if I use same function in c++ and java ?

C++ code

int hbins = 30, sbins = 32; 
int histSize[] = {hbins, sbins};
float hranges[] = { 0, 180 };
float sranges[] = { 0, 256 };
const float* ranges[] = { hranges, sranges };
MatND hist; int channels[] = {0, 1};
calcHist( &imageHSV, 1, channels, Mat(),  hist, 2, histSize, ranges, true, false);

Java code

int hbins = 30, sbins = 32;
MatOfInt histSize = new MatOfInt(hbins, sbins);
MatOfFloat histRange = new MatOfFloat(0f, 180f, 0f, 256f);
List<Mat> imageList = new ArrayList<>();
imageList.add(smallMat);
Mat hsvHist = new Mat();
Imgproc.calcHist(imageList, new MatOfInt(0, 1), new Mat(), hsvHist, histSize, histRange);

Resolved I find the problem, in C++ the image space is BGR by default but in java it is RGBA. All the data order was inversed that is why the svm prediction was completly wrong.

Thank you!