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); }
ImageDataPtr ImageData::getSubRegion(int x, int y, int width, int height) { ImageData * retour = new ImageData(); CvRect cvrect = cvRect(x,y,width, height); if( width < 0 ) { cvrect.x = x + width; cvrect.width = -width; } if( height < 0 ) { cvrect.y = y + height; cvrect.height = -height; } retour->m_image = cvCreateImage( cvSize(cvrect.width,cvrect.height),m_image->depth,m_image->nChannels); cvSetImageROI(m_image,cvrect);// définit la région d'intérêt cvCopy(m_image, retour->m_image,0);// copier le bout sélectionné dans dest return ImageDataPtr( retour ); }
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(); }