Giter Site home page Giter Site logo

cv_camera's Introduction

ROS OpenCV camera driver

It is very easy to capture video device if we use cv::VideoCapture of OpenCV.

If you are searching ROS2 driver, check here

cv_camera_node

This node uses camera_info_manager for dealing with camera_info. If no calibration data is set, it has dummy values except for width and height.

Publish

  • ~image_raw (sensor_msgs/Image)
  • ~camera_info (sensor_msgs/CameraInfo)

Service

  • ~set_camera_info (sensor_msgs/SetCameraInfo)

Parameters

  • ~rate (double, default: 30.0) – publish rate [Hz].
  • ~device_id (int, default: 0) – capture device id.
  • ~device_path (string, default: "") – path to camera device file, e. g. /dev/video0.
  • ~frame_id (string, default: "camera") – frame_id of message header.
  • ~image_width (int) – try to set capture image width.
  • ~image_height (int) – try to set capture image height.
  • ~camera_info_url (string) – url of camera info yaml.
  • ~file (string, default: "") – if not "" then use movie file instead of device.
  • ~capture_delay (double, default: 0) – estimated duration of capturing and receiving the image.
  • ~rescale_camera_info (bool, default: false) – rescale camera calibration info automatically.
  • ~camera_name (bool, default: same as frame_id) – camera name for camera_info_manager.

Supports CV_CAP_PROP_*, by below params.

  • ~cv_cap_prop_pos_msec (double)
  • ~cv_cap_prop_pos_avi_ratio (double)
  • ~cv_cap_prop_frame_width (double)
  • ~cv_cap_prop_frame_height (double)
  • ~cv_cap_prop_fps (double)
  • ~cv_cap_prop_fourcc (double)
  • ~cv_cap_prop_frame_count (double)
  • ~cv_cap_prop_format (double)
  • ~cv_cap_prop_mode (double)
  • ~cv_cap_prop_brightness (double)
  • ~cv_cap_prop_contrast (double)
  • ~cv_cap_prop_saturation (double)
  • ~cv_cap_prop_hue (double)
  • ~cv_cap_prop_gain (double)
  • ~cv_cap_prop_exposure (double)
  • ~cv_cap_prop_convert_rgb (double)
  • ~cv_cap_prop_rectification (double)
  • ~cv_cap_prop_iso_speed (double)

And supports any props. Thanks to Hernan Badino!

  • ~property_$(i)_code (int) – set this code property using ~property_$(i)_value, $(i) must start from 0.
  • ~property_$(i)_value (double) – the value to be set to ~property_$(i)_code

If you want to set the property which code is 404 as 1,

rosrun cv_camera cv_camera_node _property_0_code:=404 _property_0_value:=1

If you want to set more, use ~property_1_code and ~property_1_value.

Nodelet

This node works as nodelet (cv_camera/CvCameraNodelet).

Contributors

PR is welcome. I'll review your code to keep consistency, be patient.

  • Oleg Kalachev
  • Mikael Arguedas
  • Maurice Meedendorp
  • Max Schettler
  • Lukas Bulwahn

cv_camera's People

Contributors

bulwahn avatar mgmeedendorp avatar mikaelarguedas avatar okalachev avatar otl avatar sfalexrog avatar sgermanserrano avatar timple avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cv_camera's Issues

raspicam_node - comparable?

Just a question: is this a reasonable (or better) alternative to raspicam_node from Ubiquity Robotics? I've worked with raspicam_node and the associated armco_detect. It took quite a bit of effort to get it to work.

I am wondering wether cv_camera is a better choice. OpenCV seems better documented and supported. And I think it might work better with the opencv aruco tag APIs. I

Failing to set image width

I am using wide cameras (ELP-USBFHD09DC-FD180) that outputs Full HD and HD resolution. However cv_camera fails to set to higher resolution.

It always gives warning "fail to set image_width" and publishes only at 640*480 image resolution.

<launch>

 <node pkg="cv_camera" name="camera_rear_left"  type="cv_camera_node" output="screen">
    <param name="frame_id" value="camera_rear_left" />
    <param name="device_path" value="/dev/camera_rear_left" />
    <param name="image_width" value="1280" />
    <param name="cv_cap_prop_fourcc" value="MJPG"/>
    <param name="image_height" value="720" />
 </node>

</launch>                                                                                                   

Any help is appreciated!

Build issue Raspberry Pi4

Hi everyone!

Previously I have installed ROS and I tried to include cv_camera with the following commands:

rosinstall_generator desktop teleop_twist_keyboard cv_camera --rosdistro melodic --deps --wet-only --tar > melodic-desktop-wet.rosinstall
wstool init -j8 src melodic-desktop-wet.rosinstall
rosdep install --from-paths src --ignore-src --rosdistro melodic -y
cd && cd ~/ros_catkin_ws
sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic -j4
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc

Building with cmake:
image

Tried to use rosdeb:
image

Manually added cv_camera source:

sudo cp -r ~/catkin_ws/src/cv_camera/ /opt/ros/melodic/share/

And still doesn't work and I don't know what to do.
image

Many thanks

UPD1:

It looks like there is a similar problem here.

Automatic rescaling camera matrix on different resolution

Currently, if the resolution of camera info doesn't match the actual ~image_width and ~image_height, cv_camera just ignores it (without any warnings). This can be confusing.

I propose automatic camera info rescaling (if appropriate parameter is enabled). It can be done with some code like this:

cameraMat.copyTo(scaledCameraMat);
widthCoeff = imageWidth / cameraInfoWidth;
heightCoeff = imageHeight / cameraInfoHeight;
scaledCameraMat.at<float>(0, 0) *= widthCoeff;
scaledCameraMat.at<float>(0, 2) *= widthCoeff;
scaledCameraMat.at<float>(1, 1) *= heightCoeff;
scaledCameraMat.at<float>(1, 2) *= heightCoeff;

newCamMat = cv::getOptimalNewCameraMatrix(scaledCameraMat, distCoeffs, currFrameSize, 1);

If the parameter is disabled, a warning can be thrown in such a situation.

Feature request: String input for device ID and no default device ID

Change device id from int32 to string. This would allow the user to access IP cameras.

Also, it seems that the default device ID is 0. I tried launching with a string for the device ID and instead of opening the IP camera that I was trying to connect to, it opened device 0. This behavoir is not intuitive. I would expect and error if it failed to open the device I was to connect to.

Changing brightness and other settings

This was asked before a while back. Have you or anyone created a way to try different parameters (e.g. brightness) and watch the effects on the fly? The ROS way would be a dynamic reconfigure server which I don;t see here. Suggestions?

File infinite loop

It might be nice to default to keep playing video in an infinite loop openFile is used to open a file. I tried to use a looped .gif image to keep playing video for testing purposes but it didn't work...

VIDIOC_DQBUF: No such device error

When I unplug camera and plug it back the "VIDIOC_DQBUF: No such device" error occurs in terminal.

Maybe it's an issue within opencv library, but still is there a way, that I can catch this exception within the scope of this package?

Image is wrongly formed error.

When trying to use anything other than a RGB image, I am getting Image is wrongly formed: step<width * byte_depth * num_channels or 1920!=192013. Does anyone have any advice on how to deal with this error? I thought num_channels should be automatically set based on output format?

Is this not compatible with GRAY8/MONO8 messages? I am launching with gstreamer using the following:

"nvarguscamerasrc sensor-id=2 ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw(memory:NVMM), format=(string)GRAY8 ! nvvidconv ! video/x-raw(ANY), ! appsink"

I know my launch code is good because I can see the message being published, but when I use CV_Camera to pass to aruco it fails.

Build fails Opencv4

I am trying to build this on a jetson nano which comes installed with opencv4. Trying to build this it looks like its trying to find /usr/include/opencv. Since my CV include path is /usr/include/opencv4 I tried making a symbolic link. This allowed the code to find headers but generated a number of build errors so i assume this was built for CV3 instead. Is there suppose to open CV 4? If so what do I need to do to correct my issue?

‘CAP_V4L’ is not a member of ‘cv’

Please I need help I am new to ros, I'm using ros indigo. I downloaded the package and when catkin_making it. it gives this errors message : ‘CAP_V4L’ is not a member of ‘cv’
I did not change anything in CMakefile!

cv_camera from file

The documentation seems to indicate that if the ~file argument is set to anything other than "", it will attempt to read from that file.
However, cv_camera is unable to read from a file because it attempts to use a camera even when an argument has been given specifying a file to read from.

