Resource View->Menu->IDR_MAINFRAME->右键具体功能框->ClassWizard->在Class CIPTESTView中添加COMMAND->Add Fumction
在Header Files->View.h中添加:
void TranImgGray(IplImage *cImg, IplImage *gImg);//IplImage是OpenCV的一个图像类
函数实现:
void ***View::TranImgGray(IpLImage *cImg,IplImage *gImg)
{
uchar *data=(uchar*)cImg->imageData;
int wp = cImg->widthStep;
uchar *data=(uchar*)gImg->ImageData;
int wp1 = gImg->widthStep;
for(int i = 0; i < cImg->height; i++)
{
for(int j = 0; j < cImg->width; j++)
{
int r = data[i * wp + 3 * j];
int g = data[i * wp + 3 * j + 1];
int b = data[i * wp + 3 * j + 2];
data1[i * wp + 3 * j]=(r+b+g)/3;
data1[i * wp + 3 * j + 1]=(r+b+g)/3;
data1[i * wp + 3 * j + 2]=(r+b+g)/3;
}
}
}