我有一个使用 C++ 的简单代码(与 OpenCV 结合)这里是代码(主要)
int main(int argc, char** argv)
{
IplImage* image_input = cvLoadImage("test.jpg", CV_LOAD_IMAGE_UNCHANGED);
IplImage* image_output =cvCreateImage(cvGetSize(image_input),
IPL_DEPTH_8U,image_input->nChannels);
unsigned char *h_out = (unsigned char*)image_output->imageData;
unsigned char *h_in = (unsigned char*)image_input->imageData;
int width = image_input->width;
int height = image_input->height;
h_grayscale ( h_in , h_out ) ;
cvShowImage("Original", image_input);
cvShowImage("CPU", image_output);
cvReleaseImage(&image_input);
cvReleaseImage(&image_output);
waitKey(0);
}
这是灰度的功能
void h_grayscale( unsigned char* h_in, unsigned char* h_out){
for (unsigned int i=0; i< width*height; i++){
unsigned int index = i*3;
double temp = 0.3*h_in[index]+0.6*h_in[index+1]+0.1*h_in[index+2];
h_out[i] = (unsigned char)temp;
}
}
但图像的结果用灰度图像分成 3 部分
请告诉我我的代码有什么问题??T_T谢谢