Ask Your Question

zulugula's profile - activity

2018-10-02 07:32:59 -0600 answered a question Static video

Thanks for reply. That's beacuse my teacher says diff must be zero, so when i got value other than zero I got confused.

2018-10-02 07:28:37 -0600 marked best answer 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=woXNR... , 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);
}
2018-10-02 07:28:37 -0600 received badge  Scholar (source)
2018-09-21 01:06:14 -0600 received badge  Editor (source)
2018-09-21 01:06:14 -0600 edited question Static video

Static video Hi, I want to check if recieved image is freezed, eg. ip camera is sending the same frame all the time. I d

2018-09-20 17:55:05 -0600 asked a question Static video

Static video Hi, I want to check if recieved image is freezed, eg. ip camera is sending the same frame all the time. I d