Ask Your Question

k_kaz's profile - activity

2019-05-12 13:25:54 -0500 received badge  Notable Question (source)
2018-07-28 06:19:01 -0500 received badge  Popular Question (source)
2017-07-26 02:55:32 -0500 received badge  Enthusiast
2017-03-29 07:29:36 -0500 commented question network stream udp

@LBerger it was answered in the github opencv issues. Opencv forces a tcp connection. So i changed the server to an http stream. Thanks for the help

2017-03-29 01:36:04 -0500 commented question network stream udp

@LBerger i ve tried this solution, but it has the same behavior with the "udp://192.168.55.151:8554/" link. Is it possible that the problem is from the server?

2017-03-27 09:41:04 -0500 commented question network stream udp

@LBerger but i get the same exact error from the ffmpeg when i try to connect with tcp. If i change to udp in the ffmpeg command, the decoding is successful. So i guess that i need to tell opencv to use ffmpeg with udp instead of tcp, right?

2017-03-27 04:49:05 -0500 asked a question network stream udp

I want to process and display a network rtsp stream that is created from a raspberry camera. I have this code:

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

int main(int argc, char** argv) {

    cv::VideoCapture * stream = new cv::VideoCapture("rtsp://192.168.55.151:8554/");
    if (!stream->isOpened()) return -1;

    cv::namedWindow("rtsp_stream", CV_WINDOW_AUTOSIZE);
    cv::Mat frame;

    while (true) {

        if (!stream->read(frame)) return -1;

        cv::imshow("rtsp_stream", frame);
        cv::waitKey(15);
    }

    return 1;
}

When the stream is not live, the execution of this results in:

[tcp @ 0xa12480] Connection to tcp://192.168.55.151:8554?timeout=0 failed: Connection refused

Which means that the stream tries to connect with tcp. When the stream is live, the execution results in:

 [rtsp @ 0xb07960] method SETUP failed: 461 Client error

From internet research i found that the problem may be that the stream uses udp. If i change the URL to:

"udp://192.168.55.151:8554/"

Then the execution freezes in the cv::VideoCapture("udp://192.168.55.151:8554/"); How can i solve my problem?

Edit 1: VLC is able to open the stream.

Edit 2: As i am given to understand, ffmpeg is used to decode the stream. When i run:

ffmpeg -rtsp_transport udp -i rtsp://192.168.55.151:8554/ -t 5 test.mpg

the stream decoding and saving is successful. So how can i specify the lower level protocol to be udp?

Edit 3: If i use the ffmpeg command with tcp instead of udp, i get the same error with the c++ code, 461 client error

2017-03-20 07:42:21 -0500 marked best answer Saving and retrieving Mat data

I want to save Mat data to a float array, process them, and then save them back to Mat. I don't want to use .at function, cause processing code is already written and uses some temp arrays.

I have this piece of code:

cv::Mat test(cv::Mat original) {

    float * image_data = new float[original.rows * original.cols];

    //Save to array
    init_data_image_32(original, image_data);

    //process


    //Restore from array
    cv::Mat res(original.rows, original.cols, CV_32F, image_data, original.cols);

    cv::namedWindow("b", CV_WINDOW_NORMAL);
    cv::imshow("b", res);
    return res;
}

bool doublesEqual(double a, double b) {
    double margin_of_error = 0.0001;
    return abs(a - b) < margin_of_error;
}

void init_data_image_32(cv::Mat image, float * image_data) {
    for (int i = 0; i < image.rows; i++)
        for (int j = 0; j < image.cols; j++) {
            image_data[i*image.cols + j] = image.at<float>(i, j);
            if (!doublesEqual(image_data[i*image.cols + j], image.at<float>(i, j))) std::cout << image_data[i*image.cols + j] << " " << image.at<float>(i, j) << std::endl;
        }
}

The imshow of the resulting image in the imshow(b) has nothing to do with original, its this one: image description

Furthermore, the init_data_image_32 has some lines of output from the if clause:

nan nan
nan nan
nan nan
..

What am i doing wrong?