Example #1
0
    def get_next_frame_clean(self, save=1):
        self.depthStream.start()
        self.depthFrame = self.depthStream.readFrame()
        self.depthStream.stop()
        self.irFrame = self.irStream.readFrame()

        # colorFrame = colorStream.readFrame()
    
        # TODO : Review depthMapToImage in the code below
        # TODO : Does the function depthMapToImage apply to irFrame as well????

        depthImage = None
        depthImage = Image.fromarray(cyni.depthMapToImage(self.depthFrame.data))
        

        irImage = Image.fromarray(cyni.depthMapToImage(self.irFrame.data))
        #colorImage = Image.fromarray(colorFrame.data)

        if (save==1):
            timestamp = time.time()
            irImage_filename = "ir" +  str(timestamp)+".png"
            depthImage_filename = "depth" +  str(timestamp)+".png"
            depthImage.save("/home/madhav/Desktop/Structure-Sensor/Work/Robotic-Vision/cythonNI/examples/capture/depth"+str(timestamp)+".png")
            #colorImage.save("capture/color"+str(timestamp)+".png")
            irImage.save("/home/madhav/Desktop/Structure-Sensor/Work/Robotic-Vision/cythonNI/examples/capture/ir"+str(timestamp)+".png")

        return depthImage, irImage, irImage_filename, depthImage_filename #, colorImage
Example #2
0
import cyni
import numpy as np
import PIL as Image

cyni.initialize()
device = cyni.getAnyDevice()
device.open()
depthStream = device.createStream("depth", fps=30, width=640, height=480)
#colorStream = device.createStream("color", fps=30, width=1280, height=960)
#colorStream = device.createStream("color", fps=30, width=640, height=480)
#device.setImageRegistrationMode("depth_to_color")
device.setDepthColorSyncEnabled(on=True)
depthStream.start()
# colorStream.start()
# colorFrame = colorStream.readFrame()
# colorFrame = colorStream.readFrame()
# colorFrame = colorStream.readFrame()
# colorFrame = colorStream.readFrame()
depthFrame = depthStream.readFrame()
# registered = cyni.registerColorImage(depthFrame.data, colorFrame.data, depthStream, colorStream)
# Image.fromarray(colorFrame.data).save("color.png")
# Image.fromarray(registered).save("registered.png")
Image.fromarray(cyni.depthMapToImage(depthFrame.data)).save("depth.png")
Example #3
0
import cyni
import numpy as np
import Image
import time

cyni.initialize()
device = cyni.getAnyDevice()
device.open()
depthStream = device.createStream("depth", fps=30)
depthStream.start()

depthStream.setEmitterState(False)
depthFrame = depthStream.readFrame()
while np.sum(depthFrame.data) != 0:
    depthFrame = depthStream.readFrame()
Image.fromarray(cyni.depthMapToImage(depthFrame.data)).save("depth_off.png")

depthStream.setEmitterState(True)
depthFrame = depthStream.readFrame()
while np.sum(depthFrame.data) == 0:
    depthFrame = depthStream.readFrame()
# Read one more just to ensure the emitter is totally on
depthFrame = depthStream.readFrame()
Image.fromarray(cyni.depthMapToImage(depthFrame.data)).save("depth_on.png")
        #print time.time() - start
        #depth = depthStream.readFrame()
        #while np.sum(depth.data) == 0:
        #    depth = depthStream.readFrame()
        time.sleep(1/args.freq)
        #start = time.time()
        depth = depthStream.readFrame()
        data.append(depth.data)
        #print 'time read %f'%(time.time() - start)
        #print 1
	#print depth.data
        #data.append(depth.data)
        #start = time.time()
        depthStream.setEmitterState(False)
        #depth = depthStream.readFrame()
        #while np.sum(depth.data) != 0:
        #    depth = depthStream.readFrame()
        #print 'time %f'%(time.time() - start)
        #print depth.data
        #time.sleep(0.5/args.freq)
        #cv2.imshow("depth", cmap[np.fmin((depth.data*.064).astype('int'), 255)])
        #cv2.waitKey(100)
except KeyboardInterrupt:
    print "saving" 
    subprocess.call("rm -rf depth/%s"%(args.name), shell=True)
    subprocess.call("mkdir depth/%s"%(args.name), shell=True)
    for i in xrange(len(data)):
        Image.fromarray(cyni.depthMapToImage(data[i])).save("depth/%s/depth%i.png"%(args.name, i))
    t = time.time() - start
    print len(data)/t