Hi friends i am trying to implement paper on Rapid texture Based Moving Object Detection So in this the first step is to convert grayscale image to lbp image so i have written the following code but it is not producing the desired output So Please if anybody having proper code provide it or state correction in my code.
int main() {
Mat img = cv::imread("im1.jpg");
if (img.empty())
{
std::cout << "Cannot open image!" << std::endl;
return -1;
}
Mat greyMat;
cvtColor(img, greyMat, CV_BGR2GRAY);
Mat lbp=greyMat.clone();
long row=greyMat.rows;
long col=greyMat.cols;
for(int i=1;i<greyMat.rows;i++)
{
for(int j=1;j<greyMat.cols;j++)
{
int cp=(int)greyMat.at<uchar>(i,j);
int pp=0;
int po=7;
if(cp<=(int)greyMat.at<uchar>(i,j+1))
pp+=pow(2,po);
po--;
if(cp<=(int)greyMat.at<uchar>(i+1,j+1))
pp+=pow(2,po);
po--;
if(cp<=(int)greyMat.at<uchar>(i+1,j))
pp+=pow(2,po);
po--;
if(cp<=(int)greyMat.at<uchar>(i+1,j-1))
pp+=pow(2,po);
po--;
if(cp<=(int)greyMat.at<uchar>(i,j-1))
pp+=pow(2,po);
po--;
if(cp<=(int)greyMat.at<uchar>(i-1,j-1))
pp+=pow(2,po);
po--;
if(cp<=(int)greyMat.at<uchar>(i-1,j))
pp+=pow(2,po);
po--;
if(cp<=(int)greyMat.at<uchar>(i-1,j+1))
pp+=1*pow(2,po);
po--;
lbp.at<uchar>(i,j)=pp;
}
}
return 0;
}