0

I've setup my Raspberry pi 3 B with uv4l and have access to the video stream on http://(raspberry-IP):8080/stream address.

Now, I have Qt5(C++) and OpenCV installed on my main computer.

How can I access the stream frames within a Qt5 project? Or where can I find information on how to do it?

I've realized the stream is some file format named mjpeg with which I have no experience. Should I use the \stream address to try to access the frames or some other function in the RESTful API of uv4l components? Does OpenCV has any method to access frames from an http stream?

0

I found the answer here. Turns out the best scenario was available. OpenCV has a method for acquiring mjpeg streams. Perfect!

Here is the same code, adapted to my setup:

#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <iostream>

int main(int, char**) {
    cv::VideoCapture vcap;
    cv::Mat image;

    const std::string videoStreamAddress = "http://user:password@192.168.1.93:8080/stream/video.mjpeg";

    //open the video stream and make sure it's opened
    if(!vcap.open(videoStreamAddress)) { // <<<<<< Magic here
        std::cout << "Error opening video stream." << std::endl;
        return -1;
    }

    while(true) {
        if(!vcap.read(image)) {
            std::cout << "No frame" << std::endl;
            cv::waitKey();
        }

        // Process image here, for example.

        cv::imshow("Output Window", image);

        // Exit if a key is pressed
        if(cvWaitKey(1) >= 0) break; // use cvWaitKey() instead of cv::waitKey(1)
    }
}

Maybe it will help someone.

Now that you have a cycle acquiring frames as cv::Matyou're good to go.

Notes:

  • I installed Qt5 and OpenCV with instructions from here.
  • I made sure WITH_FFMPEG=YES when compiling OpenCV with Cmake, which was YES by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.