USB Cam

정승균·2021년 1월 20일
0

ROS

목록 보기
14/14
post-thumbnail

Ⅰ. usb_cam 노드


1. 실행 방법

2. 파라미터

parameter타입기본값의미
video_devicestring"/dev/video0"디바이스 위치
image_widthinteger640이미지 너비
image_heightinteger480이미지 높이
pixel_formatstring"mjpeg"mjepeg, yuvy, uyvy
io_methodstring"mmap"mmap, read, userptr
camera_frame_idstring"head_camera"카메라의 tf frame
framerateinteger30fps
contrastinteger32이미지의 대비값 (0-255)
brightnessinteger32이미지 밝기 (0-255)
saturationinteger32이미지 채도 (0-255)
sharpnessinteger22이미지 선명도 (0-255)
autofocusbooleanfalse자동 초점
focusinteger51autofocus="false"인 경우 초점 거리 (0=at infinity)
autoexposureboolean?자동 노출
exposureinteger?autoexposure="false"인 경우 노출 값

3. 예제 launch file

<launch>
  <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
    <param name="video_device" value="/dev/video0" />
    <param name="image_width" value="640" />
    <param name="image_height" value="480" />
    <param name="autoexposure" value="false" />
    <param name="exposure" value="50" />
    <param name="pixel_format" value="yuyv" />
    <param name="camera_frame_id" value="usb_cam" />
    <param name="io_method" value="mmap"/>
  </node>
  <node name="image_view" pkg="image_view" type="image_view" respawn="false" output="screen">
    <remap from="image" to="/usb_cam/image_raw"/>
    <param name="autosize" value="true" />
  </node>
</launch>

Ⅱ. usb_cam 토픽


1. 토픽과 메세지 유형

  • usb_cam/image_raw, usb_cam/image_raw/compressed 토픽을 발행

  • sensor_msgs/Image 타입의 메시지를 사용

    • data field에 프레임 정보가 리스트로 담겨있다.

2. 이미지 토픽을 받아 동영상으로 저장

  • rosrun image_view video_recorder image:='usb_cam/image_raw' _filename='video.avi' _fps=30

Ⅲ. CvBridge


  • 이미지 데이터 형태를 ros와 openCV간 변환시켜줌

1. ROS -> OpenCV

from cv_bridge import CvBridge
bridge = CvBridge()
cv_image = bridge.imgmsg_to_cv2(image_message, desired_encoding='passthrough')

2. OpenCV -> ROS

from cv_bridge import CvBridge
bridge = CvBridge()
image_message = bridge.cv2_to_imgmsg(cv_image, encoding="passthrough")

3. encoding

  • passthrough : msg.encoding에서 설정된 값 그대로 사용

  • mono8 : CV_8UC1, grayscale image

  • mono16 : CV_16UC1, 16-bit grayscale image

  • bgr8 : CV_8UC3, color image with blue-green-red color order

  • rgb8 : CV_8UC3, color image with red-green-blue color order

  • bgra8 : CV_8UC4, BGR color image with an alpha channel

  • rgba8 : CV_8UC4, RGB color image with an alpha channel


Ⅳ. 예시


import  cv2
import rospy
import numpy as np

from sensor_msgs.msg import Image
from cv_bridge import CvBridge

bridge = CvBridge()
cv_image = np.empy(shape=[0])

def img_callback(data):
	global cv_image
    cv_image = bridge.imgmsg_to_cv2(data, "bgr8")

rospy.init_node('cam_tune' anonymous=True)
rospy.Subscriber("/usb_cam/image_raw/", Image, img_callback)

while not rospy.is_shutdown():
	if cv_image.size != (640*480*3):
    	continue
    cv2.imshow("display", cv_image)
    cv2.waitKey(33)

0개의 댓글