zoukankan      html  css  js  c++  java
  • opencv——设置ROI区域

    #include "stdafx.h"
    #include<opencv2opencv.hpp>
    #include<opencvcv.h>
    #include <iostream>
    #include<string>
     using namespace std;
     using namespace cv;
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        IplImage *src=cvLoadImage("lena.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;  
        cvSaveImage("ROI.bmp",src);
        
        cout<<(src->roi->xOffset)<<""<<(src->roi->yOffset)<<endl;  
        cout<<(src->roi->width)<<""<<(src->roi->height)<<endl;  
        cvShowImage("sr",src);//输出设定ROI以后的图像  
        //cvWaitKey(0);
        dst=cvCloneImage(src);//复制出ROI区域的图像  
        ROI_rect_dst=cvGetImageROI(src);//得到图像的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);  
    
    
    
        return 0;
    }

           

  • 相关阅读:
    Spyder | 关于报错No module named 'PyQt5.QtWebKitWidgets'
    Java基础(11) | 接口
    Java基础(10) | 抽象
    Java基础(9) | 继承
    Java基础(7) | String
    Java基础(6) | ArrayList
    CodeBlocks17.12配置GNU GCC + 汉化
    图片懒加载
    Mac安装Mysql 超详细(转载)
    剑指 Offer 03. 数组中重复的数字
  • 原文地址:https://www.cnblogs.com/nanyangzp/p/3496455.html
Copyright © 2011-2022 走看看