econsystems / opencv_v4l2

This project contains sample OpenCV application code as well as V4L2 helper library to access camera devices in OpenCV. This code helps to achieve high framerates from cameras in OpenCV. This project gives better results than the VideoCapture class in OpenCV. This source code is only compatible in Linux.
BSD 3-Clause "New" or "Revised" License
39 stars 22 forks source link

e-CAM21_CUTX2 unable to capture frames with helper_get_cam_frame() #5

Closed clawrence121 closed 5 years ago

clawrence121 commented 5 years ago

Hey, Using your e-CAM21_CUTX2 sensor on the nvidia Jetson tx2. The camera is interfacing properly and I can access the stream using eCAM_argus_camera, I have built the opencv_v4l2 repo and have the demo programs working correctly with a USB webcam, but am unable to get them, working with the e-CAM21_CUTX2. I wrote a really basic program that uses the v4l2_helper.h header and v4l2_header.c binary, the camera sets up properly with the correct pixel format and width/height, but when attempt to call helper_get_cam_frame() I receive the output "select timeout" before the program times out after 10 attempts.

This is my code: `#include <opencv2/opencv.hpp>

include

include <sys/time.h>

include

include "v4l2_helper.h"

using namespace std; using namespace cv;

int main() { unsigned int width, height; static const char videodev = "/dev/video0"; // unsigned int start, end, fps = 0; unsigned char ptr_cam_frame; int bytes_used;

Mat srggb12_frame, preview;
cuda::GpuMat gpu_frame;

width = 1920;
height = 1080;

if (helper_init_cam(videodev, width, height, V4L2_PIX_FMT_SRGGB12, IO_METHOD_USERPTR) < 0) {
    return EXIT_FAILURE;
}

namedWindow("OpenCV V4L2 Test", CV_WINDOW_OPENGL);
cout << "Press ESC to exit the window(s)" << endl;

srggb12_frame = Mat(height, width, CV_8UC2);
// start = GetTickCount();

while(1) {
    if (helper_get_cam_frame(&ptr_cam_frame, &bytes_used) < 0) {
        break;
    }

    srggb12_frame.data = ptr_cam_frame;
    if(srggb12_frame.empty()) {
        cout << "Img load failed" << endl;
        break;
    }

    gpu_frame.upload(preview);
    imshow("OpenCV V4L2 Test", gpu_frame);

    if (helper_release_cam_frame() < 0)
    {
        break;
    }

    // assign ESC as escape key
    if(waitKey(1) == 27) break;
}

if (helper_deinit_cam() < 0)
{
    return EXIT_FAILURE;
}

return EXIT_SUCCESS;

}`

With my CMake file: `cmake_minimum_required (VERSION 3.0)

project ("V4L2 testing")

set (SOURCE "opencv-V4L2-testing.cpp") set (V4L2_TEST "opencv-v4l2-test")

find_package (OpenCV REQUIRED) include_directories (${OpenCV_INCLUDE_DIRS})

include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/lib") add_subdirectory (lib)

set (GCC_COMPILE_FLAGS -Wall -Wpedantic -Wextra -O3 -Wshadow -std=c++11 -g) add_compile_options (${GCC_COMPILE_FLAGS})

add_executable (${V4L2_TEST} ${SOURCE}) target_include_directories (${V4L2_TEST} PUBLIC ${V4L2_HELPER_LIB_INCLUDE_DIR}) target_link_libraries (${V4L2_TEST} v4l2_helper) target_link_libraries (${V4L2_TEST} ${OpenCV_LIBS})

install (TARGETS ${V4L2_TEST} DESTINATION bin)`

