您的位置:首页 > 编程语言 > C语言/C++

OpenCV 实践程序17——用C++实现ip camera的视频播放

2015-07-22 14:20 851 查看
#include "cv.h"
#include "highgui.h"
#include <iostream>
using namespace cv;

int main(int, char**) {
    cv::VideoCapture vcap;
    cv::Mat image;

    const std::string videoStreamAddress = "rtsp://192.168.1.100:554/onvif/live/1"; //rtsp://192.168.1.100:554/onvif/live/1
    if(!vcap.open(videoStreamAddress)) {
        std::cout << "Error opening video stream or file" << std::endl;
        return -1;
    }

    int counter = 0;
    for(;;) 
	{
        counter++;

        if(!vcap.read(image)) 
		{
            std::cout << "No frame" << std::endl;
            cv::waitKey();
        }

        // if the picture is too large, imshow will display warped images, so show only every 2th frame
        if (counter %2!= 0)
            continue;

        cv::imshow("Output Window", image);
	    double rate=vcap.get(CV_CAP_PROP_FPS);
	    std::cout<<"帧率为:"<<rate<<std::endl;
        if(cv::waitKey(1) >= 0) break;
    }
	return 0;
}


该程序因接受速度和解码速度不匹配,会有些错误。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: