本文主要是介绍OpenCV笔记5:设置图像的感兴趣区域(ROI),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原文地址:http://blog.sina.com.cn/s/blog_71fa0df50100pvzv.html
#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); } |
这篇关于OpenCV笔记5:设置图像的感兴趣区域(ROI)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!