Exemplo n.º 1
0
    def getDepthFrames(self, delay=.01, nFrames=10, maxDepth=2049):
        self.nFrames = nFrames
        self.delay = delay
        self.maxDepth = maxDepth
        freenect.start_depth(self.dev)
        freenect.set_depth_callback(self.dev, self.depthAcq)
        self.frames = []
        previousProgress = -1
        while len(self.frames) < nFrames:
            progress = len(self.frames) / nFrames
            if progress > previousProgress:
                blinked.progressColor(progress, 'c', 'o', pix=[2])
                previousProgress = progress

            freenect.process_events(self.ctx)
            time.sleep(delay)
Exemplo n.º 2
0
	def update_streams(self):
		if self.depth_started and not self.depth_consumers:
			logging.info("Stopping depth")
			freenect.stop_depth(self.dev)
			self.depth_started = False
		elif not self.depth_started and self.depth_consumers:
			logging.info("Starting depth")
			freenect.start_depth(self.dev)
			self.depth_started = True

		if self.video_started and not self.video_consumers:
			logging.info("Stopping video")
			freenect.stop_video(self.dev)
			self.video_started = False
		elif not self.video_started and self.video_consumers:
			logging.info("Starting video")
			freenect.start_video(self.dev)
			self.video_started = True
Exemplo n.º 3
0
    def update_streams(self):
        if self.depth_started and not self.depth_consumers:
            logging.info("Stopping depth")
            freenect.stop_depth(self.dev)
            self.depth_started = False
        elif not self.depth_started and self.depth_consumers:
            logging.info("Starting depth")
            freenect.start_depth(self.dev)
            self.depth_started = True

        if self.video_started and not self.video_consumers:
            logging.info("Stopping video")
            freenect.stop_video(self.dev)
            self.video_started = False
        elif not self.video_started and self.video_consumers:
            logging.info("Starting video")
            freenect.start_video(self.dev)
            self.video_started = True
Exemplo n.º 4
0
    def backGroundSubstractor(self, nFrames=100):
        self.nFrames = nFrames

        self.fgbg = cv2.createBackgroundSubtractorMOG2()
        freenect.start_depth(self.dev)
        freenect.set_depth_callback(self.dev, self.backAcq)
        self.background = []
        previousProgress = -1
        while len(self.background) < nFrames:

            freenect.process_events(self.ctx)
            time.sleep(.01)
            progress = len(self.background) / nFrames
            if progress > previousProgress:
                blinked.progressColor(progress, 'c', 'o', pix=[2])
                previousProgress = progress
        for frame in self.background:
            fgmask = self.fgbg.apply(frame, learningRate=0.01)
        self.background = []
Exemplo n.º 5
0
 def start_depth(self, callback):
     freenect.start_depth(self._dev)
     self._depth_callback = callback
     return freenect.set_depth_callback(self._dev, callback)
Exemplo n.º 6
0
 def start_depth(self, callback):
     freenect.start_depth(self._dev)
     self._depth_callback = callback
     return freenect.set_depth_callback(self._dev, callback)
Exemplo n.º 7
0
    cv.Resize(cv.fromarray(raw_image), cv.fromarray(image), cv.CV_INTER_AREA)
    cv.CvtColor(cv.fromarray(image), cv.fromarray(image), cv.CV_RGB2HSV)
    
    # Downsample the depth frame using nearest-neighbor to make sure 
    # invalid pixels are handled properly.
    cv.Resize(cv.fromarray(raw_depth), cv.fromarray(depth), cv.CV_INTER_NN)
    
    # Do the object recognition
    color.identify(image, constants, colors)
    global balls, yellow_walls, green_walls
    balls = blobs.find_blobs(colors, depth, color=0)
    yellow_walls = blobs.find_blobs(colors, depth, color=1, min_size=100)
    green_walls = blobs.find_blobs(colors, depth, color=2, min_size=10)

# Work around an initialization bug for synchronous image
try:
    ctx = freenect.init()
    dev = freenect.open_device(ctx, 0)
    if not dev:
        raise Exception
    freenect.start_video(dev) # sync_get_video hangs if we don't do this
    freenect.start_depth(dev) # sync_get_depth hangs if we don't do this
    freenect.stop_depth(dev)
    freenect.stop_video(dev)
    freenect.close_device(dev) # close the device so that c_sync can open it
    freenect.shutdown(ctx)
    process_frame()
    initialized = True
except:
    pass