0
$\begingroup$

Rosanswers logo

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;
}

Originally posted by omar1995 on ROS Answers with karma: 1 on 2017-08-11

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.

Originally posted by jeanpolochon with karma: 140 on 2017-08-11

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.