• OpenCV学习笔记8_ShowROI_显示感兴趣区域


    ShowROI_显示感兴趣区域

    ShowROI.c  用复制替换图层,替换出自己感兴趣的ROI

    #include "stdafx.h"
    
    #include "cv.h"
    #include "highgui.h"
    #include "cxcore.h"
    
    int main()
    {
        IplImage* img;
        img = cvLoadImage("E:\\TempDataForDebug\\tomato1.jpg");
        IplImage* sub_image = cvLoadImage("E:\\TempDataForDebug\\bee.jpg");
        
        CvRect rect;
        rect.x = 400;
        rect.y = 23;
        rect.width = sub_image->width;
        rect.height = sub_image->height;
    
        cvSetImageROI(img, rect);
        cvCopy(sub_image, img);
    
        cvResetImageROI(img);
       cvNamedWindow("sub");
        cvShowImage("sub",sub_image);
       cvNamedWindow("1");
      cvShowImage(
    "1",img);

      cvWaitKey(0);
      
    return 0;
    }

    ShowROI.c  改进版,用指针偏移,像素替换

    #include "stdafx.h"
    
    #include "cv.h"
    #include "highgui.h"
    #include "cxcore.h"
    
    int main()
    {
        IplImage* img;
        img = cvLoadImage("E:\\TempDataForDebug\\tomato1.jpg");
        IplImage* sub_image = cvLoadImage("E:\\TempDataForDebug\\bee.jpg");
        
        CvRect rect;
        rect.x = 400;
        rect.y = 23;
        rect.width = sub_image->width;
        rect.height = sub_image->height;
    
        int y,x;
    
        for (y = 0; y<sub_image->height; y++)
        {
            unsigned char* subImgData = (unsigned char*)(sub_image->imageData+y*sub_image->widthStep);
            unsigned char* bigImgData = (unsigned char*)(img->imageData+(y+rect.y)*img->widthStep);
    
            for (x = 0; x<sub_image->width; x++)
            {
                bigImgData[3*(x+rect.x) + 0] = subImgData[3*x + 0];
                bigImgData[3*(x+rect.x) + 1] = subImgData[3*x + 1];
                bigImgData[3*(x+rect.x) + 2] = subImgData[3*x + 2];
            }
        }
        cvNamedWindow("sub");
        cvShowImage("sub",sub_image);
    
        cvNamedWindow("1");
        cvShowImage("1",img);
    
        cvWaitKey(0);
    
        return 0;
    }

  • 相关阅读:
    /etc/sysctl.conf 控制内核相关配置文件
    python 并发编程 非阻塞IO模型
    python 并发编程 多路复用IO模型
    python 并发编程 异步IO模型
    python 并发编程 阻塞IO模型
    python 并发编程 基于gevent模块 协程池 实现并发的套接字通信
    python 并发编程 基于gevent模块实现并发的套接字通信
    python 并发编程 io模型 目录
    python 并发编程 socket 服务端 客户端 阻塞io行为
    python 并发编程 IO模型介绍
  • 原文地址:https://www.cnblogs.com/gaoquanning/p/3071212.html
Copyright © 2020-2023  润新知