您的位置:首页 > 运维架构

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

2013-05-10 15:02 453 查看
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;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: