#include <cv.h>
#include <highgui.h>
using namespace std;
int main(void){
cvNamedWindow("demo");
IplImage* src = cvCreateImage(cvSize(210, 210), IPL_DEPTH_8U, 3);
//三通道图像元素置0, 类似cvZero
for (int y = 0; y < src->height; y++){
uchar* ptr = (uchar*)(src->imageData + y * src->widthStep);
for (int x = 0; x < src->width; x++){
ptr[3 * x] = 0;
ptr[3 * x + 1] = 0;
ptr[3 * x + 2] = 0;
}
}
//在图像选定空间设置颜色
for (int y = 5; y <= 180; y++){
uchar* ptr = (uchar*)(src->imageData + y * src->widthStep);
for (int x = 20; x <= 160; x++){
ptr[3 * x] = x + y;
ptr[3 * x + 1] = 255 - x - y;
ptr[3 * x + 2] = y;
}
}
cvShowImage("demo", src);
//单通道图像元素设置
IplImage* temp = cvCreateImage(cvSize(210, 210), IPL_DEPTH_8U, 1);
cvZero(temp);
for(int y = 0; y < temp->height; y++){
uchar* ptrtemp = (uchar*)temp->imageData + y * temp->widthStep;
for(int x = 0; x < temp->width; x++){
ptrtemp[x] = 10;
}
}
cvShowImage("demo1", temp);
cvWaitKey();
return 0;
}
OpenCV学习笔记_用指针操作图像元素
最新推荐文章于 2023-05-06 11:48:05 发布