image_to_shm.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import os, shutil
5 from sensor_msgs.msg import Image
6 
7 
8 filenum = 0
9 MAXFILES = 100
10 PATH = "/dev/shm/rosimgframes" # filename format: frame number (integer) only, with no extension
11 imgnum = 0
12 
13 
14 def cleanup():
15  rospy.sleep(3)
16  deletefiles()
17  rospy.loginfo("image_to_shm quit")
18 
19 
21  if os.path.isdir(PATH):
22  try:
23  shutil.rmtree(PATH)
24  except:
25  pass
26 
27 
28 def imgCallBack(data):
29  global filenum, imgnum
30 
31  # imgnum += 1
32  # if data.width > 640 and imgnum %2 == 0: # skip every other high res frame
33  # return
34 
35  oldfile = PATH+"/"+str(filenum-MAXFILES)
36 
37  if os.path.exists(oldfile):
38  os.remove(oldfile)
39 
40  f = open(PATH+"/"+str(filenum), "w")
41  f.write(data.data)
42  f.close()
43 
44  filenum += 1
45 
46 
47 deletefiles()
48 os.mkdir(PATH)
49 
50 rospy.init_node('image_to_shm', anonymous=False)
51 rospy.loginfo("image_to_shm init")
52 rospy.Subscriber(rospy.get_param('~camera_topic', 'usb_cam/image_raw'), Image, imgCallBack)
53 rospy.on_shutdown(cleanup)
54 print "using topic: "+rospy.get_param('~camera_topic', 'usb_cam/image_raw')
55 
56 rospy.spin()
def imgCallBack(data)
Definition: image_to_shm.py:28
def deletefiles()
Definition: image_to_shm.py:20


oculusprime
Author(s): Colin Adamson
autogenerated on Wed Mar 10 2021 03:14:59