I created the following function to calculate the point with minimum intensity in an image matrix using opencv. However, I'm always getting the point 0,0 as the point with minimum intensity and the values of intensities are also absurd like -2142484923. Can someone help with this?
img is the input image matrix and minloc returns cvPoint with minimum intensity.
int min_Loc(Mat img, Point minloc)
{
cvtColor(img, img, CV_RGB2GRAY);
int x1;
int y1;
int x2;
int y2;
x1 = 0;
x2 = img.rows;
y1 = 0;
y2 = img.cols;
int min = std::numeric_limits< int >::max();
int currentval;
for (int j=y1; j<y2; j++)
{
for (int i=x1; i<x2; i++){
currentval = img.at<int>(j,i);
if(currentval < min){
min = std::min<int>( currentval, min );
minloc.x = i;
minloc.y = j;
}
}
}
return min;
}