cvMinMaxLoc()的實作
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
int main()
{
IplImage *Image1=cvLoadImage("grotto.jpg" ,1 );
double MinValue;
double MaxValue;
CvPoint MinLocation;
CvPoint MaxLocation;
cvSetImageCOI(Image1,1 );
cvMinMaxLoc(Image1,&
MinValue,&
MaxValue,&
MinLocation,&
MaxLocation);
printf("The Min number is : %.f/n" ,MinValue);
printf("The position is : ( %d , %d )/n" ,MinLocation.x,MinLocation.y);
printf("The Max number is : %.f/n" ,MaxValue);
printf("The position is : (%d , %d )/n" ,MaxLocation.x,MaxLocation.y);
cvNamedWindow("grotto" ,1 );
cvShowImage("grotto" ,Image1);
cvWaitKey(0 );
}
#include <highgui.h>
#include <stdio.h>
int main()
{
IplImage *Image1=cvLoadImage("grotto.jpg" ,1 );
IplImage *MaskImage1=cvLoadImage("grotto_Threshold.bmp" ,0 );
double MinValue;
double MaxValue;
CvPoint MinLocation;
CvPoint MaxLocation;
cvSetImageCOI(Image1,1 );
cvMinMaxLoc(Image1,
&
MinValue,&
MaxValue,&
MinLocation,&
MaxLocation,MaskImage1);printf("The Min number is : %.f/n" ,MinValue);
printf("The position is : ( %d , %d )/n" ,MinLocation.x,MinLocation.y);
printf("The Max number is : %.f/n" ,MaxValue);
printf("The position is : (%d , %d )/n" ,MaxLocation.x,MaxLocation.y);
cvNamedWindow("grotto" ,1 );
cvShowImage("grotto" ,Image1);
cvWaitKey(0 );
}
cvSetImageROI(result,resultrect);
cvMinMaxLoc(result, &min_val, &max_val,&min_loc,&max_loc, NULL );
center.x=min_loc.x-(int)objsize/2;center.y=min_loc.y-(int)objsize/2;
cvResetImageROI(result);
有时候,匹配要结合位置,所以之匹配的目标不一定是真正的目标。所以要求roi的最小值,这样写结果总不对,后来才发现,原来结果min_loc是roi的坐标,还要反算出原图的坐标。
trackback: http://blog.csdn.net/schoolers/article/details/4728400