新函数用红色显示,程序为:
#include <highgui.h>
#include <cv.h>
#include <iostream.h>
void main()
{
IplImage * src=cvLoadImage("baboon.jpg",-1);
IplImage * dst;
CvRect roi_rect_src;
CvRect roi_rect_dst;
cvNamedWindow("src",CV_WINDOW_AUTOSIZE);
cvMoveWindow("src",200,200); //设置窗口输出位置
cvShowImage("src",src);
cvWaitKey(0);
//基于给定的矩形设置感兴趣区域ROI
roi_rect_src.x=125;
roi_rect_src.y=300;
roi_rect_src.width=240;
roi_rect_src.height=200;
cvSetImageROI(src,roi_rect_src);
cout<<"输出源图像的ROI区域:"<<endl;
cout<<(src->roi->xOffset)<<" "<<(src->roi->yOffset)<<endl;
cout<<(src->roi->width)<<" "<<(src->roi->height)<<endl;
cvShowImage("src",src);//这时候只显示ROI区域
cvWaitKey(0);
dst=cvCloneImage(src);//完整复制包括头,ROI和数据
roi_rect_dst=cvGetImageROI(dst);//获得ROI区域
cout<<"输出目标图像的ROI区域:"<<endl;
cout<<roi_rect_dst.x<<" "<<roi_rect_dst.y<<endl;
cout<<roi_rect_dst.width<<" "<<roi_rect_dst.height<<endl;
cvNamedWindow("dst",CV_WINDOW_AUTOSIZE);
cvMoveWindow("dst",600,200);
cvShowImage("dst",dst);
cvWaitKey(0);
cvResetImageROI(dst);//释放图像的ROI
cvShowImage("dst",dst);
cvWaitKey(0);
cvReleaseImage(&src);
cvReleaseImage(&dst);
}
==========================================
这只狒狒也是标准测试图,它的名字叫baboon,在图像处理中有很高的地位。
程序中将它的鼻子作为ROI。
设置图像的感兴趣区域(ROI)
最新推荐文章于 2024-08-11 08:01:53 发布