camera_image.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #coding=utf-8
3 import os
4 import cv2
5 import rospy
6 from sensor_msgs.msg import Image
7 import cv2
8 from cv_bridge import CvBridge, CvBridgeError
9 
11  cmd = "ls /dev/video* > vs.out"
12  os.system(cmd)
13  vf = open('vs.out','r')
14  vs = vf.readlines()
15  vf.close()
16  vn = len(vs)
17  # print vs
18  for dev in vs:
19  vd = dev[:-1]
20  cmd = "udevadm info "+vd+" |grep 'ID_VENDOR_ID=0bda' > vs.info"
21  os.system(cmd)
22  infof = open("vs.info",'r')
23  info = infof.readlines()
24  infof.close()
25  # print info
26  if len(info)!=0:
27  return int(vd[-1])
28 
29  return -1
30 
31 
32 
33 
34 if __name__ == '__main__':
35  rospy.init_node('camera_image')
36  pub = rospy.Publisher('/xbot/camera/image', Image, queue_size=5)
37  index = getCameraId()
38  if index == -1:
39  rospy.loginfo("Not find face camera")
40  else:
41  capture = cv2.VideoCapture(index)
42  cv_bridge = CvBridge()
43 
44  while not rospy.is_shutdown():
45  ret, frame = capture.read()
46  frame = cv2.flip(frame,1) #镜像操作
47  msg = cv_bridge.cv2_to_imgmsg(frame,"bgr8")
48  pub.publish(msg)
49 
def getCameraId()
Definition: camera_image.py:10


xbot_face
Author(s):
autogenerated on Sat Oct 10 2020 03:27:46