videostab not using a video file as input?

asked 2016-03-09 07:39:05 -0600

ThomCastel gravatar image

updated 2016-03-10 03:59:26 -0600

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);
    }
edit retag flag offensive close merge delete

Comments

For IP stream: see How do I access an IP Camera?, so just use the correct input string.

I think that you cannot in the current version use a webcam device or set the capture parameter but what you could do is to modify the source code to have access to the VideoCapture member: https://github.com/Itseez/opencv/blob/3.1.0/modules/videostab/src/frame_source.cpp#L102.

Eduardo gravatar imageEduardo ( 2016-03-11 07:23:14 -0600 )edit

Yes, I got it to work with an IP camera. I guess I'll have to modify the code, even to only resize the input stream images. Thanks.

ThomCastel gravatar imageThomCastel ( 2016-03-11 08:19:01 -0600 )edit