And here is my output from "v4l2-ctl -d /dev/video0 --all": `Driver Info (not using libv4l2): Driver name : tegra-video Card type : vi-output, eimx290 1-0042 Bus info : platform:15700000.vi:0 Driver version: 4.4.38 Capabilities : 0x84200001 Video Capture Streaming Extended Pix Format Device Capabilities Device Caps : 0x04200001 Video Capture Streaming Extended Pix Format Priority: 2 Video input : 0 (Camera 0: ok) Format Video Capture: Width/Height : 1920/1080 Pixel Format : 'RG12' Field : None Bytes per Line : 3840 Size Image : 4147200 Colorspace : sRGB Transfer Function : Default YCbCr Encoding : Default Quantization : Default Flags :

Camera Controls

                 group_hold (intmenu): min=0 max=1 default=0 value=0
                 hdr_enable (intmenu): min=0 max=1 default=0 value=0
                    fuse_id (str)    : min=0 max=10 step=2 value='' flags=read-only, has-payload
                sensor_mode (int64)  : min=0 max=0 step=0 default=0 value=0 flags=slider
                       gain (int64)  : min=0 max=0 step=0 default=0 value=0 flags=slider
                   exposure (int64)  : min=0 max=0 step=0 default=0 value=6197 flags=slider
                 frame_rate (int64)  : min=0 max=0 step=0 default=0 value=125829120 flags=slider
                bypass_mode (intmenu): min=0 max=1 default=0 value=1
            override_enable (intmenu): min=0 max=1 default=0 value=1
               height_align (int)    : min=1 max=16 step=1 default=1 value=1
                 size_align (intmenu): min=0 max=2 default=0 value=0
           write_isp_format (int)    : min=1 max=1 step=1 default=1 value=1
   sensor_signal_properties (u32)    : min=0 max=0 step=0 default=0 flags=read-only, has-payload
    sensor_image_properties (u32)    : min=0 max=0 step=0 default=0 flags=read-only, has-payload
  sensor_control_properties (u32)    : min=0 max=0 step=0 default=0 flags=read-only, has-payload
          sensor_dv_timings (u32)    : min=0 max=0 step=0 default=0 flags=read-only, has-payload
               sensor_modes (int)    : min=0 max=30 step=1 default=30 value=5 flags=read-only`

With my program output: pixfmt = R G 1 2 width = 1920 height = 1080 Press ESC to exit the window(s) select timeout select timeout ^C

Any help would be great, cheers!

dilipkumar25 commented 5 years ago

Hi, Thank you for the detailed info along with sample code and logs. It helps us understand the problem.

The e-CAM21_CUTX2 was designed to be used along with Nvidia internal ISP. Hence the best way to use this particular camera is to use argus APIs. The documentation for argus APIs is provided by Nvidia. A sample source code for using argus APIs along with opencv is also provided in the tegra_multimedia_api package in jetpack.

You can use this library too. However, you'll be missing out on many of the features of the camera if v4l2 is used directly. Hence, we would recommend Argus over this library for this camera.

On Sat, 4 May, 2019, 10:41 AM clawrence121, notifications@github.com wrote:

Hey, Using your e-CAM21_CUTX2 sensor on the nvidia Jetson tx2. The camera is interfacing properly and I can access the stream using eCAM_argus_camera, I have built the opencv_v4l2 repo and have the demo programs working correctly with a USB webcam, but am unable to get them, working with the e-CAM21_CUTX2. I wrote a really basic program that uses the v4l2_helper.h header and v4l2_header.c binary, the camera sets up properly with the correct pixel format and width/height, but when attempt to call helper_get_cam_frame() I receive the output "select timeout" before the program times out after 10 attempts.

This is my code: `

include <opencv2/opencv.hpp>

include

include <sys/time.h>

include

include "v4l2_helper.h"

using namespace std; using namespace cv;

int main() { unsigned int width, height; static const char videodev = "/dev/video0"; // unsigned int start, end, fps = 0; unsigned char ptr_cam_frame; int bytes_used;

Mat srggb12_frame, preview; cuda::GpuMat gpu_frame;

width = 1920; height = 1080;

if (helper_init_cam(videodev, width, height, V4L2_PIX_FMT_SRGGB12, IO_METHOD_USERPTR) < 0) { return EXIT_FAILURE; }

namedWindow("OpenCV V4L2 Test", CV_WINDOW_OPENGL); cout << "Press ESC to exit the window(s)" << endl;

srggb12_frame = Mat(height, width, CV_8UC2); // start = GetTickCount();

while(1) { if (helper_get_cam_frame(&ptr_cam_frame, &bytes_used) < 0) { break; }

srggb12_frame.data = ptr_cam_frame; if(srggb12_frame.empty()) { cout << "Img load failed" << endl; break; }

gpu_frame.upload(preview);
imshow("OpenCV V4L2 Test", gpu_frame);

if (helper_release_cam_frame() < 0) { break; }

// assign ESC as escape key
if(waitKey(1) == 27) break;

}

if (helper_deinit_cam() < 0) { return EXIT_FAILURE; }

return EXIT_SUCCESS;

}`

