Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

videostab with input video not from file?

Hi, I'm using the code bellow for stabilization (OpenCV 3.0, Ubuntu).

It's working fine but I want to be able to change the type of video source (webcam, IP stream...) and resize the input frames, how should I do that?

    std::string videoFile = getMyFile();

    MotionModel model = cv::videostab::MM_AFFINE;
    bool use_gpu = true;

    cv::Ptr<VideoFileSource> video = cv::makePtr<VideoFileSource>(videoFile,true); 

    cv::Ptr<OnePassStabilizer> stabilizer = cv::makePtr<OnePassStabilizer>();

    cv::Ptr<MotionEstimatorBase> MotionEstimator = cv::makePtr<MotionEstimatorRansacL2>(model);

    cv::Ptr<ImageMotionEstimatorBase> ImageMotionEstimator;
    if (use_gpu)
    {
        ImageMotionEstimator = cv::makePtr<KeypointBasedMotionEstimatorGpu>(MotionEstimator);
    }
    else
    {
        ImageMotionEstimator = cv::makePtr<KeypointBasedMotionEstimator>(MotionEstimator);
    }

    stabilizer->setFrameSource(video);
    stabilizer->setMotionEstimator(ImageMotionEstimator);
    stabilizer->setLog(cv::makePtr<cv::videostab::NullLog>());
    stabilizer->setBorderMode(BORDER_REFLECT_101);
    stabilizer->setRadius(10);

    std::string windowTitle = "Stabilized Video";
    cv::namedWindow(windowTitle, cv::WINDOW_AUTOSIZE);

    while(true)
    {
        double procT = (double)getTickCount();
        cv::Mat frame = stabilizer->nextFrame();

        if(frame.empty())
        {
            break;
        }

        procT = ((double)getTickCount() - procT)/getTickFrequency();
        cout << 1/procT << " FPS" << endl;

        cv::imshow(windowTitle,frame);
        cv::waitKey(1);
    }

videostab with input not using a video not from file?file as input?

Hi, I'm using the code bellow for stabilization (OpenCV 3.0, Ubuntu).

It's working fine but I want to be able to change the type of video source (webcam, IP stream...) and resize the input frames, how should I do that?

    std::string videoFile = getMyFile();

    MotionModel model = cv::videostab::MM_AFFINE;
    bool use_gpu = true;

    cv::Ptr<VideoFileSource> video = cv::makePtr<VideoFileSource>(videoFile,true); 

    cv::Ptr<OnePassStabilizer> stabilizer = cv::makePtr<OnePassStabilizer>();

    cv::Ptr<MotionEstimatorBase> MotionEstimator = cv::makePtr<MotionEstimatorRansacL2>(model);

    cv::Ptr<ImageMotionEstimatorBase> ImageMotionEstimator;
    if (use_gpu)
    {
        ImageMotionEstimator = cv::makePtr<KeypointBasedMotionEstimatorGpu>(MotionEstimator);
    }
    else
    {
        ImageMotionEstimator = cv::makePtr<KeypointBasedMotionEstimator>(MotionEstimator);
    }

    stabilizer->setFrameSource(video);
    stabilizer->setMotionEstimator(ImageMotionEstimator);
    stabilizer->setLog(cv::makePtr<cv::videostab::NullLog>());
    stabilizer->setBorderMode(BORDER_REFLECT_101);
    stabilizer->setRadius(10);

    std::string windowTitle = "Stabilized Video";
    cv::namedWindow(windowTitle, cv::WINDOW_AUTOSIZE);

    while(true)
    {
        double procT = (double)getTickCount();
        cv::Mat frame = stabilizer->nextFrame();

        if(frame.empty())
        {
            break;
        }

        procT = ((double)getTickCount() - procT)/getTickFrequency();
        cout << 1/procT << " FPS" << endl;

        cv::imshow(windowTitle,frame);
        cv::waitKey(1);
    }