Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
增加亮度不会产生所需的效果 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 - Fatal编程技术网

增加亮度不会产生所需的效果 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);
    。这会在开始处理之前将输入图像填充为空白,因此您应该删除这一行

  • 为了获得最大的速度,您应该反转这两个循环,以便首先在行上迭代,然后在列上迭代。这是因为OpenCV中的图像是在内存中逐行存储的,因此通过增加列来访问图像在缓存使用率方面更为有效

  • 临时变量
    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];