void bowFeatures(std::vector<BOWImg> &images, cv::Mat vocabulary, std::string ext) { cv::initModule_nonfree(); Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create(ext); Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce"); BOWImgDescriptorExtractor bow(extractor,matcher); bow.setVocabulary(vocabulary); #ifdef _USE_OPENMP_ #pragma omp parallel for for(unsigned i = 0;i<images.size();i++) { bow.compute(images[i].img,images[i].keyPoints,images[i].BOWDescriptor); // To Do: Need normalization or not ? normalize(images[i].BOWDescriptor,images[i].BOWDescriptor,1.0,0.0,NORM_MINMAX); } #else for(std::vector<BOWImg>::iterator iter = images.begin();iter != images.end(); iter++) { bow.compute(iter->img,iter->keyPoints,iter->BOWDescriptor); // To Do: Need normalization or not ? normalize(iter->BOWDescriptor,iter->BOWDescriptor,1.0,0.0,NORM_MINMAX); } #endif }
//! Load settings from config and use them to set up mosaicer components, and set them going. int main(int argc, char* argv[]) { //grc::FeatureDetector * featureDetector = 0; //Delete these after (potentially) handling exceptions grc::Renderer * mosaicRenderer = 0; grc::EvaluationFunction * evaluationFunction = 0; try { CMosaicingParams PARAMS(0, 0); config config(argc > 1 ? argv[1] : "default.cfg"); PARAMS.init(&config); PARAMS.BOW.DescriptorBinning.RADIUS = PARAMS.PatchDescriptor.radius(); boost::scoped_ptr<CImageSource> pImageLoader( CImageSource::makeImageSource( PARAMS.Im)); boost::scoped_ptr<CFeatureExtractor> pFeatureExtractor ( CFeatureExtractor::makeFeatureExtractor(PARAMS.Im, PARAMS.Corner, PARAMS.PatchDescriptor, PARAMS.DescriptorSetClustering)); grc::Transform::eTransType_s = (grc::Enums::eTransformType)(int)PARAMS.TransformType; grc::Transform::warpMethod_s = (grc::Enums::eWarpMethod)(int)PARAMS.WarpMethod == grc::Enums::eWarpBilinear ? CV_INTER_LINEAR : CV_INTER_NN; grc::cDescriptor::eDescriptorType_s = (grc::Enums::eDescriptorInvarianceType)(int)PARAMS.PatchDescriptorType; grc::cDescriptor::eDescriptorSize_s = (grc::Enums::eDescriptorSize)(int)PARAMS.PatchDescriptorSize; grc::ImageSource imSource((grc::Enums::eVideoSource)(int)PARAMS.VideoSource, PARAMS.Im.ImageDir.IMAGE_DIR.asSz(), PARAMS.Im.VideoFile.FILENAME.asSz(), (grc::Enums::eDisplayMode)(int)PARAMS.MosaicDestination, PARAMS.MosaicSaveDir.asSz()); //Pure-Translation-Extended "H:/Projects/External/DTA003 Image mosaicing/Test Data/Rangiora" IplImage * pIm = cvLoadImage("/home/data/data/data/mosaicing/FixedCamera800/IMG_0004.JPG"); grc::FeatureMatcher2 * featureMatcher = 0; //featureMatcher = new grc::BFFeatureMatcher(imSource, *pFeatureExtractor, PARAMS.BOWMatching); CBoW bow(PARAMS.BOW); featureMatcher = new grc::BoWFeatureMatcher(imSource, *pFeatureExtractor, bow, PARAMS.BOWMatching); grc::BaySACTransformEstimator transformEstimator(*featureMatcher, PARAMS.RANSACHomography, PARAMS.Im.getCamCalibrationMat(), ((bool)PARAMS.MarkCorrespondences) ? pImageLoader.get() : 0); switch(PARAMS.EvaluationFunction) { case grc::Enums::eSSDEvaluation: evaluationFunction = new grc::SumSquaredErrorEvaluationFunction; break; } if(evaluationFunction == 0 && PARAMS.EvaluationFunction != grc::Enums::eNoEvaluation) throw new grc::GRCException("main: No evaluation function initialised"); CvSize mosaicSize = cvSize(PARAMS.MosaicX,PARAMS.MosaicY); grc::TransformEngine engine(transformEstimator, PARAMS.MaxFrames, PARAMS.IncrementalRendering ? 1 : 0, PARAMS.LM * PARAMS.LMIterations, mosaicSize, PARAMS.SkipFrames ? grc::Enums::eChooseSequentialSkip : grc::Enums::eChooseSequential, PARAMS.FullFrameUpdateFreq, PARAMS.MaxSearchForTransform); switch(PARAMS.RendererType) { case grc::Enums::eBasicRenderer: mosaicRenderer = new grc::Renderer(imSource, engine, mosaicSize, evaluationFunction); break; case grc::Enums::eFeatheredRenderer: mosaicRenderer = new grc::FeatheredRenderer(imSource, engine, mosaicSize, PARAMS.FeatherRadius, evaluationFunction); break; case grc::Enums::eMultiScaleRenderer: mosaicRenderer = new grc::MultiScaleFeatheredRenderer(imSource, engine, mosaicSize, PARAMS.FeatherRadius, evaluationFunction); break; case grc::Enums::eDijkstraRenderer: mosaicRenderer = new grc::DijkstraCutRenderer(imSource, engine, mosaicSize, PARAMS.DijkstraScale, evaluationFunction); break; } if(mosaicRenderer == 0) throw new grc::GRCException("main: No renderer initialised"); //This ensures images are captured by this thread: CStopWatch s; s.startTimer(); imSource.doCaptureImages(&engine, mosaicRenderer); s.stopTimer(); std::cout << s.getElapsedTime() << " seconds total" << endl; //PARAMS.printUseSummary(); //PARAMS.printCfgFile(); } catch(grc::GRCException * pEx) { std::cout << "ERROR: Unhandled exception: " << *(pEx->GetErrorMessage()) << std::endl << "Exiting..."; cvDestroyAllWindows(); #ifndef __GNUC__ Sleep(5000); #endif delete pEx; } //delete featureDetector; delete mosaicRenderer; delete evaluationFunction; }