Ask Your Question
0

how can i capture an image from camera using opencv c++ code in ROS ?

asked 2017-08-11 03:04:56 -0500

omar1995 gravatar image

updated 2017-08-11 04:34:53 -0500

rbbg gravatar image

This is my code: but I don't how to use it in ROS.Please help me step by step.

#include "opencv2/opencv.hpp"
using namespace cv;
int main(int argc, char** argv)
{
    VideoCapture cap;
    // open the default camera, use something different from 0 otherwise;
    // Check VideoCapture documentation.
    if(!cap.open(0))
        return 0;
    for(;;)
    {
          Mat frame;
          cap >> frame;
          if( frame.empty() ) break; // end of video stream
          imshow("this is you, smile! :)", frame);
          if( waitKey(10) == 27 ) break; // stop capturing by pressing ESC 
    }
    // the camera will be closed automatically upon exit
    // cap.close();
    return 0;
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-08-11 06:38:48 -0500

You should have a look at the UVC camera package or at the lib UVC camera package since I suppose you you are using a USB camera.

To make the node works with your camera you should check the device name is the launch file. The node will then publish the camera frames to an image topic.

Then if you want to display them, you should either :

  • Use the image view package to visualize your frames
  • Write a subscriber to your image topic and display them using imshow(). This second solution allows you to use the images for processing. You will find a simple tutorial here.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2017-08-11 03:04:56 -0500

Seen: 4,931 times

Last updated: Aug 11 '17