zoukankan      html  css  js  c++  java
  • cvMinMaxLoc函数实例

     cvMinMaxLoc()找出图片或一组数据中最大值及最小值的数据,以及最大值及最小值的位置,第一个引数为输入IplImage资料结构或CvMat资料结构,第二个引数为输出最小值double型别数据,第三个引数为输出最大值double型别数据,第四个引数为输出最小值位置CvPoint资料结构,第五个引数为输出最大值位置CvPoint资料结构.找出图片或一组数据中最大值及最小值的数据,以及最大值及最小值的位置,第一个引数为输入IplImage资料结构或CvMat资料结构,第二个引数为输出最小值double型别数据,第三个引数为输出最大值double型别数据,第四个引数为输出最小值位置CvPoint资料结构,第五个引数为输出最大值位置CvPoint资料结构. cvMinMaxLoc(输入IplImage或CvMat资料结构,输出double型别最小值数据,输出double型别最大值数据,输出最小值CvPoint资料结构,输出最大值CvPoint资料结构) cvMinMaxLoc(输入IplImage或CvMat资料结构,输出double型别最小值数据,输出double型别最大值数据,输出最小值CvPoint资料结构,输出最大值CvPoint资料结构)。

    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 );
    }

    上面的结果是抓出这张图片最大最小值的数据,选择绿色这个通道,虽然这已经不算是极端值的意义了,不过它仍然是可以对一般图形做处理,cvMinMaxLoc()可以同时找出最大最小值,也可以指出最大值的位置跟最小值的位置,而cvMinMaxLoc()必须对单通道做处理因此必须要用,cvSetImageCOI选定颜色,也可以支援ROI,甚至,cvMinMaxLoc()可以用遮罩的方式实作,使用的方法如下:
    #include <cv.h>
    #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 );
    }
    上面的程式也只對grotto_Threshold.bmp白色的部份做處理,從白色區域找出它的最大最小值以及它的位置,跟前面的程式差不多.
    //////////////

    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

  • 相关阅读:
    坑爹的Android Ble 问题记录日志
    Android4.3 蓝牙BLE初步
    Bluetooth Low Energy——蓝牙低功耗
    Bluetooth LE(低功耗蓝牙)
    Bluetooth LE(低功耗蓝牙)
    Bluetooth LE(低功耗蓝牙)
    Bluetooth LE(低功耗蓝牙)
    Bluetooth LE(低功耗蓝牙)
    C#中“@”的作用和用法
    C#中对输出格式的初始化
  • 原文地址:https://www.cnblogs.com/JohnShao/p/2151804.html
Copyright © 2011-2022 走看看