Labels

Showing posts with label in-betweeners. Show all posts
Showing posts with label in-betweeners. Show all posts

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