With my CMake file: `cmake_minimum_required (VERSION 3.0)

project ("V4L2 testing")

set (SOURCE "opencv-V4L2-testing.cpp") set (V4L2_TEST "opencv-v4l2-test")

find_package (OpenCV REQUIRED) include_directories (${OpenCV_INCLUDE_DIRS})

include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/lib") add_subdirectory (lib)

set (GCC_COMPILE_FLAGS -Wall -Wpedantic -Wextra -O3 -Wshadow -std=c++11 -g) add_compile_options (${GCC_COMPILE_FLAGS})

add_executable (${V4L2_TEST} ${SOURCE}) target_include_directories (${V4L2_TEST} PUBLIC ${V4L2_HELPER_LIB_INCLUDE_DIR}) target_link_libraries (${V4L2_TEST} v4l2_helper) target_link_libraries (${V4L2_TEST} ${OpenCV_LIBS})

install (TARGETS ${V4L2_TEST} DESTINATION bin)`

And here is my output from "v4l2-ctl -d /dev/video0 --all": `Driver Info (not using libv4l2): Driver name : tegra-video Card type : vi-output, eimx290 1-0042 Bus info : platform:15700000.vi:0 Driver version: 4.4.38 Capabilities : 0x84200001 Video Capture Streaming Extended Pix Format Device Capabilities Device Caps : 0x04200001 Video Capture Streaming Extended Pix Format Priority: 2 Video input : 0 (Camera 0: ok) Format Video Capture: Width/Height : 1920/1080 Pixel Format : 'RG12' Field : None Bytes per Line : 3840 Size Image : 4147200 Colorspace : sRGB Transfer Function : Default YCbCr Encoding : Default Quantization : Default Flags :

Camera Controls

             group_hold (intmenu): min=0 max=1 default=0 value=0
             hdr_enable (intmenu): min=0 max=1 default=0 value=0
                fuse_id (str)    : min=0 max=10 step=2 value='' flags=read-only, has-payload
            sensor_mode (int64)  : min=0 max=0 step=0 default=0 value=0 flags=slider
                   gain (int64)  : min=0 max=0 step=0 default=0 value=0 flags=slider
               exposure (int64)  : min=0 max=0 step=0 default=0 value=6197 flags=slider
             frame_rate (int64)  : min=0 max=0 step=0 default=0 value=125829120 flags=slider
            bypass_mode (intmenu): min=0 max=1 default=0 value=1
        override_enable (intmenu): min=0 max=1 default=0 value=1
           height_align (int)    : min=1 max=16 step=1 default=1 value=1
             size_align (intmenu): min=0 max=2 default=0 value=0
       write_isp_format (int)    : min=1 max=1 step=1 default=1 value=1

sensor_signal_properties (u32) : min=0 max=0 step=0 default=0 flags=read-only, has-payload sensor_image_properties (u32) : min=0 max=0 step=0 default=0 flags=read-only, has-payload sensor_control_properties (u32) : min=0 max=0 step=0 default=0 flags=read-only, has-payload sensor_dv_timings (u32) : min=0 max=0 step=0 default=0 flags=read-only, has-payload sensor_modes (int) : min=0 max=30 step=1 default=30 value=5 flags=read-only`

With my program output: pixfmt = R G 1 2 width = 1920 height = 1080 Press ESC to exit the window(s) select timeout select timeout ^C

Any help would be great, cheers!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/econsystems/opencv_v4l2/issues/5, or mute the thread https://github.com/notifications/unsubscribe-auth/ADD5ZTNSQYUV3Z3UMU553G3PTULIBANCNFSM4HKYEA4Q .

clawrence121 commented 5 years ago

Awesome, I appreciate the prompt reply, thanks!