Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Static video

Hi, I want to check if recieved image is freezed, eg. ip camera is sending the same frame all the time. I decided to simulate freeze with test avi video like this: https://www.youtube.com/watch?v=woXNRYAlbNg , theoretically difference between two cv::mat frames (with 4 sec. interval) should be zero. But it isn't. Does anybody can help me?

Static video

Hi, I want to check if recieved image is freezed, eg. ip camera is sending the same frame all the time. I decided to simulate freeze with test avi video like this: https://www.youtube.com/watch?v=woXNRYAlbNg , theoretically difference between two cv::mat frames (with 4 sec. interval) should be zero. But it isn't. Does anybody can help me?

Here is code:

cv::Mat frame1, frame2;
cv::VideoCapture cap;
cap.open("myTestVid.avi");
cap.read(frame1);
sleep(3);
cap.read(frame2);
compareFrames(frame1, frame2);

And here is compareFrames method:

void CompareWorker::compareFrames(Mat frame1, Mat frame2)
{
//    std::cout << "compare frames";
    QImage firstImage((const unsigned char *)(frame1.data), frame1.cols, frame1.rows, QImage::Format_RGB888);
    QImage secondImage((const unsigned char*)(frame2.data), frame2.cols, frame2.rows, QImage::Format_RGB888);


    double totaldiff = 0.0;
    double diffLevelVal = 0.0 ;
    if((frame1.rows == frame2.rows) && (frame1.cols == frame2.cols)){
        for ( int y = 0 ; y < firstImage.height() ; y++ ) {
            //odczytywanie linii obrazków
            uint *firstLine = ( uint* )firstImage.scanLine( y ) ;
            uint *secondLine = ( uint* )secondImage.scanLine( y ) ;
            for ( int x = 0 ; x < firstImage.width() ; x++ ) {
                uint pixelFirst = firstLine[ x ] ;
                int rFirst = qRed( pixelFir ) ;
                int gFirst = qGreen( pixelFir ) ;
                int bFirst = qBlue( pixelFir ) ;

                uint pixelSecond = secondLine[ x ] ;
                int rSecond = qRed( pixelSec ) ;
                int gSecond = qGreen( pixelSec ) ;
                int bSecond = qBlue( pixelSec ) ;
                double rDiff = std::abs(rFirst - rSec)/255.0;
                totaldiff+=rDiff;
                double gDiff = std::abs(gFirst - gSec)/255.0;
                totaldiff+=gDiff;
                double bDiff = std::abs(bFirst - bSec)/255.0;
                totaldiff+=bDiff;
            }
        }

    }
    diffLevelVal = ((totaldiff * 100)  / (firstImage.width() * firstImage.height() * 3));

    emit returnDiffVal(diffLevelVal);
}