I get asked for this quite a lot these days and for a spell I thought I'd deleted it but I found it again so before I lose it again here it is:
A blog discussing my successes, failures and in-betweeners whilst working on computer vision related projects.
Showing posts with label RTSP. Show all posts
Showing posts with label RTSP. Show all posts
Monday, 26 November 2012
Friday, 6 July 2012
Fixes in OpenCV and RTSP
We've finally got it going!
I'll get onto what was wrong in a second but first I want to share this line with you:
As you can see it is the same as my camera connection url in the previous post except I've added ?tcp to the end. I've found that this forces the rtsp connection to run using the tcp protocol instead of the udp protocol which is useful if you can't afford to have any packet loss. This gives us a decent picture but still performed very poorly, freezing often and dropping the frame rate down to something terrible.
I'll get onto what was wrong in a second but first I want to share this line with you:
CvCapture *camera = cvCreateFileCapture("rtsp://admin:admin@192.168.1.128/ch1-s1?tcp");
As you can see it is the same as my camera connection url in the previous post except I've added ?tcp to the end. I've found that this forces the rtsp connection to run using the tcp protocol instead of the udp protocol which is useful if you can't afford to have any packet loss. This gives us a decent picture but still performed very poorly, freezing often and dropping the frame rate down to something terrible.
Monday, 18 June 2012
Issues with OpenCV and RTSP
For months now I've been fighting with OpenCV to try and get a decent image coming through my internet camera and it's really beginning to drive me mad. I've got a reasonable little program to test the connection which looks like this:
/*
* File: main.cpp
* Author: Ryan
*
* Created on October 27, 2011, 2:23 PM
*/
#include <cstdlib>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/legacy/legacy.hpp"
#include "opencv2/video/tracking.hpp"
#include <stdio.h>
using namespace std;
using namespace cv;
int main() {
// CvCapture *camera = cvCreateFileCapture("/home/ryan/NetBeansProjects/OpenRTSP/video-H264-1");
// CvCapture *camera = cvCreateFileCapture("stream_fifo");
// CvCapture *camera = cvCreateFileCapture("Wildlife.wmv");
CvCapture *camera = cvCreateFileCapture("rtsp://admin:admin@192.168.1.128/ch1-s1"); //purple cam /?tcp
// CvCapture *camera=cvCreateFileCapture("http://192.168.1.5/image.jpg"); //black cam
// CvCapture *camera = cvCreateCameraCapture(0); //built in cam
// cvWaitKey(10000);
if (camera == NULL) {
printf("camera is null, aborting...");
return -1;
}
printf("camera is not null\n");
fflush(stdout);
cvNamedWindow("img");
int i = 0;
while (cvWaitKey(100) != 27) {
// CvCapture *camera=cvCreateFileCapture("http://192.168.1.5/image.jpg");
IplImage *img = cvQueryFrame(camera);
if (img == NULL) break;
cvShowImage("img", img);
// cvReleaseCapture(&camera);
// printf("Image: %i\n", ++i);
}
cvReleaseCapture(&camera);
return 0;
}
Subscribe to:
Posts (Atom)