How do I capture images from a wifi camera?
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
EDIT 1:
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
{
public:
// 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() :
node_("~")
{
// 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)
{
cinfo_->setCameraName(video_device_name_);
sensor_msgs::CameraInfo camera_info;
camera_info.header.frame_id = img_.header.frame_id;
camera_info.width = image_width_;
camera_info.height = image_height_;
cinfo_->setCameraInfo(camera_info);
}
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_);
cap>>image;
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.");
ros::spinOnce();
loop_rate.sleep();
}
return true;
}
};
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "usb_cam");
wificampc::wificampc a;
a.spin();
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 ...