標籤:
//用widthStep的方法來增加某範圍的像素//sandy//時間:2015-10-5#include <cv.h>#include <highgui.h>int main(int argc, char** argv){ //載入圖片 IplImage* interest_img; interest_img=cvLoadImage("E:\\picture\\d.jpg",1); //定義一個矩形作為感興趣地區 CvRect rect=cvRect(100,150,250,250); //建立IplImage映像頭,制定映像的尺寸,深度和通道數 IplImage *sub_img= cvCreateImageHeader( cvSize(rect.width,rect.height ),//映像的尺度=矩形尺度 interest_img->depth , interest_img->nChannels ); sub_img->origin =interest_img->origin ;//定義映像座標原點的位置 sub_img->widthStep =interest_img->widthStep; //imageData指標指向興趣子領域 sub_img->imageData =interest_img->imageData + rect.y *interest_img->widthStep + rect.x *interest_img->nChannels ; //藍色通道增加100 cvAddS(sub_img,cvScalar(100),sub_img);//【存放單通道映像中像素:cvScalar(255)】把第一個sub_img的元素與cvScalar(100)相加放到第二個sub_img裡。 //顯示 cvNamedWindow("roi_add",1); cvShowImage("roi_add",sub_img); //釋放 cvReleaseImageHeader(&sub_img); cvWaitKey(); return 0;}
用widthStep的方法來增加某範圍的像素----與imageROI對比