Ask Your Question

hongyuanlu's profile - activity

2017-06-15 09:20:14 -0600 asked a question OpenCV how the frame is grabbed out from WebCam?

I am wondering in a single frame grab

cap >> frame

If I am using Logitech C920 which has its own hardware encoder, and I am grabbing 720p image, Am I getting 1280 * 720 * 3=921600 * 3=2700000 bytes from the USB port directly?

Or I am getting a compressed image out first and decode it into 2700000bytes?

2017-06-15 07:30:10 -0600 asked a question OpenCV on Mac and Raspberry Pi performance comparison

Hi, guys.

What I am working on is to use OpenCV + Raspberry Pi 3 Model B + Raspberry Cam V2 + Gstreamer to capture video frames, process them and save them into a video file.

My goal is to capture the frames at frame rate of at least 30fps for 1280x720 resolutions.

My code is also here:

cv::VideoCapture cap("v4l2src device=/dev/video0 ! video/x-raw, framerate=30/1, width=1280, height=720, format=RGB ! videoconvert ! appsink");
if (!cap.isOpened()) {
    printf("=ERR= can't create video capture\n");
    return -1;
}

cv::VideoWriter writer;
writer.open("appsrc ! videoconvert ! omxh264enc ! h264parse ! mpegtsmux ! filesink location=test.mp4", 0, (double)30, cv::Size(640, 480), true);
if (!writer.isOpened()) {
    printf("=ERR= can't create video writer\n");
    return -1;
}

On raspberry pi, write is not writing fast enough: a single frame write uses 50ms~60ms, which is less than what I am desiring.

However, a strange thing I find is, CAP >> FRAME costs from 20ms to 60ms on my Mac, however, it costs 10ms on RPi. However, VIDEOWRITER << FRAME costs 60ms on RPi, but it costs 10ms on my Mac.

This is my code to measure the time:

auto start = std::chrono::high_resolution_clock::now();
cap >> frame;
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end-start;
std::cout << diff.count() << " s\n";

I am looking for any solution to reduce the CAP >> FRAME time on Mac and reduce the VIDEOWRITER << CAP time on RPi.

Thank you in advance!

2017-06-14 16:40:38 -0600 received badge  Enthusiast
2017-06-05 05:16:41 -0600 commented question GStreamer + OpenCV using Raspberry Pi + Mac OSX

@berak One more question, is it possible to get the appsink in use? I want to check the buffer of it..

2017-06-05 05:12:16 -0600 commented question GStreamer + OpenCV using Raspberry Pi + Mac OSX

I added it now and it is still not working..

2017-06-04 14:32:48 -0600 asked a question GStreamer + OpenCV using Raspberry Pi + Mac OSX

The current problem I am working on is to send stream from Raspberry Pi to Mac OSX using Gstreamer and extract frames from Gstreamer using OpenCV. Here is my code:

Mac:

cv::VideoCapture cap("tcpclientsrc host=129.31.224.100 port=8888 ! gdpdepay ! rtph264depay ! avdec_h264 ! "
                                 "videoconvert ! appsink");
    if (!cap.isOpened()) {
        printf("=ERR= can't create video capture\n");
        return -1;
    }

RPi:

gst-launch-1.0 wrappercamerabinsrc ! video/x-raw, 
framerate=30/1, width=1280, height=720, format=RGB ! 
videoconvert ! vtenc_h264 ! h264parse !  
rtph264pay config-interval=1 pt=96 ! gdppay ! 
tcpserversink host=129.31.224.100 port=8888

The error message is:

VIDEOIO(cvCreateFileCapture_AVFoundation (filename)): raised unknown C++ exception!

=ERR= can't create video capture

The thing I want to achieve is to read frames from gstreamer by using OpenCV.

The above command works in command line, but not working in C++ code.

Thank you in advance!