Example #1
0
bool QVideoCapture::read_frame()
{
    if( ( m_cvCapture.read(m_frame) ) && ( !m_frame.empty() ) )
    {
        emit frame_was_captured(m_frame);
        if(!deviceFlag)
        {
            emit capturedFrameNumber((int)m_cvCapture.get(CV_CAP_PROP_POS_FRAMES));
        }
        return true;
    }
    else
    {
        this->pause();
        return false;
    }
}
void MainWindow::createThreads()
{
    //-------------------Pointers for objects------------------------
    pt_improcThread = new QThread(this); // Make an own QThread for opencv interface
    pt_opencvProcessor = new QOpencvProcessor();
    std::string cascadeFilename = std::string("haarcascades/haarcascade_frontalface_alt.xml");
    #ifdef HAARCASCADES_PATH
        //cascadeFilename = std::string(HAARCASCADES_PATH) + std::string("haarcascade_frontalface_alt.xml");
        cascadeFilename = std::string(LBPCASCADES_PATH) + std::string("lbpcascade_frontalface.xml");
    #endif
    bool loadResult = pt_opencvProcessor->loadClassifier( cascadeFilename );
    qWarning("Haarcascade %s was %s", cascadeFilename.c_str(), loadResult ? "loaded" : "not loadeded");
    pt_opencvProcessor->moveToThread( pt_improcThread );
    connect(pt_improcThread, SIGNAL(finished()), pt_opencvProcessor, SLOT(deleteLater()));

    //--------------------QVideoCapture------------------------------
    pt_videoThread = new QThread(this);
    pt_videoCapture = new QVideoCapture();
    pt_videoCapture->moveToThread(pt_videoThread);
    connect(pt_videoThread, SIGNAL(started()), pt_videoCapture, SLOT(initializeTimer()));
    connect(pt_videoThread, SIGNAL(finished()), pt_videoCapture, SLOT(close()));
    connect(pt_videoThread, SIGNAL(finished()), pt_videoCapture, SLOT(deleteLater()));

    //----------Register openCV types in Qt meta-type system---------
    qRegisterMetaType<cv::Mat>("cv::Mat");
    qRegisterMetaType<cv::Rect>("cv::Rect");

    //----------------------Connections------------------------------
    //connect(pt_videoCapture, SIGNAL(frame_was_captured(cv::Mat)), pt_opencvProcessor, SLOT(custom_algorithm(cv::Mat)),Qt::BlockingQueuedConnection);
    connect(pt_videoCapture, SIGNAL(frame_was_captured(cv::Mat)), pt_opencvProcessor, SLOT(searchFace(cv::Mat)),Qt::BlockingQueuedConnection);
    connect(pt_opencvProcessor, SIGNAL(frame_was_processed(cv::Mat,double)), pt_display, SLOT(updateImage(cv::Mat,double)), Qt::BlockingQueuedConnection);
    connect(pt_display, SIGNAL(selectionUpdated(cv::Rect)), pt_opencvProcessor, SLOT(setRect(cv::Rect)));

    //----------------------Thread start-----------------------------
    pt_improcThread->start();
    pt_videoThread->start();
}