Convert Gray image into LBP image
Hello everyone,
I want to detect the eye blink in android OpenCV. I have been suggested to use LBP and SVM Classification for better results. I have been looking at different places including this and this but having trouble in understanding the code. I want the code in Java and I am having problems in converting the C++ code into Java as there are some function which are different in both of them. Can someone kindly give me a sample code to convert gray image to LBP image so that I can apply SVM on it. Need it badly. Please help.. Here is a code in C++. I need this in Java.
Mat LBP(Mat img){
Mat dst = Mat::zeros(img.rows-2, img.cols-2, CV_8UC1);
for(int i=1;i<img.rows-1;i++) {
for(int j=1;j<img.cols-1;j++) {
uchar center = img.at<uchar>(i,j);
unsigned char code = 0;
code |= ((img.at<uchar>(i-1,j-1)) > center) << 7;
code |= ((img.at<uchar>(i-1,j)) > center) << 6;
code |= ((img.at<uchar>(i-1,j+1)) > center) << 5;
code |= ((img.at<uchar>(i,j+1)) > center) << 4;
code |= ((img.at<uchar>(i+1,j+1)) > center) << 3;
code |= ((img.at<uchar>(i+1,j)) > center) << 2;
code |= ((img.at<uchar>(i+1,j-1)) > center) << 1;
code |= ((img.at<uchar>(i,j-1)) > center) << 0;
dst.at<uchar>(i-1,j-1) = code;
}
}
return dst;
}
Thanks in advance.
"but could not understand it"
you probably want to explain, what you did understand, and what not.
(any given code would be useless, without a minimal understanding of what you're doing)
@berak So far I have detected the eyes and face using haarcascade. Converted them to gray image. So now I have a gray image of that detected region(in this case eyes) on which i want to apply LBP. I know the concept of how LBP works but having trouble in writing the code in java. Can you please help me with that ?
above would be part1 of the assignment. after that, you'd have to grid the lbp-image into parts, take a histogram of each, and concatenate those histograms to the final (1d feature vector) to be used by svm.
since this involves a lot of per-pixel operations, you'd rather want to keep it c++ (via jni), and only retunr the final feature vect to java