Ask Your Question
0

RTSP stream from IP camera not moving

asked 2018-02-10 00:02:08 -0500

o_rexy gravatar image

Hi, I am trying to stream an IP camera using RTSP. My code works fine when testing using a big buck bunny stream (either of the two commented out) however when I use the address of the camera it captures only a single frame and only updates that frame on a key press and then eventually crashes. The camera streams fine using its default explorer.

Any help is greatly appreciated, thanks.

#include "opencv2\opencv.hpp"
#include <stdint.h>
#include <math.h>  

#define PI 3.14159265
#define key_up 72
#define key_down 80
using namespace cv;
using namespace std;

int main(int argv, char** argc)
{
Mat frame;
//VideoCapture vid("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
VideoCapture vid("rtsp://192.168.1.150:1024/0");
//VideoCapture vid("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov");

namedWindow("RTSP stream", CV_WINDOW_FREERATIO);

int fps = (int)vid.get(CV_CAP_PROP_FPS);
int height = (int)vid.get(CV_CAP_PROP_FRAME_HEIGHT);
int width = (int)vid.get(CV_CAP_PROP_FRAME_WIDTH);

FileStorage fs2("Calibration.yml", FileStorage::READ);
double CutAngle = (double)fs2["TreeAngle"];
int heightDev = (int)fs2["HorLine"];
int widthDev = (int)fs2["VertLine"];

if (!vid.isOpened())
{
    return -1;
}
while (vid.read(frame))
{

    line(frame, Point(0, heightDev), Point(width, heightDev), Scalar(0, 0, 255), 1, 8, 0);
    line(frame, Point(widthDev, 0), Point(widthDev, height), Scalar(0, 0, 255), 1, 8, 0);
    line(frame, Point(widthDev, heightDev), Point((widthDev) + abs((height-heightDev) / tan(CutAngle * (PI / 180.0))), height), Scalar(0, 0, 255), 0.1, CV_AA, 0); 
    line(frame, Point(widthDev, heightDev), Point((widthDev) + abs((heightDev) / tan((180-CutAngle) * (PI / 180.0))), 0), Scalar(0, 0, 255), 0.1, CV_AA, 0); 


    imshow("RTSP stream", frame);

    char key = waitKey(1000 / fps) & 0xFF;

    if (key == 'r')
        CutAngle += 1;
    else if (key == 't')
        CutAngle -= 1;
    else if (key == int(27))
        break;
    else if (key == 'a')
        widthDev -= 1;
    else if (key == 'd')
        widthDev += 1;
    else if (key == 'w')
        heightDev -= 1;
    else if (key == 's')
        heightDev += 1;
    else if (key == 'z'){
        FileStorage fs("Calibration.yml", FileStorage::WRITE);
        fs << "TreeAngle" << CutAngle;
        fs << "VertLine" << widthDev;
        fs << "HorLine" << heightDev;}
    else if (key == 'p'){
        CutAngle = (40/2)+1;
        widthDev = (width/5)+1;}

 // waitKey();
}
return 1;
vid.release();

//Mat test = imread("dawson.jpg", CV_LOAD_IMAGE_UNCHANGED);
//imshow("Test", test);
//waitKey();
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-02-15 04:36:07 -0500

o_rexy gravatar image

figured it out.

int fps = (int)vid.get(CV_CAP_PROP_FPS);

wasnt pulling the FPS from the stream, just changed it with a fixed rate.

edit flag offensive delete link more

Comments

Hi there,I have two questions? 1) I am trying to use RTSP to open stream from CCTV IP Camera, like --> camera = cv2.VideoCapture("rtsp://admin:123456@192.168.1.13:554/Streaming/Channels/102/"), using python, but, I couldn't read the video stream, I am using Ubuntu 16.04 and OpenCV, but i see Camera's IP is different and my server's IP is different, is that a problem?, 2) How much FPS you changed as fixed rate?

Guru VM gravatar imageGuru VM ( 2018-05-10 01:51:15 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-02-10 00:02:08 -0500

Seen: 1,550 times

Last updated: Feb 10 '18