增加亮度不会产生所需的效果 cvtcolor(img、dst、CV_RGB2YCrCb); for(int col=0;colwidth;col++) { 对于(int行=0;行高;行++) { int idxF=row*dst->widthStep+dst->nChannels*col;//读取图像数据 CvPoint pt={row,col}; temp_ptr2[0]+=temp_ptr1[0]*0.0722+temp_ptr1[1]*0.7152+temp_ptr1[2]*0.2126;//通道Y } }
但结果是: 请帮助我,我哪里出错了?关于这个代码示例,有很多话要说:增加亮度不会产生所需的效果 cvtcolor(img、dst、CV_RGB2YCrCb); for(int col=0;colwidth;col++) { 对于(int行=0;行高;行++) { int idxF=row*dst->widthStep+dst->nChannels*col;//读取图像数据 CvPoint pt={row,col}; temp_ptr2[0]+=temp_ptr1[0]*0.0722+temp_ptr1[1]*0.7152+temp_ptr1[2]*0.2126;//通道Y } },c,opencv,image-processing,luminance,C,Opencv,Image Processing,Luminance,但结果是: 请帮助我,我哪里出错了?关于这个代码示例,有很多话要说: L> > P>首先,您使用的是旧的C风格API( IplImage < /COD>指针, CVBLAH < /Calp>函数等),它已经过时且更难以维护(特别是容易引入内存泄漏),因此您应该考虑使用C++风格的结构和函数。(cv::Mat结构和cv::blah函数) 您的错误可能来自最开始的指令cvCopy(dst,img);。这会在开始处理之前将输入图像填充为空白,因此您应该删除这一行 为了获得最大的速度,您应该反转这
-
<> L> > P>首先,您使用的是旧的C风格API(<代码> IplImage < /COD>指针,<代码> CVBLAH < /Calp>函数等),它已经过时且更难以维护(特别是容易引入内存泄漏),因此您应该考虑使用C++风格的结构和函数。(
cv::Mat
结构和cv::blah
函数)
cvCopy(dst,img);
。这会在开始处理之前将输入图像填充为空白,因此您应该删除这一行idxF
从未使用过,因此您可能也应该删除以下行:
cvCvtColor(img,dst,CV_RGB2YCrCb);
for (int col=0;col<dst->width;col++)
{
for (int row=0;row<dst->height;row++)
{
int idxF = row*dst->widthStep + dst->nChannels*col; // Read the image data
CvPoint pt = {row,col};
temp_ptr2[0] += temp_ptr1[0]* 0.0722 + temp_ptr1[1] * 0.7152 +temp_ptr1[2] *0.2126 ; // channel Y
}
}
temp_ptr1
和temp_ptr2
中时,您交换了x
和y
坐标的位置。您应该通过以下方式访问图像:
int idxF = row*dst->widthStep + dst->nChannels*col;
dst
分配的内存,因此在应用程序中会导致内存泄漏。请在函数结束时调用cvReleaseImage(&dst);
temp_ptr1 = &((uchar*)(img->imageData + (img->widthStep*pt.y)))[pt.x*3];