- 基础结构体
CvPoint int x,y
CvPoint2D32f Float x,y;
CvSize Int width,height
CvRect int x,y,width,height
CvScalar double val[4] 这里为RGBA的值
- CvMat
typedef struct CvMat {
int type;
int step;
int* refcount; // for internal use only
union {
uchar* ptr;
short* s;
int* i;
float* fl;
double* db;
} data;
union {
int rows;
int height;
};
union {
int cols;
int width;
};
} CvMat;
float vals[] = [1,2,3,4];
cvCreateMat(5,5, CV_32FC1);
CvInitMatHeader {
&Mat, 2, 2, CV_32FC1, vals
}
*( (float*)CV_MAT_ELEM_PTR(*mat, 3, 2) ) = 7.7; // 赋值
cvmSet(mat, 2, 2, 0.5);
double cvGet(mat, 2,2);
- IplImage
// 对于指定区域进行色彩加强
int main(){
char input[] = "/Users/basasuya/Downloads/1.jpg";
IplImage* src = cvLoadImage(input);
int x,y,width,height,add;
scanf("%d %d %d %d %d",&x,&y,&width,&height,&add);
cvSetImageROI(src, cvRect(x,y,width,height));
cvAddS(src, cvScalar(add), src);
cvResetImageROI(src);
cvNamedWindow("Roi_Add", 1);
cvShowImage("Roi_Add", src);
cvWaitKey();
}
//另一种加强的方式
int main(){
char input[] = "/Users/basasuya/Downloads/1.jpg";
IplImage* src = cvLoadImage(input);
int x,y,width,height,add;
scanf("%d %d %d %d %d",&x,&y,&width,&height,&add);
// cvSetImageROI(src, cvRect(x,y,width,height));
IplImage* cha = cvCreateImageHeader(cvSize(width, height), src->depth, src->nChannels);
cha->origin = src->origin;
cha->widthStep = src->widthStep;
cha->imageData = src->imageData + y* src->widthStep + x* src->nChannels;
cvAddS(cha, cvScalar(add), cha);
cvReleaseImageHeader(&cha);
cvNamedWindow("Roi_add", CV_WINDOW_AUTOSIZE);
cvShowImage("Roi_add", src);
cvWaitKey();
return 0;
}
//将两个图片进行叠加
int main(){
char input1[] = "/Users/basasuya/Downloads/1.jpg";
char input2[] = "/Users/basasuya/Downloads/2.jpg";
IplImage* s1 = cvLoadImage(input1);
IplImage* s2 = cvLoadImage(input2);
int x,y,width,height;
double alpha, beta;
scanf("%d %d %lf %lf",&x,&y,&alpha,&beta);
width = s2->width; height = s2->height;
// cvSetImageROI(src, cvRect(x,y,width,height));
cvSetImageROI(s1, cvRect(x,y,width,height));
cvSetImageROI(s2, cvRect(0,0,width,height));
cvAddWeighted(s1, alpha, s2, beta, 0, s1);
cvResetImageROI(s1);
ShowImg(s1);
return 0;
}