예제 #1
0
void VideoExtractor::processFrame(void)
{
    IplImage * src1, * src2;

    src1 = m_videoStream[0]->getImage();
    if(m_dual)
        src2 = m_videoStream[1]->getImage();

    ImageDataPtr source1 = nullptr, source2 = nullptr;

    if(src1)
        source1 = ImageDataPtr(new ImageData(*src1));
    if( m_dual && src2 )
        source2 = ImageDataPtr(new ImageData(*src2));
    else if(! src1)
        throw Exception::buildException("Aucune source valable", "VideoExtractor",
                                        "run", EPC);

    ImageDataPtr result;
    //endOfCapture = timer.nsecsElapsed();
    if( m_isHandleActived )
        result = VirtualHandle::executeHandle(m_paramHandle.toString().toStdString(), source1, source2);
    else
        result = source1;
    //endOfHandle = timer.nsecsElapsed();
    if( ! result)
    {
        throw Exception::buildException("Votre traitement ne retourne pas de résultat!", "VideoExtractor",
                                        "run", EPC);
    }

    m_nbImageHandled++;
    emit imageHandled(result, source1, source2);
}
예제 #2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    m_areaMode( Default ),
    m_extractor(new VideoExtractor() ),
    m_isHandleActived(true),
    m_isPlay(false),
    m_subImage(nullptr),
    m_subImageSource1(nullptr),
    m_subImageSource2(nullptr),
    m_subResults(nullptr),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->mdiArea->setMainWindow(this);

    connect(ui->actionQuitter, SIGNAL(triggered()), qApp, SLOT( quit() ) );

    connect(ui->buttonPrevious, SIGNAL(clicked()), m_extractor, SLOT(previous()));
    connect(ui->buttonNext, SIGNAL(clicked()), m_extractor, SLOT(next()));

    ui->mdiAreaMode->addItem("Default", Default);
    ui->mdiAreaMode->addItem("Tabulation", Tabulation);
    ui->mdiAreaMode->addItem("Libre", Free);

    int max = 1<<(sizeof(int)*8-2) ;

    m_extractor->changeHandleParameters( new ComboBox("Traitement", VirtualHandle::getAllHandleName(),
                                                      MainHandle),
                                            ui->parametersArea );
    m_extractor->changePeriodeParameters( new Slider("Time", 200000000, 0, max) ,
                                          ui->parametersArea );

    /* obligatoire, à n'appeler qu'une unique fois et dans une fonction /!\ */
    qRegisterMetaType<ImageDataPtr>("ImageDataPtr");
    connect( m_extractor, SIGNAL(imageHandled(ImageDataPtr,ImageDataPtr,ImageDataPtr) ),
             this, SLOT(setImage(ImageDataPtr,ImageDataPtr,ImageDataPtr) ) );
    connect( m_extractor, SIGNAL(streamFinished()), this, SLOT(playPause()));

    VideoReader * cam1 = new VideoReader();
    cam1->useCamera(); //or FolderReader * cam1 = new FolderReader("img/");

    m_extractor->useSource(cam1, 0);
    m_extractor->showParameters( ui->parametersArea );

    ui->mdiAreaMode->setCurrentIndex( ui->mdiAreaMode->findData(m_areaMode) );
    VirtualHandle::setView(ui->mdiArea);

    ui->sliderCurseur->setTracking(true);

    m_extractor->start();
    updateSeek();
}
예제 #3
0
void VideoExtractor::run(void)
{
    bool stoppedByUser = true;
    QElapsedTimer timer;
    //qint64 endOfCapture;
    //qint64 endOfHandle;
    qint64 begin;
    IplImage * src1, * src2;
    timer.start();
    while( ! m_stopped )
    {
        mutex.lock();
        while(!threadLanced)
        {
            cond.wait(&mutex);
        }
        mutex.unlock();

        begin = timer.nsecsElapsed();

        m_videoStream[0]->grab(); // a for for that ... I'm too lazy
        m_videoStream[1]->grab();

        if( m_timeMax && m_timeMax > begin)
        {
            stoppedByUser = false;
            break;
        }

        src1 = m_videoStream[0]->getImage();
        src2 = m_videoStream[1]->getImage();

        ImageDataPtr source1 = nullptr, source2 = nullptr;

        if(src1)
            source1 = ImageDataPtr(new ImageData(*src1));
        if(src2)
            source2 = ImageDataPtr(new ImageData(*src2));
        else if(! src1)
            break;

        //endOfCapture = timer.nsecsElapsed();
        ImageDataPtr result;
        if(isStarted())
            result = VirtualHandle::executeHandle(m_paramHandle.toString().toStdString(), source1, source2);
        else
            result = source1;
        //endOfHandle = timer.nsecsElapsed();

        if( ! result)
        {
            throw Exception::buildException("Votre traitement ne retourne pas de résultat!", "VideoExtractor", "run", EPC);
        }

        m_nbImageHandled++;
        emit imageHandled(result, source1, source2);
        if( m_nbMaxImage && m_nbImageHandled == m_nbMaxImage )
        {
            stoppedByUser = false;
            break;
        }
        qint64 waitTime = ( m_paramPeriod.toInt() - timer.nsecsElapsed() + begin )/1000;
        if(waitTime < 0)
        {
         /*   std::cerr << "Warning : la boucle a du retard : " <<  waitTime
                      << "\nDuree de la boucle : " << m_paramPeriod.toInt()
                      << "\nDuree reelle : " << timer.nsecsElapsed() << std::endl; */
        }
        else
            QThread::usleep( waitTime );
    }

    emit finished(stoppedByUser);
    deleteLater();
}