码迷,mamicode.com
首页 > 其他好文 > 详细

opencv_ROI选择感兴趣的区域在原图上画出矩形并显示ROI及应用程序

时间:2014-12-09 17:47:46      阅读:368      评论:0      收藏:0      [点我收藏+]

标签:opencv   roi   

#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>

int main()
{
        IplImage *Image1;
        IplROI ROI;
        CvRect Rect1,Rect2;
        Image1=cvLoadImage("黑子.jpg",1);
        Rect1=cvRect(50,50,14,22);//坐标值根据手动标定来确定
        ROI=cvRectToROI(Rect1,0);
        Image1->roi=&ROI;

        Rect2=cvROIToRect(*Image1->roi);

        cvNamedWindow("Coast(Region Of Interesting)",1);
        cvShowImage("Coast(Region Of Interesting)",Image1);

        Image1->roi=NULL;
        cvRectangle(Image1,cvPoint(50,50),cvPoint(50 + 14,50 + 22),CV_RGB(255,0,0),1,8,0);
        cvNamedWindow("Coast",1);
        cvShowImage("Coast",Image1);

        cvWaitKey(0);
}
#include"opencv2/highgui/highgui.hpp"
#include"iostream"
using namespace std;
using namespace cv;
 
  
void main()  
{  
    IplImage *src=cvLoadImage("黑子.jpg",-1);//读入图像  
    IplImage *dst;  
    CvRect ROI_rect_src;  
    CvRect ROI_rect_dst;  
    cvNamedWindow("src",CV_WINDOW_AUTOSIZE);  
    cvMoveWindow("src",200,200);  
    cvShowImage("src",src);//输出未定位ROI的图像  
    cvWaitKey(0);  
      
    ROI_rect_src.x=src->width/2;  
    ROI_rect_src.y=src->height/2;  
    ROI_rect_src.width=200;  
    ROI_rect_src.height=200;  
    cvSetImageROI(src,ROI_rect_src);  
    cout<<"输出图像区域"<<endl;  
    cout<<(src->roi->xOffset)<<""<<(src->roi->yOffset)<<endl;  
    cout<<(src->roi->width)<<""<<(src->roi->height)<<endl; 
<span style="white-space:pre">	</span>cvNamedWindow("src1",CV_WINDOW_AUTOSIZE);
    cvShowImage("src1",src);//输出设定ROI以后的图像  
  
    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",400,200);  
    cvShowImage("dst",dst);  
    cvWaitKey(0);  
  
    cvResetImageROI(dst);//释放目标图像的ROI  
    cvShowImage("dst",dst);  
    cvWaitKey(0);  
    cvReleaseImage(&src);  
    cvReleaseImage(&dst);  
}  


opencv_ROI选择感兴趣的区域在原图上画出矩形并显示ROI及应用程序

标签:opencv   roi   

原文地址:http://blog.csdn.net/hanshuning/article/details/41825993

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!