bool affiche = true;
//Mat pic1 is the source image.
cv::Mat Image(pic1.rows, pic1.cols, CV_8UC1);
cv::Mat lbp(pic1.rows, pic1.cols, CV_8UC1);
//converts the pic to grayscale
if (pic1.channels() == 3)
cvtColor(pic1, Image, CV_BGR2GRAY);
unsigned center = 0;
unsigned center_lbp = 0;
Mat H(1, 256, CV_8UC1, Scalar::all(0));//creating the histogram
for (int row = 1; row < Image.rows - 1; row++)
{
for (int col = 1; col < Image.cols - 1; col++)
{
center = Image.at<uchar>(row, col);
center_lbp = 0;
if (center <= Image.at<uchar>(row - 1, col - 1))
center_lbp += 1;
H.at<uchar>(center_lbp) += 1;
if (center <= Image.at<uchar>(row - 1, col))
center_lbp += 2;
H.at<uchar>(center_lbp) += 1;
if (center <= Image.at<uchar>(row - 1, col + 1))
center_lbp += 4;
H.at<uchar>(center_lbp) += 1;
if (center <= Image.at<uchar>(row, col - 1))
center_lbp += 8;
H.at<uchar>(center_lbp) += 1;
if (center <= Image.at<uchar>(row, col + 1))
center_lbp += 16;
H.at<uchar>(center_lbp) += 1;
if (center <= Image.at<uchar>(row + 1, col - 1))
center_lbp += 32;
H.at<uchar>(center_lbp) += 1;
if (center <= Image.at<uchar>(row + 1, col))
center_lbp += 64;
H.at<uchar>(center_lbp) += 1;
if (center <= Image.at<uchar>(row + 1, col + 1))
center_lbp += 128;
H.at<uchar>(center_lbp) += 1;
lbp.at<uchar>(row, col) = center_lbp;
}
}
//normalize the histogram
normalize(H, H, 0, 1, NORM_MINMAX, -1, Mat());
imwrite("LBP/LBPImage.jpg", lbp);
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?