[OpenCV] Motion detection con differenze da background

nucce

Utente Attivo
52
0
CPU
AMD Athlon64 X2 500+
Scheda Madre
Asus M3A32-MVP Deluxe WiFi Edition
HDD
Western Digital Raptor 150GB 10.000rpm
RAM
Corsair Dominator 4x2GB 1066GHz
GPU
Sapphire ATi Radeon HD3870
Audio
Creative Sound Blaster Audigy SE
Monitor
Samsung SyncMaster 931BW
PSU
Corsair Tx750w 750W
Case
CoolerMaster Centurion 5
OS
Windows 7 64bit
Salve a tutti.
Stavo dando un'occhiata alla libreria OpenCV e stavo provando il motion detection tramite la modalità cvGaussianBGModel. Per ora mi sono limitato a fare un collage da due tutorial per capirne meglio il funzionamento e fare delle prove.
Visto che OpenCV non riesce a riconoscere la mia webcam l'ho prima inizializzata con la libreria InputVideo (che si appoggia su DirectX) o poi estratto un frame che ho poi fornito al Gaussian Model che dovrebbe oltre a calcolare la differenze dovrebbe ridare il background con
cvShowImage("BG", bgModel->background);
ma io nella finestra BG non vedo nulla, vedo solo grigio... non capisco perchè!!! Questo è il mio codice:

Codice:
#include "stdafx.h"

#include <videoInput.h>

#include <iostream>

#include <cv.h>
#include <cxcore.h>
#include <cvaux.h>
#include <highgui.h>

int _tmain(int argc, _TCHAR* argv[])
{
    
    videoInput VI;
    int numDevices = VI.listDevices();
    int device1 = 0;
    VI.setupDevice(device1);
    int width = VI.getWidth(device1);
    int height = VI.getHeight(device1);
    
    IplImage* image = cvCreateImage(cvSize(width, height), 8, 3);

    unsigned char* yourBuffer = new unsigned char[VI.getSize(device1)];

    cout << "Tacking the background" << endl;
    for(int firstFrame = 0; firstFrame <= 5; firstFrame++){
        
        /* Capture 1 video frame for initialization */
        VI.getPixels(device1, yourBuffer, false, false);
        image->imageData = (char*)yourBuffer;
        cvConvertImage(image, image, CV_CVTIMG_FLIP); //src, dst, flag
    }
    cvSaveImage("Background.jpg", image);

    /* Create windows */
    cvNamedWindow("Camera", 1);    //Camera Live
    cvNamedWindow("BG", 1);           //Background
    cvNamedWindow("Back", 1);        //Background
    cvNamedWindow("FG", 1);           //Foreground - Differential Mask

    /* Select parameters for Gaussian model. */
    CvGaussBGStatModelParams* params = new CvGaussBGStatModelParams;
    params->win_size=2;
    params->n_gauss=5;
    params->bg_threshold=0.7;
    params->std_threshold=3.5;
    params->minArea=15;
    params->weight_init=0.05;
    params->variance_init=30;
    
    
    CvBGStatModel* bgModel = cvCreateGaussianBGModel(image, params);
    
    while(1)
    {
        /* Grab a fram */
        VI.getPixels(device1, yourBuffer, false, false);
        image->imageData = (char*)yourBuffer;
        cvConvertImage(image, image, CV_CVTIMG_FLIP); //src, dst, flag
        
        /* Update model */
        cvUpdateBGStatModel(image, bgModel);
        
        /* Display results */
        cvShowImage("Camera", image);
        cvShowImage("BG", bgModel->background);
        cvShowImage("FG", bgModel->foreground);
        
        /* If "ESC" pressed exit */
        if(cvWaitKey(15)==27) break;
    }
    
    /* Release Resources */
    VI.stopDevice(device1);
    cvDestroyWindow("BG");
    cvDestroyWindow("FG");
    cvDestroyWindow("Camera");
    cvReleaseBGStatModel( &bgModel );
    cvReleaseImage(&image);
    
    return 0;
}
 

xxGIOxx

Nuovo Utente
1
0
Salve, ho letto il tuo post e volevo chiederti se sapevi dirmi dove posso trovare quei tutorial di cui parli. Devo fare una ricerca quindi non mi serve programmare un software di motion detection ma solo capire il funzionamento. Sai aiutarmi? grazie
 

nucce

Utente Attivo
52
0
CPU
AMD Athlon64 X2 500+
Scheda Madre
Asus M3A32-MVP Deluxe WiFi Edition
HDD
Western Digital Raptor 150GB 10.000rpm
RAM
Corsair Dominator 4x2GB 1066GHz
GPU
Sapphire ATi Radeon HD3870
Audio
Creative Sound Blaster Audigy SE
Monitor
Samsung SyncMaster 931BW
PSU
Corsair Tx750w 750W
Case
CoolerMaster Centurion 5
OS
Windows 7 64bit

Entra

oppure Accedi utilizzando
Discord Ufficiale Entra ora!