The file to read from was set using the following command.
Using absolute or relative paths has the same result.
rosparam set cv_camera/file "IMG_0678.MOV"

This confirms that the parameter was successfully set

rosparam get cv_camera/file
IMG_0678.MOV

Error output:

rosrun cv_camera cv_camera_node /cv_camera/:=/my_camera
VIDEOIO ERROR: V4L: can't open camera by index 0
[ERROR] [1553094833.392343089]: cv camera open failed: device_id0 cannot be opened

cv_camera still functions normally when viewing a camera.
The issue has been confirmed for both .MOV and .avi files.
The device used is using Ubuntu Mate 18.04 and ROS melodic.

Is there a way to correct this issue so I can stream a recorded video over a ROS topic, or is there another utility someone can recommend for this purpose?
Thank you.

How to set camera to MJPG?

I am using an ELP-USB100W04H-L36 usb camera and the launch file below however the MJPG format is not getting set correctly and I'm getting the following error
VIDEOIO ERROR: V4L2: setting property #8 is not supported
I can get it to stream in MJPG format using the ros package "usb_cam" but that package isn't nodelet capable while this one is.

<launch>

  <node pkg="cv_camera" type="cv_camera_node" name="cv_camera_node">
    <param name="device_id" value="2"/>
    <param name="image_width" value="1280"/>
    <param name="image_height" value="720"/>
    <param name="cv_cap_prop_fourcc" value="MJPG"/>
    <!--77 74 80 71-->
  </node>

</launch>

Any help would be greatly appreciated.

‘CAP_V4L’ is not a member of ‘cv’ in cap_.open(device_path, cv::CAP_V4L);

Hi,

I'm trying launch cv_camera with ros but I couldn't compile this package in ros, I launched this command:

catkin_make --only-pkg-with-deps rossumo cv_camera -DARDRONESDK3_PATH=~/out/arsdk-native/staging/usr

...

/home/docker/catkin_ws/src/cv_camera/src/capture.cpp: In member function ‘void cv_camera::Capture::open(const string&)’:
/home/docker/catkin_ws/src/cv_camera/src/capture.cpp:95:26: error: ‘CAP_V4L’ is not a member of ‘cv’
   cap_.open(device_path, cv::CAP_V4L);
                          ^
make[2]: *** [cv_camera/CMakeFiles/cv_camera.dir/src/capture.cpp.o] Error 1
make[1]: *** [cv_camera/CMakeFiles/cv_camera.dir/all] Error 2

What do you think I'm doing wrong?

Thanks!

.launch file property to ask for monochrome image

I am sure it's there somewhere but after reading the code for a while, I thought I would just ask.

Do you know how to launch cv_camera from a .launch file I can ask for monochrome images.

I have a Raspberry Pi 4 with a Raspi Camera Module v2 on Ubuntu.

Thanks!

The current version does not support setting up focus parameters

The current version does not support setting up the focus of the camera. Since I need it, I have implemented this and I would like to issue a PR. Could the owner of the project kindly give me permissions to push my branch and issue a PR ?
With best regards
Piotr Holonowicz

[ERROR] [1533077476.693028660]: cv camera open failed: device_id0 cannot be opened

I'm running a ros pointgrey camera drive as my input node, which publishes to /camera/left/image_raw, and I'm calling
rosrun cv_camera cv_camera_node /cv_camera/image_raw:=/camera/left/image_raw
but I get the following error:
[ERROR] [1533077476.693028660]: cv camera open failed: device_id0 cannot be opened
It seems cv_camera is trying to access the camera directly instead of publishing to its topic? How do I resolve this?

Running warning and suggestions on grabing image

Dear authors:

Thanks in advance for your code!

I wrote a launch as follows:

<launch>
  <arg name="device_id" default="0" />
  <arg name="image_width" default="1280" />
  <arg name="image_height" default="720" />

  <node name="cv_camera" pkg="cv_camera" type="cv_camera_node" output="screen" >
    <param name="device_id" value="$(arg device_id)" />
    <param name="image_width" value="$(arg image_width)" />
    <param name="image_height" value="$(arg image_height)" />
  </node>
  <node name="image_view" pkg="image_view" type="image_view" respawn="false" output="screen">
    <remap from="image" to="/cv_camera/image_raw" />
    <param name="autosize" value="true" />
  </node>
