3

I have a raspberry pi b+ uploading a video stream with the mjpeg-streamer.

On the Raspberry Pi

/usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so -y -r 340x240 -f 10 -d /dev/video0" -o "/usr/local/lib/output_http.so -w /usr/local/www"

This creates a video stream accessible by

http://10.1.111.150:8080/?action=stream

making a jpeg image -> Live stream on the firefox browser

Now, what I would like to do is open this stream with OpenCV 3.0.0 in Visual Studio 2013.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    int q;
    VideoCapture cap; 

//cap.open(0) for internal camera
//
cap.open("http://10.1.111.150:8080/?action=stream");


if (!cap.isOpened())  // if not success, exit program
{
    cout << "Cannot open the video cam" << endl << "Press q to continue:";
    cin >> q;
    return -1;
}

double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

cout << "Frame size : " << dWidth << " x " << dHeight << endl;

namedWindow("MyVideo", CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
namedWindow("MyNegativeVideo", CV_WINDOW_AUTOSIZE);

while (1)
{
    Mat frame;
    Mat contours;

    bool bSuccess = cap.read(frame); // read a new frame from video

    if (!bSuccess) //if not success, break loop
    {
        cout << "Cannot read a frame from video stream" << endl;
        break;
    }

    flip(frame, frame, 1);
    imshow("MyVideo", frame); //show the frame in "MyVideo" window

    Canny(frame, contours, 500, 1000, 5, true);
    imshow("MyNegativeVideo", contours);

    if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
    {
        cout << "esc key is pressed by user" << endl;
        break;
    }
}
return 0;}

This is an example code that works to open the internal webcam on my laptop when I usecap.open(0) But trying to open the ip camera from its addresscap.open("http://10.1.111.150:8080/?action=stream"); is not working.

UPDATE I've made some changes on the RPi by running

/usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so -y -r 340x240 -f 10 -d /dev/video0" -o "/usr/local/lib/output_rtsp.so -p /usr/local/www"

the difference being the output_rtsp.so -p

By the looks the webcam (active light is on) and the program running in the raspberry pi's terminal, I can assume the stream is working. I can't confirm this through a browser though.

Running

cap.open("rtsp://10.1.111.150:8080/?action=stream");

in the openCV code does not open the stream.

Can anyone tell me where I'm going wrong?

AdamoVenti
  • 31
  • 4

0 Answers0