17
17
class ImageCapture (object ):
18
18
19
19
def __init__ (self , imageManager , fileSaveLocation ,
20
- cameraName = "OPENNI_FRAME_LEFT" , setupCallback = False ):
20
+ cameraName = "OPENNI_FRAME_LEFT" , setupCallback = False ):
21
21
self .imageManager = imageManager
22
22
self .fileSaveLocation = fileSaveLocation
23
23
self .cameraName = cameraName
@@ -31,27 +31,28 @@ def setupCallback(self):
31
31
lcmUtils .addSubscriber ("OPENNI_FRAME" , lcmbotcore .images_t (),
32
32
self .onImageMessage )
33
33
34
- def saveImage (self , extension = "rgb.png" ):
34
+ def saveImage (self , saveUtime = True , extension = "rgb.png" ):
35
35
# construct filename where this image will be saved
36
36
baseFilename = utils .convertImageIDToPaddedString (self .counter ) + "_"
37
37
baseFilename = os .path .join (self .fileSaveLocation , baseFilename )
38
- rgbFilename = baseFilename + extension
39
- utimeFilename = baseFilename + "utime.txt"
38
+ imageFilename = baseFilename + extension
40
39
self .counter += 1
41
40
42
41
# get the image and it's utime
43
42
self .imageManager .updateImages ()
44
43
image = self .imageManager .getImage (self .cameraName )
45
- utime = self .imageManager .getUtime (self .cameraName )
46
44
image = filterUtils .flipImage (image )
47
- print 'writing:' , rgbFilename
48
- ImageCapture .writeImage (image , rgbFilename )
49
-
50
- # now save the utime
51
- print 'writing:' , utimeFilename
52
- text_file = open (utimeFilename , "w" )
53
- text_file .write (str (utime ))
54
- text_file .close ()
45
+ print 'writing:' , imageFilename
46
+ ImageCapture .writeImage (image , imageFilename )
47
+
48
+ if saveUtime :
49
+ utime = self .imageManager .getUtime (self .cameraName )
50
+ utimeFilename = baseFilename + "utime.txt"
51
+ # now save the utime
52
+ print 'writing:' , utimeFilename
53
+ text_file = open (utimeFilename , "w" )
54
+ text_file .write (str (utime ))
55
+ text_file .close ()
55
56
56
57
@staticmethod
57
58
def writeImage (image , filename ):
@@ -80,8 +81,7 @@ def onImageMessage(self, msg):
80
81
81
82
82
83
@staticmethod
83
- def readFromLogFile (lcmLogFilename , fileSaveLocation , channelName = "OPENNI_FRAME" ,
84
- cameraName = "OPENNI_FRAME_LEFT" ):
84
+ def readFromLogFile (lcmLogFilename , fileSaveLocation , channelName = "OPENNI_FRAME" , cameraName = "OPENNI_FRAME_LEFT" , saveDepth = False ):
85
85
"""
86
86
Reads from lcmlog located at filename. Goes through each
87
87
images_t() message on OPENNI_FRAME channel and saves it
@@ -94,26 +94,37 @@ def readFromLogFile(lcmLogFilename, fileSaveLocation, channelName="OPENNI_FRAME"
94
94
if not os .path .isdir (fileSaveLocation ):
95
95
os .makedirs (fileSaveLocation )
96
96
97
- # first construct imageManager object
97
+
98
+ # construct imageManager object
98
99
imageManager = cameraview .ImageManager ()
99
- imageManager .queue .addCameraStream (channelName , cameraName , lcmbotcore .images_t .LEFT )
100
+ if saveDepth :
101
+ imageManager .queue .addCameraStream (channelName , cameraName , lcmbotcore .images_t .DEPTH_MM_ZIPPED )
102
+ else :
103
+ imageManager .queue .addCameraStream (channelName , cameraName , lcmbotcore .images_t .LEFT )
100
104
imageManager .addImage (cameraName )
101
105
102
106
# open the lcm log
103
107
imageManager .queue .openLCMFile (lcmLogFilename )
104
108
105
109
imageCapture = ImageCapture (imageManager , fileSaveLocation ,
106
- cameraName = "OPENNI_FRAME_LEFT" , setupCallback = False )
110
+ cameraName = cameraName , setupCallback = False )
107
111
108
112
while imageManager .queue .readNextImagesMessage ():
109
- imageCapture .saveImage ()
113
+ if saveDepth :
114
+ imageCapture .saveImage (saveUtime = False , extension = "depth.png" )
115
+ else :
116
+ imageCapture .saveImage (extension = "rgb.png" )
110
117
111
118
print "reached end of lcm log"
112
119
return
113
120
114
- def captureImages (logFolder ):
115
- paths = utils .getFilenames (logFolder )
116
- ImageCapture .readFromLogFile (paths ['lcmlog' ], paths ['images' ])
121
+ def captureImages (logFolder , saveDepth ):
122
+ corlPaths = utils .getFilenames (logFolder )
123
+
124
+ if saveDepth :
125
+ ImageCapture .readFromLogFile (corlPaths ['lcmlog' ], corlPaths ['images' ], cameraName = "OPENNI_FRAME_DEPTH_MM_ZIPPED" , saveDepth = True )
126
+
127
+ ImageCapture .readFromLogFile (corlPaths ['lcmlog' ], corlPaths ['images' ], cameraName = "OPENNI_FRAME_LEFT" )
117
128
118
129
119
130
def test ():
0 commit comments