FlowField_sV* Project_sV::requestFlow(int leftFrame, int rightFrame, const FrameSize frameSize) throw(FlowBuildingError) { Q_ASSERT(leftFrame < m_frameSource->framesCount()); Q_ASSERT(rightFrame < m_frameSource->framesCount()); if (dynamic_cast<EmptyFrameSource_sV*>(m_frameSource) == NULL) { FlowSourceV3D_sV *v3d; if ((v3d = dynamic_cast<FlowSourceV3D_sV*>(m_flowSource)) != NULL) { v3d->setLambda(m_preferences->flowV3DLambda()); try { return m_flowSource->buildFlow(leftFrame, rightFrame, frameSize); } catch (FlowBuildingError err) { m_v3dFailCounter++; qDebug() << "Failed creating optical flow, falling back to OpenCV ..."; qDebug() << "Failed attempts so far: " << m_v3dFailCounter; delete m_flowSource; m_flowSource = new FlowSourceOpenCV_sV (this); return m_flowSource->buildFlow(leftFrame, rightFrame, frameSize); } } return m_flowSource->buildFlow(leftFrame, rightFrame, frameSize); } else { throw FlowBuildingError(tr("Empty frame source; Cannot build flow.")); } }
FlowField_sV* Project_sV::requestFlow(int leftFrame, int rightFrame, const FrameSize frameSize) throw(FlowBuildingError) { Q_ASSERT(leftFrame < m_frameSource->framesCount()); Q_ASSERT(rightFrame < m_frameSource->framesCount()); if (dynamic_cast<EmptyFrameSource_sV*>(m_frameSource) == NULL) { FlowSourceV3D_sV *v3d; if ((v3d = dynamic_cast<FlowSourceV3D_sV*>(m_flowSource)) != NULL) { v3d->setLambda(m_preferences->flowV3DLambda()); try { return m_flowSource->buildFlow(leftFrame, rightFrame, frameSize); } catch (FlowBuildingError err) { m_v3dFailCounter++; qDebug() << "Failed creating optical flow, falling back to OpenCV ..."; qDebug() << "Failed attempts so far: " << m_v3dFailCounter; delete m_flowSource; QSettings m_settings; int algo = m_settings.value("preferences/preferredOpenCVAlgo", 0).toInt(); int dev_index = m_settings.value("preferences/oclDriver", -1).toInt(); QString method = m_settings.value("preferences/flowMethod", "OpenCV-CPU").toString(); if (method == "OpenCV-CPU") { dev_index = -1; } m_flowSource = new FlowSourceOpenCV_sV(this, algo, dev_index); return m_flowSource->buildFlow(leftFrame, rightFrame, frameSize); } } return m_flowSource->buildFlow(leftFrame, rightFrame, frameSize); } else { throw FlowBuildingError(tr("Empty frame source; Cannot build flow.")); } }