Esempio n. 1
1
void App::process()
{
    if (sources.empty())
    {
        cout << "Loading default images...\n";
        sources.resize(2);
        sources[0] = new ImageSource("data/stitching/t100mA.JPG");
        sources[1] = new ImageSource("data/stitching/t100mB.JPG");
    }

    stitcher_cpu.setFeaturesMatcher(new cv::detail::BestOf2NearestMatcher(false, 0.5));
    stitcher_gpu.setFeaturesMatcher(new cv::detail::BestOf2NearestMatcher(true, 0.5));

    cout << "\nControls:\n"
         << "  space - chanege CPU/GPU mode\n\n";

    vector<Mat> imgs(sources.size());
    Mat pano;

    double total_fps = 0;
    bool first_iter_cpu = true;
    bool first_iter_gpu = true;

    while (!exited)
    {
        int64 start = getTickCount();

        for (size_t i = 0; i < sources.size(); ++i)
            sources[i]->next(imgs[i]);

        int64 proc_start = getTickCount();

        if (use_gpu)
        {
            if (first_iter_gpu)
            {
                stitcher_gpu.estimateTransform(imgs);
                first_iter_gpu = false;
            }
            stitcher_gpu.composePanorama(imgs, pano);
        }
        else
        {
            if (first_iter_cpu)
            {
                stitcher_cpu.estimateTransform(imgs);
                first_iter_cpu = false;
            }
            stitcher_cpu.composePanorama(imgs, pano);
        }

        double proc_fps = getTickFrequency()  / (getTickCount() - proc_start);

        stringstream msg; msg << "total FPS = " << setprecision(4) << total_fps;
        printText(pano, msg.str(), 0);

        msg.str(""); msg << "processing FPS = " << setprecision(4) << proc_fps;
        printText(pano, msg.str(), 1);

        printText(pano, use_gpu ? "mode = GPU" : "mode = CPU", 2);

        imshow("stitching_demo", pano);

        processKey(waitKey(3) & 0xff);

        total_fps = getTickFrequency()  / (getTickCount() - proc_start);

        cout << endl;
    }
}
Esempio n. 2
0
PERF_TEST_P(stitch, a123, TEST_DETECTORS)
{
    Mat pano;

    vector<Mat> imgs;
    imgs.push_back( imread( getDataPath("stitching/a1.png") ) );
    imgs.push_back( imread( getDataPath("stitching/a2.png") ) );
    imgs.push_back( imread( getDataPath("stitching/a3.png") ) );

    Ptr<detail::FeaturesFinder> featuresFinder = GetParam() == "orb"
            ? Ptr<detail::FeaturesFinder>(new detail::OrbFeaturesFinder())
            : Ptr<detail::FeaturesFinder>(new detail::SurfFeaturesFinder());

    Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb"
            ? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE)
            : makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE);

    declare.time(30 * 20).iterations(20);

    while(next())
    {
        Stitcher stitcher = Stitcher::createDefault();
        stitcher.setFeaturesFinder(featuresFinder);
        stitcher.setFeaturesMatcher(featuresMatcher);
        stitcher.setWarper(makePtr<SphericalWarper>());
        stitcher.setRegistrationResol(WORK_MEGAPIX);

        startTimer();
        stitcher.stitch(imgs, pano);
        stopTimer();
    }

    EXPECT_NEAR(pano.size().width, 1182, 50);
    EXPECT_NEAR(pano.size().height, 682, 30);

    SANITY_CHECK_NOTHING();
}