</launch>

The running result is as follows:

SUMMARY
========

PARAMETERS
 * /cv_camera/device_id: 0
 * /cv_camera/image_height: 720
 * /cv_camera/image_width: 1280
 * /image_view/autosize: True
 * /rosdistro: melodic
 * /rosversion: 1.14.10

NODES
  /
    cv_camera (cv_camera/cv_camera_node)
    image_view (image_view/image_view)

auto-starting new master
process[master]: started with pid [11533]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 892cb1c4-7c51-11eb-b551-f0038c0ab1cd
process[rosout-1]: started with pid [11544]
started core service [/rosout]
process[cv_camera-2]: started with pid [11550]
process[image_view-3]: started with pid [11552]
[ INFO] [1614797520.944463821]: Initializing nodelet with 8 worker threads.
[ INFO] [1614797520.967735263]: Using transport "raw"
[ WARN:0] VIDEOIO(V4L2:/dev/video0): select() timeout.

and without image visualization. Any suggestions on the following code.

Best,
Yujie

[ERROR] [1623689901.478565848]: cv camera open failed: device_id0 cannot be opened

Hi!
I have a similar problem to issue #18.
I followed all your answers but unfortunately couldn't solve it.

I am using a Ricoh Theta Z1 camera. (ROS Noetic, Ubuntu 20.04)
I installed v4l2loopback, gstreamer1.0 packages and libuvc-theta + libuvc-theta-sample packages.

Although I can see the feed from the camera if I use gst_viewer without problems, i run into problems when I try to use your package cv_camera with it.

When I run ls /dev | grep video i get back video0.

After I installed your package I tried to set up the camera device do use and run the node:
rosparam set cv_camera/device_id 0
rosrun cv_camera cv_camera_node

I got this error instead
WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (1758) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Internal data stream error.
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (888) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ WARN:0] global ../modules/videoio/src/cap_v4l.cpp (887) open VIDEOIO(V4L2:/dev/video0): can't open camera by index
[ERROR] [1623689901.478565848]: cv camera open failed: device_id0 cannot be opened

The results of running ls -l /dev/video* are crw-rw----+ 1 root video 81, 0 Jun 14 17:19 /dev/video0

I got nothing back when I ran sudo chmod 666 /dev/video* just like user lflanag4.

Can you give me a hand?

Best regards,

Mário

camera calibration result

Hi guys, i am not too sure what are the value to add in for rectification_matrix and the projection_matrix that is required for my USB camera. I got my camera result from kalibr.

cam0:
cam_overlaps: []
camera_model: ds
distortion_coeffs: []
distortion_model: none
intrinsics: [-0.008924692942985086, 0.9138075160533852, 420.0386682531036, 419.0136126237458,
303.3523319667734, 244.90890485641165] #(intrinsics vector: [xi alpha fu fv pu pv])
resolution: [640, 480]
rostopic: /image_converter/output_image


I need to covert it to this format. This is what i put but i am not too sure if i did it correctly.

image_width: 640
image_height: 480
camera_name: usb_cam
camera_matrix:
rows: 3
cols: 3
data: [357.7808547369238, 0, 329.66778704539, 0, 357.41035237313594, 240.04276942034474, 0, 0, 1]
distortion_model: radtan
distortion_coefficients:
rows: 1
cols: 4
data: [0.012252036342139852, 0.009736785998316986, 0.005191213687411114,
0.0009482505467547185]
rectification_matrix:
rows: 3
cols: 3
data: [1, 0, 0, 0, 1, 0, 0, 0, 1]
projection_matrix:
rows: 3
cols: 4
data: [357.7808547369238, 0, 329.66778704539, 0, 0, 357.41035237313594, 240.04276942034474, 0, 0, 0, 1, 0]

Unable to change the node execution rate

Hi, thanks for open-sourcing this piece of code!
I have been using this to capture images from an Arducam OV9281 camera connected to my Linux workstation. However, I find that the node publishes at 10 Hz (I used rostopic hz cv_camera/image_raw to check) instead of the default 30 Hz. Moreover, setting the rate explicitly does not change the publishing rate. Is there a way fix this? Maybe I am missing something here? It would be great if you could help me out here.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.