void UpdateCameraView::operator()( osg::Node* node, osg::NodeVisitor* nv ) { Chronometer timer; timer.tic(); cv::Mat currentImg; videoStream >> currentImg; if (!currentImg.empty()) { if ((!augEnvironment->posFound)&&(augEnvironment->synchroniser.tac() > 200)) //wait 1s to match { cvImg = augEnvironment->match(currentImg); augEnvironment->posFound = true; } else if ((augEnvironment->hasProjected)&&(augEnvironment->synchroniser.tac() > 300)&&(!imageCaptured)) { static int count = 0; int lastindex = augEnvironment->parameterFileName.find_last_of("/"); string dir = augEnvironment->parameterFileName.substr(0, lastindex); string errFilename = dir + "/" + augEnvironment->errorFileNameBase + "err.png"; imwrite(errFilename, currentImg); if (augEnvironment->calculateErr) { double meanErr, maxErr; augEnvironment->calculateReprojectionErr(augEnvironment->groundTruthFileName, currentImg); cout<<meanErr<<" "<<maxErr<<endl; } cvImg = currentImg.clone(); imageCaptured = true; } else { cvImg = currentImg.clone(); } osg::ref_ptr<osg::Group> backgroundCameraNode = dynamic_cast<osg::Group*>(node); for (unsigned int i = 0 ; i < backgroundCameraNode->getNumChildren() ; i++) { if (backgroundCameraNode->getChild(i)->getName() == string("Background texture")) { updateBackgroundTexture(backgroundCameraNode->getChild(i)); } } if (augEnvironment->recordVideo) { if (! vWriter.isOpened()) { vWriter.open("recordedStream.mpg", CV_FOURCC('P','I','M','1'), 20.0f, currentImg.size(), true); } vWriter << currentImg; if (! vWriter2.isOpened()) { vWriter2.open("outStream.mpg", CV_FOURCC('P','I','M','1'), 20.0f, currentImg.size(), true); } vWriter2 << cvImg; } traverse( node, nv ); } }