Ask Your Question

How do I capture images from a wifi camera?

asked 2015-01-23 03:27:53 -0600

Kailegh gravatar image

updated 2015-01-27 16:46:14 -0600

Hi, i am new at this so I need your help, I need to capture images from a wifi camera( this in particular SJ4000 WIFI). I had thought of doing it using the usb_cam and changing the /dev/video0 for the one that uses my camera. My question is that I am not very sure if I can recieve images by wifi using the usb_cam node, and if it is possible I do not know how can I find the path to my wifi camera, /dev/video0 that is for my laptop cam but how do I find which is the one for my wifi camera?

Thanks a lot


thanks a lot, @ahendrix i have progressed a lot, but now i am stuck again, this is my code as far as i go( i use some of usb_cam code)

#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <camera_info_manager/camera_info_manager.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <sstream>

namespace wificampc {

class wificampc
  // private ROS node handle
  ros::NodeHandle node_;

  // shared image message
  sensor_msgs::Image img_;
  image_transport::CameraPublisher image_pub_;
  cv::Mat image;

  // parameters
  std::string video_device_name_, io_method_name_, pixel_format_name_, camera_name_, camera_info_url_;
  int image_width_, image_height_, framerate_, exposure_, brightness_, contrast_, saturation_, sharpness_, focus_,
      white_balance_ , device_id_;
  bool autofocus_, autoexposure_, auto_white_balance_;
  boost::shared_ptr<camera_info_manager::CameraInfoManager> cinfo_;

  wificampc() :
    // advertise the main image topic
    image_transport::ImageTransport it(node_);
    image_pub_ = it.advertiseCamera("image_raw", 1);

    // grab the parameters
    node_.param("video_device", video_device_name_, std::string("/dev/video0"));  //importante
    node_.param("device_id", device_id_, 0);                                      //importante

    node_.param("image_width", image_width_, 640);                              //importante
    node_.param("image_height", image_height_, 480);                            //importante
    node_.param("framerate", framerate_, 15);                                   //importante

    // load the camera info
    node_.param("camera_info_url", camera_info_url_, std::string(""));
    cinfo_.reset(new camera_info_manager::CameraInfoManager(node_, camera_name_, camera_info_url_));
    // check for default camera info
    //if (camera_info_url_.size() == 0)
      sensor_msgs::CameraInfo camera_info;
      camera_info.header.frame_id = img_.header.frame_id;
      camera_info.width = image_width_;
      camera_info.height = image_height_;

    ROS_INFO("Starting '%s' (%s) at %dx%d via %s (%s) at %i FPS", camera_name_.c_str(), video_device_name_.c_str(),
        image_width_, image_height_, io_method_name_.c_str(), pixel_format_name_.c_str(), framerate_);


  bool take_and_send_image()
      ROS_INFO("Capturing from %d", device_id_);
    cv::VideoCapture cap(device_id_);
    sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image).toImageMsg();

    // grab the camera info
    sensor_msgs::CameraInfoPtr ci(new sensor_msgs::CameraInfo(cinfo_->getCameraInfo()));
    ci->header.frame_id = msg->header.frame_id;
    ci->header.stamp = msg->header.stamp;

    // publish the image
    image_pub_.publish(*msg, *ci);
    return true;

  bool spin()

    ros::Rate loop_rate(this->framerate_);
    while (node_.ok())
      if (!take_and_send_image())
        ROS_WARN("Wifi camera did not respond in time.");
    return true;


int main(int argc, char **argv)
  ros::init(argc, argv, "usb_cam");
  wificampc::wificampc a;
  return EXIT_SUCCESS;

My problem now is that i do not know very well how to use image_transport::CameraPublisher, i dont know if the image you publish in your topic is supposed to have been modified by your camera info parameter and the one in the topic is different from the one capture; i do not really understand that. That is my ... (more)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-01-26 01:28:35 -0600

ahendrix gravatar image

usb_cam and gscam are not appropriate for what you're trying to do; they're for using webcams that you connect to your computer using USB.

I'm not aware of a ROS driver for the SJ4000. It looks like a fairly new camera, so I suspect no one has developed a ROS driver for it yet. You'll probably need to write your own driver.

A few places to start:

  • Go through the ROS C++ tutorials
  • Figure out how to retrieve images from your camera. Start with the basics, and work up to a C++ program which can receive raw images and display them on screen using OpenCV.
  • Convert your program into a C++ ROS node which receives images and publishes them using image_transport. Start with the image_transport publisher tutorial. Once you have that working, upgrade to the image_transport::CameraPublisher.
  • Read through the camera_info_manager tutorial. This library helps your driver store and publish calibration data, which will allow you to calibrate your camera later.
edit flag offensive delete link more

answered 2015-01-23 10:52:11 -0600


To start with, have you checked out this package:

In general terms, if you can access the web stream in OpenCV, you can write a python module to re-publish it as a rostopic.

Best wishes, Ilia

edit flag offensive delete link more


sorry but i do not get how can I get images from a wifi camera through that

Kailegh gravatar image Kailegh  ( 2015-01-23 14:22:00 -0600 )edit

mjpeg_server appears to be for subscribing to a topic and making it available over a web service. I think the OP is looking for a driver which can connect to a network camera and publish the images as a ROS topic.

ahendrix gravatar image ahendrix  ( 2015-01-26 01:17:48 -0600 )edit

Of course, I meant simply as a starting point to use as a model.

IliaBaranov gravatar image IliaBaranov  ( 2015-01-26 10:32:32 -0600 )edit

Your Answer

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

Add Answer

Question Tools



Asked: 2015-01-23 03:27:53 -0600

Seen: 2,071 times

Last updated: Jan 27 '15