使用OpenCV去除闪烁?

时间:2011-03-08 11:07:44

标签: opencv flicker

我是openCV的新手。我已经在ubuntu系统上安装了opencv库,编译它并试图在opencv中查看一些图像/视频处理应用程序以了解更多信息。

我很想知道OpenCV库是否有任何算法/类用于删除捕获的视频中的闪烁?如果是,我应该深入了解哪些文件或代码?

如果openCV没有它,那么在其他一些视频处理库/ SDK / Matlab中是否有任何标准实现,它们提供了从视频序列中去除闪烁的算法?

任何指针都很有用

谢谢。

-AD。

2 个答案:

答案 0 :(得分:1)

我不知道任何去除视频的标准方法。

但是VirtualDub是一个视频处理软件,它有一个用于消除视频的过滤器。您可以找到它的过滤器源和文档(可能是算法描述)here

答案 1 :(得分:1)

我编写了自己的Deflicker C ++函数。这里是。您可以按原样剪切和粘贴此代码 - 除了通常的openCV之外,不需要任何标头。

    Mat deflicker(Mat,int);
    Mat prevdeflicker;
    Mat deflicker(Mat Mat1,int strengthcutoff = 20){  //deflicker - compares each pixel of the frame to a previously stored frame, and throttle small changes in pixels (flicker)

    if (prevdeflicker.rows){//check if we stored a previous frame of this name.//if not, theres nothing we can do. clone and exit
         int i,j;
        uchar* p;
        uchar* prevp;
        for( i = 0; i < Mat1.rows; ++i)
        {
            p = Mat1.ptr<uchar>(i);
            prevp = prevdeflicker.ptr<uchar>(i);
            for ( j = 0; j < Mat1.cols; ++j){  

                Scalar previntensity = prevp[j];
                Scalar intensity = p[j];
                int strength = abs(intensity.val[0] - previntensity.val[0]);

                if(strength < strengthcutoff){ //the strength of the stimulus must be greater than a certain point, else we do not want to allow the change
                    //value 25 works good for medium+ light.  anything higher creates too much blur around moving objects. 
                    //in low light however this makes it worse, since low light seems to increase contrasts in flicker - some flickers go from 0 to 255 and back.  :(
                    //I need to write a way to track large group movements vs small pixels, and only filter out the small pixel stuff.  maybe blur first?

                    if(intensity.val[0] > previntensity.val[0]){  // use the previous frames value.  Change it by +1 - slow enough to not be noticable flicker
                        p[j] = previntensity.val[0] + 1;  
                    }else{
                        p[j] = previntensity.val[0] - 1;
                    }
                }

            }

        }//end for
    }

    prevdeflicker = Mat1.clone();//clone the current one as the old one.
    return Mat1;
}

将其称为:Mat = deflicker(Mat)。它需要一个循环和一个灰度图像,如下所示:

for(;;){
    cap >> frame; // get a new frame from camera
    cvtColor( frame, src_grey, CV_RGB2GRAY );  //convert to greyscale - simplifies everything

    src_grey = deflicker(src_grey);  // this is the function call

    imshow("grey video", src_grey);
    if(waitKey(30) >= 0) break;
}