改变ROI区域进行操作学习

#include "highgui.h"
#include "cv.h"
#include <iostream>
using namespace std;
void main()
{
	IplImage *src=cvLoadImage("small.jpg",-1);//读入图像
	//IplImage *dst;
	CvRect ROI_rect_src;
	CvRect ROI_rect_dst;

	ROI_rect_src.x=0;
	ROI_rect_src.y=0;
	ROI_rect_src.width=src->width;
	ROI_rect_src.height=src->height;
	cvSetImageROI(src,ROI_rect_src);
	IplImage *dst = cvCloneImage(src);//复制出ROI区域的图像
	CvScalar pixel;
	for (int i = src->height/2; i < src->height*0.8; ++i)
	{
		for (int j = src->width/2; j < src->width*0.8; ++j)
		{
			//获得像素的RGB值并显示, 注意内存中存储顺序是BGR
			pixel = cvGet2D(dst, i, j);
			//printf("B=%f,G=%f,R=%f/t", pixel.val[0], pixel.val[1], pixel.val[2]);
			//修改各点的值
			pixel.val[0] = 0;
			pixel.val[1] = 0;
			pixel.val[2] = 0;
			cvSet2D(dst, i, j, pixel);
		}
	}
	cvShowImage("ROI像素改变后",dst);//输出设定ROI以后的图像
	cvWaitKey(0);
	cvResetImageROI(dst);//释放目标图像的ROI
	cvShowImage("源图像",src);//输出设定ROI以后的图像
	cvWaitKey(0);
	cvReleaseImage(&src);
	cvReleaseImage(&dst);  
}
改变 改变ROI区域进行操作学习_第1张图片 改变ROI区域进行操作学习_第2张图片

你可能感兴趣的:(存储,include,DST)