#include <cv.h>
#include <highgui.h>
int main(int argc, char** argv)
{
IplImage* src;
if (((src = cvLoadImage("001.jpg", 1)) != 0))
{
int x = 1000;
int y = 400;
int width = 400;
int height = 400;
int add = 50;
//给定图片的从左上角(x,y) 长宽为width,height的区域进行ROI增加像素
cvSetImageROI(src, cvRect(x, y, width, height));
//增加像素 并且存储在src
cvAddS(src, cvScalar(add), src);
//释放基于给定矩形的ROI
cvResetImageROI(src);
//创建窗口
cvNamedWindow("Src", 1);
//通过新建的窗口对src进行show
cvShowImage("Src", src);
cvWaitKey();
}
return 0;
}
#include <cv.h>
#include <highgui.h>
int main(int argc, char* argv[])
{
IplImage* interest_img = cvLoadImage("001.jpg");
// 确定一个矩形区域 参数分别是左/右上角坐标 具体根据截取原图的 origin
CvRect interest_rect = cvRect(400, 400, 400, 400);
//创建一个图像的头 具体为截取的图片
IplImage *sub_img = cvCreateImageHeader(cvSize(interest_rect.width, interest_rect.height), interest_img->depth, interest_img->nChannels);
// 截取图形的原点 根据原图获得
sub_img->origin = interest_img->origin;
//校队后的行字节数
sub_img->widthStep = interest_img->widthStep;
//图像数据的指针
sub_img->imageData = interest_img->imageData + interest_rect.y * interest_img->width + interest_rect.x * interest_img->nChannels;
//为截取的图像增加像素
cvAddS(sub_img, cvScalar(50), sub_img);
cvNamedWindow("main");
cvNamedWindow("result");
//通过窗口展示原图像和截取图像
cvShowImage("main", interest_img);
cvShowImage("result", sub_img);
cvWaitKey();
//释放内存
cvReleaseImage(&interest_img);
cvReleaseImageHeader(&sub_img);
cvDestroyWindow("main");
cvDestroyWindow("result");
return 0;
}