Example #1
0
void VGAWorker::processImage() {
    // If this is the first time processing, initialize VGA processing fields and return
    // without further processing
    if(!oldScreen.data) {
        oldScreen = currentScreen.clone();
        if(lastStableScreen.data)
            lastStableScreen.release();
        lastStableScreen = Mat::zeros(currentScreen.size(), currentScreen.type());
        return;
    }

    // Get difference between last and current images
    float percentDifference = PAOLProcUtils::getVGADifferences(oldScreen, currentScreen);

    // If computer image has not changed significantly
    if(percentDifference < COMP_DIFF_THRESHOLD) {
        // Update stable screen count
        stableScreenCount++;
        //copy the current image to the last stable image location
        if(lastStableScreen.data)
            lastStableScreen.release();
        lastStableScreen = currentScreen.clone();
    }
    else {
        // If there has been a change and the number of images stable before the change
        // were enough, save the last stable image
        if(stableScreenCount >= COMP_REPEAT_THRESHOLD) {
            saveImageWithTimestamp(lastStableScreen);
            realImageIsStored = true;
        }

        stableScreenCount = 0;
        stableTime=currentImageTime;
    }
}
Example #2
0
void VGAWorker::saveLastImage() {
    //if(stableScreenCount>0)
        saveImageWithTimestamp(lastStableScreen);
}
void MainWindow::processImage() {
    // If this is the first time processing, initialize WB processing fields and return
    // without further processing
    if(!oldFrame.data) {
        oldRefinedBackground = Mat::zeros(currentFrame.size(), currentFrame.type());
        oldMarkerModel = Mat::zeros(currentFrame.size(), currentFrame.type());
        return;
    }

    // Get rectified versions of old and current frames
    Mat oldRectified = PAOLProcUtils::rectifyImage(oldFrame, corners);
    Mat currentRectified = PAOLProcUtils::rectifyImage(currentFrame, corners);

    //compare picture to previous picture and store differences in allDiffs
    float numDif;
    Mat allDiffs;
    PAOLProcUtils::findAllDiffsMini(allDiffs, numDif, oldRectified, currentRectified, 40, 1);

    // If there is a large enough difference, reset the stable whiteboard image count and do further processing
    if(numDif > .03) {
        // Reset stable whiteboard image count
        stableWhiteboardCount = 0;
        // Find true differences (ie. difference pixels with enough differences surrounding them)
        float refinedNumDif;
        Mat filteredDiffs;
        PAOLProcUtils::filterNoisyDiffs(filteredDiffs, refinedNumDif, allDiffs);
        displayMat(filteredDiffs, *ui->imDisplay4);

        // Find if there are enough true differences to update the current marker and whiteboard models
        // (ie. professor movement or lighting change detected)
        if(refinedNumDif > .04) {
            // Identify where the motion (ie. the professor) is
            Mat movement = PAOLProcUtils::expandDifferencesRegion(filteredDiffs);
            // Rescale movement info to full size
            Mat mvmtFullSize = PAOLProcUtils::enlarge(movement);
            displayMat(mvmtFullSize, *ui->imDisplay5);

            // Find marker candidates
            Mat markerCandidates = PAOLProcUtils::findMarkerStrokeCandidates(currentRectified);
            // Find marker locations
            Mat markerLocations = PAOLProcUtils::findMarkerStrokeLocations(currentRectified);
            // Keep marker candidates intersecting with marker locations
            Mat currentMarkerWithProf = PAOLProcUtils::filterConnectedComponents(markerCandidates, markerLocations);

            // Use the movement information to erase the professor
            Mat currentMarkerModel = PAOLProcUtils::updateModel(
                        oldMarkerModel, currentMarkerWithProf, mvmtFullSize);
            displayMat(currentMarkerModel, *ui->imDisplay6);

            // Find how much the current marker model differs from the stored one
            float markerDiffs = PAOLProcUtils::findMarkerModelDiffs(oldMarkerModel, currentMarkerModel);
            qDebug("numDif: %f", numDif);
            qDebug("refinedNumDif: %f", refinedNumDif);
            qDebug("markerDiffs: %f", markerDiffs);
            // Save and update the models if the marker content changed enough
            if(markerDiffs > .008) {
                // Save the smooth marker version of the old background image
                Mat oldRefinedBackgroundSmooth = PAOLProcUtils::smoothMarkerTransition(oldRefinedBackground);
                saveImageWithTimestamp(oldRefinedBackgroundSmooth);
                // Update marker model
                oldMarkerModel = currentMarkerModel.clone();
                // Update enhanced version of background
                Mat whiteWhiteboard = PAOLProcUtils::whitenWhiteboard(currentRectified, currentMarkerModel);
                oldRefinedBackground = PAOLProcUtils::updateModel(
                            oldRefinedBackground, whiteWhiteboard, mvmtFullSize);
                displayMat(oldRefinedBackground, *ui->imDisplay2);
            }
        }
    }
    // Otherwise, check if the frames are basically identical (ie. stable)
    else if(numDif < .000001) {
        stableWhiteboardCount++;
        // If the image has been stable for exactly twenty frames, the lecturer is not present, so we
        // can update the marker and whiteboard models without movement information
        if(stableWhiteboardCount == 20) {
            // Save the smooth marker version of the old background image
            Mat oldRefinedBackgroundSmooth = PAOLProcUtils::smoothMarkerTransition(oldRefinedBackground);
            saveImageWithTimestamp(oldRefinedBackgroundSmooth);

            // Update marker model
            // Find marker candidates
            Mat markerCandidates = PAOLProcUtils::findMarkerStrokeCandidates(currentRectified);
            // Find marker locations
            Mat markerLocations = PAOLProcUtils::findMarkerStrokeLocations(currentRectified);
            // Keep marker candidates intersecting with marker locations
            Mat currentMarkerModel = PAOLProcUtils::filterConnectedComponents(markerCandidates, markerLocations);

            oldMarkerModel = currentMarkerModel.clone();
            // Update enhanced version of background
            Mat whiteWhiteboard = PAOLProcUtils::whitenWhiteboard(currentRectified, currentMarkerModel);
            oldRefinedBackground = whiteWhiteboard.clone();
            displayMat(oldRefinedBackground, *ui->imDisplay2);
        }
    }
}