Opencv3 receiving RTSP Network video stream

Source: Internet
Author: User
Tags gstreamer

Project needs, recently in the study of the reception of webcam video streams. Prior to the use of VLC, simple operation, the receiving effect is particularly good, slightly delayed, and VLC is open source ... If the code is a bit tough, you can rewrite it yourself.

But, however, this will be a relatively large project right, lazy people have lazy way, the use of OPENCV self-function to receive the RTSP video stream function, Opencv2 and OPENCV3 code are here, the following:

OPENCV2:

#include "opencv2/opencv.hpp"

#include "opencv2/core/core.hpp"

#include <opencv2/video/video.hpp>

#include "opencv2/highgui/highgui.hpp"

#include <fstream>

#include <iostream>

The author of OpenCV version 3.0, so the code is version 2.x, contains packages that are 3.0 packages

using namespace CV;

using namespace Std;

int main (int argc, char **argv) {

Iplimage *pframe = NULL, *srcimage=null;

Cvcapture *pcapture = NULL;

Pcapture =cvcreatefilecapture ("rtsp://0.0.0.1/stream1");//your own RTSP address

if (!pcapture) {

printf ("Can not get the videostream from the camera!\n");

return NULL;

}

Doublerate=cvgetcaptureproperty (Pcapture,cv_cap_prop_fps);

Cvsize size=cvsize ((int) cvgetcaptureproperty (pcapture,cv_cap_prop_frame_width), (int) Cvgetcaptureproperty ( Pcapture,cv_cap_prop_frame_height));

Cvvideowriter*writer=cvcreatevideowriter ("Videotest.avi", CV_FOURCC (' M ', ' J ', ' P ', ' G '), rate,size);

while (1) {

Pframe = Cvqueryframe (pcapture);

Srcimage=cvcloneimage (pframe);

Cvwriteframe (Writer,srcimage);

Cvshowimage ("123234", srcimage);

cout<<pframe->width<< "," <<pFrame->height<<endl;

Cvwaitkey (30);

Cvreleaseimage (&srcimage);

Srcimage=null;

}

Cvreleasecapture (&pcapture);

Cvreleaseimage (&pframe);

return 0;

}

OPENCV3:

#include "stdafx.h"

#include <opencv2/opencv.hpp>

#include <iostream>

using namespace Std;

using namespace CV;

int main ()

{

Videocapturecap;

Cap.open ("rtsp://0.0.0.1/stream1");//hehe, the key to this sentence

matcamera_cimg;

matcamera_gimg;

Cap.set (cv_cap_prop_frame_height,768);

Cap.set (cv_cap_prop_frame_width,1024);

if (!cap.isopened ())

return 1024;

while (1)

{

Cap>> camera_cimg;

if (Camera_cimg.empty ())

Break

Cvtcolor (camera_cimg,camera_gimg, Cv_rgb2gray);

Imshow ("Input", camera_cimg);

if (Cvwaitkey (ten) = = ' Q ')

Break

}

System ("pause");

return 0;

}


=========================

1, compile Opencv-dwith gstreamer=on with GSTREAMER; 2,cvcapturefromfile ("Rtspsrc location=\" rtsp://192.168.0.220:554/user=admin&password=admin&channel=1 &stream=0.sdp?real_stream--rtp-caching=10\ "Latency=10! Rtph264depay! H264parse! Omxh264dec! Videoconvert! Appsink ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.