How to train Local Binary Patterns to SVM
public: cv::Mat LBP(Mat pic1){
bool affiche = true;
Mat Image(pic1.rows, pic1.cols, CV_8UC1), lbp(pic1.rows, pic1.cols, CV_8UC1);
cvtColor(pic1, Image, CV_BGR2GRAY);
unsigned center = 0, center_lbp = 0;
Mat H(1, 256, CV_32FC1, Scalar::all(0));
for (int row = 1; row < Image.rows - 1; row++)
{
for (int col = 1; col < Image.cols - 1; col++)
{
center = Image.at<float>(row, col);
center_lbp = 0;
if (center <= Image.at<float>(row - 1, col - 1))
center_lbp += 1;
if (center <= Image.at<float>(row - 1, col))
center_lbp += 2;
if (center <= Image.at<float>(row - 1, col + 1))
center_lbp += 4;
if (center <= Image.at<float>(row, col - 1))
center_lbp += 8;
if (center <= Image.at<float>(row, col + 1))
center_lbp += 16;
if (center <= Image.at<float>(row + 1, col - 1))
center_lbp += 32;
if (center <= Image.at<float>(row + 1, col))
center_lbp += 64;
if (center <= Image.at<float>(row + 1, col + 1))
center_lbp += 128;
lbp.at<float>(row, col) = center_lbp;
H.at<float>(center_lbp) += 1;
}
}
normalize(H, H, 0, 1, NORM_MINMAX, -1, Mat());
textureData.push_back(H);
return H;
}
I am a beginner in openCV. The code above is inside a function that should return the finished training data. My problem is that I don't know how to get the numbers inside H and how to create the training data for the SVM. Can somebody help me with this?
H.at<uchar>(center_lbp) += 1;
should only appear once (at the end)if (pic1.channels() == 3)
<-- you need anelse
case here, or Image won't be initialized3: you will need to change:
and:
It triggered a breakpoint at normalize();
could you update your code ?
^^^updated
your histogram is float, but your Image is still uchar, so:
Image.at<uchar>
.please try to use a debug build, cases like this should trigger an exception.
"I don't know how to get the numbers inside H" -- you can just print it out:
I have a problem. Using CV_32FC1 does not output an array inside H that looks like [0,1,0,1,0,0,1......] while using CV_8UC1 outputs the right array but will return a SEHException at svm->train().