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();
}