ROI 函数的注意事项

#include <cv.h>  
#include <stdio.h>  
#include <iostream>  
#include <fstream>  
#include "cv.h"  
#include "highgui.h"  
#include <highgui.h>    
#include <cassert>    
#include <iostream>    
#include <Windows.h>    
#include <highgui.h>  
// ch3_ex3_12 image_name x y width height add#   
int main(int argc, char** argv)
{

    IplImage* src;
    cvNamedWindow("Example3_12_pre", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("Example3_12_post", CV_WINDOW_AUTOSIZE);
    if (argc == 7 && ((src = cvLoadImage(argv[1], 1)) != 0))
    {
        int x = atoi(argv[2]);// atoi函数  把字符串转换成长整型数
        int y = atoi(argv[3]);
        int width = atoi(argv[4]);
        int height = atoi(argv[5]);
        int add = atoi(argv[6]);
        int ax = (src->width)/2-100;
        int ay = (src->height)/2-100;
        cvShowImage("Example3_12_pre", src);
        cvSetImageROI(src, cvRect(ax, ay, width, height)); //传入矩形结构 通过内联构造函数cvRect(x, y, width, height)构建  
        cvAddS(src, cvScalar(add), src);//把scr的元素与常量cvScalar(add)相加放到scr里。内联构造函数cvScalar传入图像色彩。  
        cvResetImageROI(src);    //释放选择的ROI区域,不然OPENCV函数只会对感兴趣区域操作,这一点要特别注意!ROI为提高处理速度而生。如果不释放,cvShowImage只显示ROI区域。  

        cvShowImage("Example3_12_post", src);

        cvWaitKey();

    }

    cvReleaseImage(&src);

    cvDestroyWindow("Example3_12_pre");

    cvDestroyWindow("Example3_12_post");

    return 0;

}


你可能感兴趣的:(ROI 函数的注意事项)