티스토리 뷰

1. 패키지 생성

catkin_create_pkg my_cam std_msgs rospy

 

2. launch 파일

edge_cam.launch

<launch>
	<node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
		<param name="video_device" value="/dev/video0" />
		<param name="autoexposure" value="false" />
		<param name="exposure" value="48" />
		<param name="image_width" value="640" />
		<param name="image_height" value="480" />
		<param name="pixel_format" value="yuyv" />
		<param name="camera_frame_id" value="usb_cam" />
		<param name="io_method" value="mmap" />
	</node>
	<node name="my_cam" pkg="my_cam" type="edge_cam.py" output="screen"/>
</launch>

 

3. 소스 파일

edge_cam.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import cv2
import rospy
import numpy as np

from sensor_msgs.msg import Image
from cv_bridge import CvBridge

bridge = CvBridge()
cv_image = np.empty(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 rosopy.is_shutdown():
	if cv_image.size != (640*480*3):
		continue
	gray = cv2.cvtColor(cv_image, cv2.COLOR_BGR2GRAY)
	blur_gray = cv2.GaussianBlur(gray, (5, 5), 0)
	edge_img = cv2.Canny(np.uint8(blur_gray), 60, 70)

	cv2.imshow("original", cv_image)
	cv2.imshow("gray", gray)
	cv2.imshow("gaussian blur", blur_gray)
	cv2.imshow("edge", edge_img)
	cv2.waitKey(1)

 

4. 실행

roslaunch my_cam edge_cam.launch

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함