ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Converting raw image into mono8

asked 2015-06-11 15:59:47 -0500

dshimano gravatar image

Hi, I'm trying to use the ethzasl_ptam node. Curently, I am passing an image to it using my webcam with the uvc_camera node. I am getting clean raw footage from the uvc_camer node (I can see in with rqt), but the screan that comes up with the ptam node is weird looking. After looking around online, I think this is happening becouse the ptam node needs mono8 video, not color. I have been looking around for how to change the video type, and the best way seems to be with opencv. However, I haven't fpund any tutorials I understand. I've tried to follow this one, but I am not sure I followed it corectlly. My computer didn't think I wrote a node when I tried to implement the file on the tutorial (auto-tab didn't work, and when I used rosrun I got a "cv in neithe a node or a package" error message) and when I ran it with ./cv.py an error poped up

 Traceback (most recent call last):
  File "./cv.py", line 3, in <module>
    roslib.load_manifest('my_package')
  File "/opt/ros/indigo/lib/python2.7/dist-packages/roslib/launcher.py", line 62, in load_manifest
    sys.path = _generate_python_path(package_name, _rospack) + sys.path
  File "/opt/ros/indigo/lib/python2.7/dist-packages/roslib/launcher.py", line 93, in _generate_python_path
    m = rospack.get_manifest(pkg)
  File "/usr/lib/python2.7/dist-packages/rospkg/rospack.py", line 163, in get_manifest
    return self._load_manifest(name)
  File "/usr/lib/python2.7/dist-packages/rospkg/rospack.py", line 207, in _load_manifest
    retval = self._manifests[name] = parse_manifest_file(self.get_path(name), self._manifest_name, rospack=self)
  File "/usr/lib/python2.7/dist-packages/rospkg/rospack.py", line 199, in get_path
    raise ResourceNotFound(name, ros_paths=self._ros_paths)
rospkg.common.ResourceNotFound: my_package

Any direction anyone can offer would be apriciated.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2015-06-11 17:26:37 -0500

updated 2015-06-11 17:27:36 -0500

One possibly easier way to solve your original problem is to use image_proc. If you run image_proc correctly it will automatically create a /my_camera/image_mono topic that your ethzasl_ptam node can subscribe to (probably with some remapping).

edit flag offensive delete link more

Comments

Thanks, I just got it to work using image proc. Now I'm need to put it in a nice little launch file.

dshimano gravatar image dshimano  ( 2015-06-15 14:23:21 -0500 )edit
1

answered 2018-09-25 10:24:21 -0500

lucasw gravatar image

I've added a nodelet here https://github.com/lucasw/image_manip to convert most types to most other types: rgb, bgr and mono of 8/16/32/64 to any other (but yuv422 isn't supported yet). Dynamic reconfigure is used to change the destination types.

I haven't tested all the combinations so likely there is some wrong behavior and errors.

image description

rqt_image_view doesn't support some of the types, though adding mono32 or bgr64 etc. support to it won't be too hard.

This is an example launch file using a stored image.

edit flag offensive delete link more
0

answered 2015-06-13 23:21:29 -0500

I've wrote a simple program to transform raw image(in RGB) to grayscale image.

Here's the code:

 #include <ros/ros.h>
 #include <cv_bridge/cv_bridge.h>
 #include <sensor_msgs/image_encodings.h>
 #include <opencv2/imgproc/imgproc.hpp>
 using namespace cv;

 ros::Publisher pub;
 void transformer(const sensor_msgs::Image::ConstPtr& img)
 {
      cv_bridge::CvImagePtr cvimg = cv_bridge::toCvCopy(img , sensor_msgs::image_encodings::BGR8);
      //To Grayscale
      cv::Mat img_conv;
      cv::cvtColor(cvimg->image,img_conv,CV_BGR2GRAY);

      //Publish it
      cvimg->image = img_conv;
      cvimg->encoding = "mono8";  //This is easily forgotten
      pub.publish(cvimg->toImageMsg());
 }

 int main(int argc, char** argv)
 {
      ros::init(argc, argv, "color_to_gray_node");
      ros::NodeHandle node;

      pub = node.advertise("/usb_cam/image_mono", 1000);
      ros::Subscriber sub = node.subscribe("/usb_cam/image_raw", 1, transformer);

      ros::spin();
}
edit flag offensive delete link more

Comments

Can I use this code the other way, mono8 to rgb? The camera provided on my robot is mono8 but my CNN wants rgb.

arsenicCatnip gravatar image arsenicCatnip  ( 2022-05-05 08:07:11 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2015-06-11 15:59:47 -0500

Seen: 3,490 times

Last updated: Sep 25 '18