Ask Your Question

Slippery John's profile - activity

2017-09-18 16:54:17 -0500 received badge  Good Question (source)
2016-09-12 06:23:22 -0500 received badge  Nice Question (source)
2013-10-27 23:16:52 -0500 received badge  Favorite Question (source)
2013-04-11 03:20:21 -0500 received badge  Nice Question (source)
2012-12-03 20:49:28 -0500 received badge  Famous Question (source)
2012-11-21 06:26:37 -0500 received badge  Notable Question (source)
2012-11-14 18:19:26 -0500 received badge  Popular Question (source)
2012-10-31 07:30:30 -0500 asked a question uvc_camera gets a terrible image and usb_camera doesn't set framerate

I have a Logitech c920 webcam that I want to use with ROS. I originally installed uvc_camera, but it gets a terrible quality image from the camera. Then I tried usb_cam, which gets a fantastic quality image, but only at 10fps (which just isn't good enough).

uvc_cam image

usb_camera image

So my question is: How do I get a good image out of uvc OR How do I set frame rate with usb_camera

It should be noted that guvcview gets a fantastic image using the uvc driver, though ros does not.

launch file contents:

FOR usb_cam:
<launch>
    <node name="camera" pkg="usb_cam" type="usb_cam_node" output="screen" >
        <param name="video_device" value="/dev/video1" />
        <param name="image_width" value="1280" />
        <param name="image_height" value="720" />
        <param name="pixel_format" value="yuyv" />
        <param name="camera_frame_id" value="webcam" />
    </node>
</launch>

FOR uvc_camera:
<launch>
  <node ns="camera" pkg="uvc_camera" type="camera_node" name="uvc_camera" output="screen">
    <param name="width" type="int" value="1280" />
    <param name="height" type="int" value="720" />
    <param name="fps" type="int" value="30" />
    <param name="frame" type="string" value="webcam" />
    <param name="device" type="string" value="/dev/video1" />
  </node>
</launch>
2012-10-17 07:20:57 -0500 received badge  Famous Question (source)
2012-10-14 07:06:37 -0500 received badge  Notable Question (source)
2012-10-14 04:11:40 -0500 received badge  Popular Question (source)
2012-10-13 14:04:12 -0500 received badge  Student (source)
2012-10-13 07:26:15 -0500 asked a question ROS and OpenCV: sending single images, image type, and receiving laptop camera stream

WARNING: super beginner

For a week or so, me and a few others were working with openCV outside of ROS and we got some things up and running. It has fallen upon me to figure out how to get it all translated into a form run-able via ROS. Using the example node from this tutorial as a template, I created what I hope is a functional node that isolates pixels with certain B, G, or R values. I'll post the code for said node at the bottom (it's short).

On to my actual questions though:

  1. How can I send it a single image? This is probably just a nomenclature misunderstanding, but the tutorial indicates that the node will require an image stream as input but to date I've only been using individual image files.
  2. What is the type for ROS images? I may need to create my own message type so I can add more parameters to the code.
  3. How can I get an input stream from my laptop's webcam? I don't have frequent access to the Husky that we will eventually be using, so it would be nice to be able to use that.

Below is the code for my node. It shouldn't be necessary to answer, so feel free to skip it.

#!/usr/bin/env python
import roslib; roslib.load_manifest('ports')
import sys
import rospy
import cv
import numpy as np
from std_msgs.msg import String
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError

class isolateColorServer:

    def __init__(self):
        self.image_pub = rospy.Publisher("image_topic_2", Image)
        cv.NamedWindow("Image Window", 1)
        self.bridge = CvBridge()
        self.image_sub = rospy.Subscriber("image_topic", Image, self.callback)

    def callback(self, data):
        try:
            cv_image = self.bridge.imgmsg_to_cv(data, "bgr8")
        except CvBridgeError, e:
            print e

        color = 'R'
        value = 128

        if (color == 'R'):
            cv_image[np.where((cv_image >= [0, 0, value]).all(axis=2))] = [0, 0, 255]
            cv_image[np.where((cv_image <= [255, 255, value]).all(axis=2))] = [255, 255, 255]
        elif (color == 'G'):
            cv_image[np.where((cv_image >= [0, value, 0]).all(axis=2))] = [0, 255, 0]
            cv_image[np.where((cv_image <= [255, value, 255]).all(axis=2))] = [255, 255, 255]
        elif (color == 'B'):
            cv_image[np.where((cv_image >= [value, 0, 0]).all(axis=2))] = [255, 0, 0]
            cv_image[np.where((cv_image <= [value, 255, 255]).all(axis=2))] = [255, 255, 255]
        else:
            print("You picked an incorrect value for the color field. You need to pick R, G, or B.")

        cv.ShowImage("Image Window", cv_image)
        cv.WaitKey(3)

        try:
            self.image_pub.publish(self.bridge.cv_to_imgmsg(cv_image, "bgr8"))
        except CvBridgeError, e:
            print e

def main(args):
    ics = isolateColorServer()
    rospy.init_node('isolateColorServer', anonymous=True)
    try:
        rospy.spin()
    except KeyboardInterrupt:
        print "Shutting Down"
    cv.DestroyAllWindows()

if __name__ == '__main__':
    main(sys.argv);