def __init__(self): print('Press ESC in window to stop') self.depth_image = None; freenect.runloop(depth=self.do_depth, video=self.do_rgb, body=self.body) self.th1, self.th2 = 0,0
def start(self): # Asynchronously loads data from kinect # self.body just kills when it gets ESC freenect.runloop( depth=self.process_depth_info, video=self.process_rgb, body=self.body)
def ping_kinect(): cv.NamedWindow('Depth') cv.NamedWindow('RGB') keep_running = True def display_depth(dev, data, timestamp): global keep_running cv.ShowImage('Depth', frame_convert.pretty_depth_cv(data)) if cv.WaitKey(10) == 27: keep_running = False def display_rgb(dev, data, timestamp): global keep_running cv.ShowImage('RGB', frame_convert.video_cv(data)) if cv.WaitKey(10) == 27: keep_running = False def body(*args): if not keep_running: raise freenect.Kill print('Press ESC in window to stop') freenect.runloop(depth=display_depth, video=display_rgb, body=body)
def display(self, video=True, depth=False): if not self.device: self.device = get_device(self.device_num) if video: self.set_video_mode() if depth: self.set_depth_mode() def video_cb(dev, video, timestamp): if self.video_mode.fmt == fn.VIDEO_RGB: # OpenCV uses BGR instead of RGB video = cv.cvtColor(video, cv.COLOR_RGB2BGR) cv.imshow(f'Video - Device {self.device_num}', video) self.waitKey() def depth_cb(dev, depth, timestamp): pass def body_cb(dev, ctx): if self._should_kill: LOG.info('Killing streams') raise fn.Kill on_video = video_cb if video else None on_depth = depth_cb if depth else None fn.runloop(depth=on_depth, video=on_video, body=body_cb, dev=self.device) cv.destroyAllWindows()
def loop(self): """ Freenect has its own looping function, so we have to use that. Put general things that should happen in every frame into the "body" callback. """ freenect.runloop(depth=self.handle_depth_frame, video=self.handle_video_frame, body=self.kinect_body_callback)
def main_loop(self): print("KinectVision.main_loop()") print('Press ESC in window to stop') freenect.runloop(depth=self.display_depth, video=self.display_rgb, body=self.body)
def __init__(self): print('Press ESC in window to stop') self.depth_image = None freenect.runloop(depth=self.do_depth, video=self.do_rgb, body=self.body) self.th1, self.th2 = 0, 0
def Main(): global filenamePrefix procComms.PrintLog('Initializing...') # precalc depth lookup pointCloudHelpers.PrecalcDepthLookupTable() procComms.PrintLog('Precalculated depth lookup table.') # find filename with highest index so that we don't overwrite anything maxIdx = 0 for filepath in glob.glob('../output/*.scan'): # shitty code but whatev a, b, filename = filepath.split('/') name, ext = filename.split('.') idx = int(name) if idx > maxIdx: maxIdx = idx filenamePrefix = maxIdx procComms.PrintDebug('Found last scan index: ' + str(filenamePrefix)) freenect.runloop( depth = DepthCallback, video = VideoCallback, body = BodyCallback)
def open_camera(self): cv2.startWindowThread() cv2.namedWindow('RGB') cv2.moveWindow('RGB', 20, 20) cv2.startWindowThread() print('starting freenect') freenect.runloop(video=self.display_camera_fourth, body=self.body)
def run(self): """Starts execution""" freenect.runloop( depth=self.display_depth, video=self.display_rgb, body=self.main )
def main(): # Start kinect recording # freenect.runloop(depth=display_depth, video=display_rgb, body=body) # start opengl # init_gl() freenect.runloop(depth=display_depth, video=display_rgb, body=body)
def main(): target_dir = "saved" if not os.path.isdir(target_dir): os.mkdir(target_dir) setup_handler() freenect.runloop(body=body, video=video, depth=depth) cv2.destroyAllWindows()
def start_kinect(self): """Initialize the depth camera, or send empty array if it is off""" if ENABLE_KINECT: freenect.runloop(depth=self.send_depth, video=self.send_rgb, body=self.body) else: self.current_depth_frame = np.empty((640, 480)) self.current_rgb_frame = np.empty((640, 480))
def main(): target_dir = "saved" if not os.path.isdir(target_dir): os.mkdir(target_dir) setup_handlers() print("Do NOT touch the canvas until the camera is not calibrated!") print("Calibration started...") freenect.runloop(body=body, video=video, depth=depth) cv2.destroyAllWindows()
def run(self): """ Instrucción ejecutada por el Thread. Parametros: None Return: None """ while not self.quit: # Ejecuta un ciclo de ejecución del Kinect. freenect.runloop( depth=self.display_depth, # Control de imagen de profundidad. video=self.display_rgb, # Control de imagen de color. body=self.main # Control de motor y led Kinect. )
def main(): face_cascade = cv2.CascadeClassifier( path.join(cv2.haarcascades, "haarcascade_frontalface_default.xml")) color_img = AtomicTimeVar() gray_img = AtomicTimeVar() depth_img = AtomicTimeVar() freenect.runloop(depth=gen_handle_depth(depth_img), video=gen_handle_video(color_img, gray_img), body=gen_handle_body(face_cascade, color_img, gray_img, depth_img))
def start(mode = "tr"): """ Start method for the module, used by other modules to initialize Kinect services. """ global run_mode, file_manager, faceCascade run_mode= mode file_manager = Sample_Manager() faceCascade = file_manager.faceCascade freenect.runloop(video=display_rgb,depth=display_depth,body=body) #start("tr")
def start(mode="tr"): """ Start method for the module, used by other modules to initialize Kinect services. """ global run_mode, file_manager, faceCascade run_mode = mode file_manager = Sample_Manager() faceCascade = file_manager.faceCascade freenect.runloop(video=display_rgb, depth=display_depth, body=body) #start("tr")
def main(address, port): context = zmq.Context() socket = context.socket(zmq.PUB) socket.setsockopt(zmq.HWM, 10) print('Listening on [%s:%d]' % (address, port)) socket.bind("tcp://%s:%d" % (address, port)) depth_type = kinectfs_pb2.KinectMessage.KinectFrame.FREENECT_DEPTH_11BIT video_type = kinectfs_pb2.KinectMessage.KinectFrame.FREENECT_VIDEO_RGB depth = functools.partial(send_frame, socket, depth_type) video = functools.partial(send_frame, socket, video_type) freenect.runloop(depth=depth, video=video, body=update_tilt)
def run(self, contact_update_callback): self.keep_running = True print("setting up handlers") #self._setup_handlers() print("save the contact update callback") self.contact_update_callback = contact_update_callback print("decide if dummy") if not self.dummy_loop_frames is None: self._run_dummy_loop() else: print("starting a prod loop") freenect.runloop(depth=self._depth_callback, body=self._body) cv2.destroyAllWindows() # if any
def generate_modelpoints(i_c, argv): if i_c == None and not (len(sys.argv) == 4 and sys.argv[3] == '1'): print "Error: The intrinsic matrix hasn't been calculated yet, please do that before you continue" return None global intrinsic_matrix, distortion, fake if len(sys.argv) == 4 and sys.argv[3] == '1': try: intrinsic_matrix = cv.Load("Camera_matrix.xml") distortion = cv.Load("Distortion.xml") except: print "Error: The intrinsic matrix hasn't been calculated yet, please do that before you continue" return None else: intrinsic_matrix = i_c[0] distortion = i_c[1] print "Press esc to stop" cv.NamedWindow('Depth') cv.NamedWindow('RGB') cv.SetMouseCallback("RGB",mouseclick,None) if len(argv) > 1 and argv[1] != "0": rgb_im = np.load("RGB.npy") depth_im = np.load("Depth.npy") if argv[1] == "1": fake = True while(1): try: display_depth(None,depth_im,None) display_rgb(None,rgb_im,None) except freenect.Kill: print "\nInfo: Done gathering points" break cv.DestroyAllWindows() else: try: freenect.runloop(depth=display_depth, video=display_rgb, body=body) except freenect.Kill: print "\nInfo: Done gathering points" cv.DestroyAllWindows() return None
def main(path): global fp depth_type = kinectfs_pb2.KinectMessage.KinectFrame.FREENECT_DEPTH_11BIT video_type = kinectfs_pb2.KinectMessage.KinectFrame.FREENECT_VIDEO_RGB depth = functools.partial(save_frame, depth_type) video = functools.partial(save_frame, video_type) start_time = time.time() with open(path, 'w') as fp: freenect.runloop(depth=depth, video=video, body=update_tilt) fps_rgb = total_frames_rgb / (time.time() - start_time) fps_depth = total_frames_depth / (time.time() - start_time) print('# frames(RGB): %d FPS(RGB): %f' % (total_frames_rgb, fps_rgb)) print('# frames(DEPTH): %d FPS(DEPTH): %f' % (total_frames_depth, fps_depth))
def __init__(self, module_path=None): self.module_path = module_path self.depth_func = lambda x: x self.module_key = '' self.keep_running = True self.depth_func = None self.depth_image = None if self.module_path: self.load_external_module(self.module_path) cv2.namedWindow('Depth') cv2.setMouseCallback('Depth', self.mouse_depth) cv2.namedWindow('RGB') cv2.setMouseCallback('RGB', self.mouse_rgb) freenect.runloop(depth=self.display_depth, video=self.display_rgb, body=self.main_loop)
def main(argv=[]): global rgb, keep_running, points_set, using_depth, shots, taken, stop, note if len(argv) > 1: shots = int(argv[1]) cv.NamedWindow("Calibrate") print('Press Esc or Q in window to stop') freenect.runloop(depth=None, video=handle_rgb, body=body) if stop: return keep_running = True using_depth = True taken = 0 freenect.runloop(depth=None, video=handle_rgb, body=body, vmode=freenect.VIDEO_IR_8BIT) if stop: return note = "Calculating the camera matrices..." showrgb() rgb_cm, rgb_d, depth_cm, depth_d, R, t = calibrate() cv.Save("matrices/rgb_cm.xml", rgb_cm) cv.Save("matrices/rgb_d.xml", rgb_d) cv.Save("matrices/depth_cm.xml", depth_cm) cv.Save("matrices/depth_d.xml", depth_d) cv.Save("matrices/Rotation.xml", R) cv.Save("matrices/translation.xml", t) note = "Found the camera matrices. Press any key to exit." showrgb() cv.WaitKey(0)
def main(): global rgb, keep_running, points_set, using_depth cv.NamedWindow("Calibrate") cv.SetMouseCallback("Calibrate", mouseclicked, None) print('Press ESC in window to stop') freenect.runloop(depth=None, video=display_rgb, body=body) while not points_set: try: showrgb() key = (cv.WaitKey(10)) % 0x100 if key < 255: keypressed(key) except freenect.Kill: return keep_running = True points_set = False using_depth = True print('Press ESC in window to stop') freenect.runloop(depth=None, video=display_rgb, body=body, vmode=freenect.VIDEO_IR_8BIT) while not points_set: try: showrgb() key = (cv.WaitKey(10)) % 0x100 if key < 255: keypressed(key) except freenect.Kill: return
def main(input_arg): if not (input_arg.img_src == "w" or input_arg.img_src == "k"): rospy.loginfo("You can only use kinect or a webcam") os._exit() if input_arg.img_src == "w": cam = cv2.VideoCapture(1) # change int to corresponding camera number else: import freenect rospy.init_node("cam_rgb_pub") ic = ImagePublisher(input_arg) rate = rospy.Rate(30) try: while not rospy.is_shutdown(): if input_arg.img_src == "w": ic.get_rgb(input_arg, cam) else: freenect.runloop(video=ic.get_rgb(input_arg), body=ic.body(input_arg)) rate.sleep() except KeyboardInterrupt: print("shutting down ros")
if self.nightvision: cv_data = simplify_cv(data) else: cv_data = video_cv(data) if self.debug: cv.ShowImage('Video', cv_data) if (self._last_img + self.snapshot_secs < time.time() or self._snapshot): cv.SaveImage('babby-current.jpg', cv_data) k = boto.s3.key.Key(self.s3bucket) if self._snapshot: k.key = '/babby/snapshot-%s.jpg' % self._snapshot self._snapshot = False else: k.key = '/babby/current.jpg' k.set_contents_from_filename('babby-current.jpg') k.set_acl('public-read') self._last_img = time.time() if __name__ == '__main__': cv.NamedWindow('Video') cv.NamedWindow('Depth') watcher = Watcher() freenect.runloop(depth=watcher.depth_callback, video=watcher.video_callback, body=watcher.body_callback)
def video_kin(dev, video, timestamp): global run print timestamp cv.ShowImage('RGB', cv.fromarray(video)) cv.WaitKey(10) freenect.runloop(video=video_kin)
def startloop(server): freenect.runloop(depth=createdepthhandler(server))
rgb_time = time.time() def log_dep(dev, data, timestamp): global rgb_data, dep_data, frame_number, rgb_time data = frame_convert.pretty_depth(data)[:,:,None] dep_data.append( data ) rgb_data.append( rgb_temp ) frame_number += 1 print "Writing frame", frame_number, print "\tColor data is %ims stale" % ((time.time() - rgb_time)*1000) def log_rgb(dev, data, timestamp): global rgb_temp, time, rgb_time rgb_temp = data[:,:,:,None] rgb_time = time.time() def body(*args): if not keep_running: raise freenect.Kill def handler(signum, frame): global keep_running keep_running = False print('Press Ctrl-C in terminal to stop') signal.signal(signal.SIGINT, handler) freenect.runloop(depth=log_dep, video=log_rgb, body=body)
last_time = 0 def body(dev, ctx): global last_time if not keep_running: raise freenect.Kill if time.time() - last_time < 3: return print "boop" last_time = time.time() led = random.randint(0, 6) tilt = random.randint(0, 30) print "set_led(%s)" % led freenect.set_led(dev, led) print "set_tilt_degs(%s)" % tilt freenect.set_tilt_degs(dev, tilt) print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev))) def fake_display(dev, data, timestamp): return def handler(signum, frame): """Sets up the kill handler, catches SIGINT""" global keep_running keep_running = False #print('Press Ctrl-C in terminal to stop') #signal.signal(signal.SIGINT, handler) freenect.runloop(body=body, depth=fake_display, video=fake_display)
# v.playVideo("videos/buenos/bienvenida.mpg") break if ((puntoR1 > 0.0) or (puntoR2 > 0.0)): print "Robots" # v.playVideo("videos/buenos/moviles.mpg") break elif ( (radius > dist1) and (radius < dist2) and (radius > dist3)and (radius < dist4)): if ((punto8 > 0.0) and (punto13 > 0.0) and (punto10 < 0.0) and (punto14 > 0.0) ): print "redes" # v.playVideo("videos/buenos/rna.mpg") break if ((punto8 < 0.0) and (punto14 < 0.0) and (punto10 > 0.0) and (punto11 > 0.0)): print "Banda" # v.playVideo("videos/buenos/banda.mpg") break cv2.imshow('Original', original) #cv2.createTrackbar('threshold', 'Original', threshold, 500, change_threshold) #cv2.createTrackbar('depth', 'Original', current_depth, 2048, change_depth) #cv2.createTrackbar('tilt', 'Original', 0, 30, change_tilt) def main(dev, ctx): freenect.set_tilt_degs(dev, tilt) if __name__ == '__main__': freenect.runloop(depth=show_depth, body=main)
def run(self): freenect.runloop(body=self.body, depth=createdepthhandler(self.server))
import random import signal keep_running = True last_time = 0 def body(dev, ctx): global last_time if not keep_running: raise freenect.Kill if time.time() - last_time < 3: return last_time = time.time() led = random.randint(0, 6) tilt = random.randint(0, 30) freenect.set_led(dev, led) freenect.set_tilt_degs(dev, tilt) print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev))) def handler(signum, frame): """Sets up the kill handler, catches SIGINT""" global keep_running keep_running = False print('Press Ctrl-C in terminal to stop') signal.signal(signal.SIGINT, handler) freenect.runloop(body=body)
#!/usr/bin/env python import freenect import cv import numpy as np cv.NamedWindow('Depth') def display(dev, data, timestamp): data -= np.min(data.ravel()) data *= 65536 / np.max(data.ravel()) image = cv.CreateImageHeader((data.shape[1], data.shape[0]), cv.IPL_DEPTH_16U, 1) cv.SetData(image, data.tostring(), data.dtype.itemsize * data.shape[1]) cv.ShowImage('Depth', image) cv.WaitKey(5) freenect.runloop(depth=lambda *x: display(*freenect.depth_cb_np(*x)))
import cv import numpy as np cv.NamedWindow('Depth') cv.NamedWindow('RGB') def display_depth(dev, data, timestamp): data -= np.min(data.ravel()) data *= 65536 / np.max(data.ravel()) image = cv.CreateImageHeader((data.shape[1], data.shape[0]), cv.IPL_DEPTH_16U, 1) cv.SetData(image, data.tostring(), data.dtype.itemsize * data.shape[1]) cv.ShowImage('Depth', image) cv.WaitKey(5) def display_rgb(dev, data, timestamp): image = cv.CreateImageHeader((data.shape[1], data.shape[0]), cv.IPL_DEPTH_8U, 3) # Note: We swap from RGB to BGR here cv.SetData(image, data[:, :, ::-1].tostring(), data.dtype.itemsize * 3 * data.shape[1]) cv.ShowImage('RGB', image) cv.WaitKey(5) freenect.runloop(depth=lambda *x: display_depth(*freenect.depth_cb_np(*x)), rgb=lambda *x: display_rgb(*freenect.rgb_cb_np(*x)))
import threading import random dev = None def tilt_and_sense(): global dev while not dev: time.sleep(1) while 1: time.sleep(3) led = random.randint(0, 6) tilt = random.randint(0, 30) print('Led[%d] Tilt[%d]' % (led, tilt)) freenect.set_led(dev, led) freenect.set_tilt_degs(dev, tilt) print(freenect.raw_accel(dev)) print(freenect.mks_accel(dev)) threading.Thread(target=tilt_and_sense).start() def dev_getter(my_dev, *_): global dev dev = my_dev freenect.runloop(depth=lambda *x: dev_getter(*freenect.depth_cb_np(*x)))
def run(self): freenect.runloop(body=self.body, depth=self.depth_handler)
#!/usr/bin/env python import freenect from demo_mp_depth_show import display freenect.runloop(rgb=lambda *x: display(*freenect.rgb_cb_np(*x)))
#!/usr/bin/env python import freenect import matplotlib.pyplot as mp mp.ion() image = None def display(dev, data, timestamp): global image if image: image.set_data(data) else: image = mp.imshow(data, interpolation='nearest', animated=True) mp.draw() if __name__ == '__main__': freenect.runloop(depth=lambda *x: display(*freenect.depth_cb_np(*x)))
if image_depth: image_depth.set_data(data) else: image_depth = mp.imshow(data, interpolation="nearest", animated=True) mp.draw() def display_rgb(dev, data, timestamp): global image_rgb mp.figure(2) if image_rgb: image_rgb.set_data(data) else: image_rgb = mp.imshow(data, interpolation="nearest", animated=True) mp.draw() def body(*args): if not keep_running: raise freenect.Kill def handler(signum, frame): global keep_running keep_running = False print("Press Ctrl-C in terminal to stop") signal.signal(signal.SIGINT, handler) freenect.runloop(depth=display_depth, video=display_rgb, body=body)
#!/usr/bin/env python import freenect import cv2 import frame_convert2 cv2.namedWindow('RGB') keep_running = True def body(dev, ctx): if not keep_running: raise freenect.Kill def display_rgb(dev, data, timestamp): global keep_running print frame_convert2.video_cv(data) c = cv2.waitKey(10) if 'q' == chr(c & 255): keep_running = False if 's' == chr(c & 255): cv2.imwrite("saved1.jpg", frame_convert2.video_cv(data)) print('Press q in window to stop') print('Press s in window to save a camera shot') freenect.runloop(video=display_rgb, body=body)
# Convert to HSV colourspace frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) # find the Hue, Saturation, Value components of the frame CH_H, CH_S, CH_V = cv2.split(frame) if cv2.waitKey(10) == 27: # find Hue value of middle pixel pxl_H = CH_H[int(frame.shape[0] / 2), int(frame.shape[1] / 2)] # find Saturation value of middle pixel pxl_S = CH_S[int(frame.shape[0] / 2), int(frame.shape[1] / 2)] # find intensity value of middle pixel pxl_V = CH_V[int(frame.shape[0] / 2), int(frame.shape[1] / 2)] cv2.imwrite("measure_hsv.jpg", _target) print("Hue", pxl_H) print("Saturation", pxl_S) print("Intensity", pxl_V) keep_running = False def body(*args): if not keep_running: raise freenect.Kill print('Press ESC in window to stop') freenect.runloop(depth=depth, video=rgb, body=body)
screen.fill(BLACK) #Make the window black pygame.draw.circle(screen,(255,min(255,max(0,255*(1000.0-final_z)/500)),0),(final_xy[0],final_xy[1]),10) if center_set: paint_controller(center_xy) if active_area: pygame.draw.circle(screen,YELLOW,(old_xy[0],old_xy[1]),active_area_limit,2) if exclusion_zone: pygame.draw.circle(screen,RED,(exclusion_xy[0],exclusion_xy[1]),exclusion_zone_limit,2) font = pygame.font.Font(None, 48) if hold_it: ftext=actions[action_set][action_num]+"! Holding for "+str((rightnow-hold_it_start).seconds)+" / "+str(hold_it_limit.seconds) elif center_set: ftext="Set for "+str((rightnow-action_less_start).seconds)+" / "+str(action_less_limit.seconds)+" "+str(int(rel_xy[0]))+" / "+str(r_medium) elif trying_to_set_center: ftext="Trying for "+str((rightnow-setting_center_start).seconds)+" / "+str(center_setting_limit.seconds) else: ftext="Searching..." text = font.render(ftext,1,YELLOW) screen.blit(text, (20,20)) screen.blit(screen,(0,0)) #Updates the main screen --> screen pygame.display.flip() #Updates everything on the window for e in pygame.event.get(): #Iterates through current events if e.type is pygame.QUIT: #If the close button is pressed, the while loop ends raise freenect.Kill freenect.runloop(depth=process_depth, body=body)
keep_running = False def display_rgb(dev, data, timestamp): global keep_running data = data[:, :, ::-1] # RGB -> BGR cv2.imshow('RGB', data) if cv2.waitKey(10) == 27: keep_running = False def body(*args): if not keep_running: raise freenect.Kill cv2.destroyAllWindows() print('Press ESC in window to stop') ctx = freenect.init() devPtr = freenect.open_device(ctx, 0) #freenect.set_video_mode(devPtr, freenect.VIDEO_IR_8BIT, freenect.RESOLUTION_MEDIUM) #ir, data = freenect.sync_get_video(format=freenect.VIDEO_IR_8BIT) #print ir #print data freenect.runloop(depth=display_depth, video=display_rgb, body=body, dev=devPtr )
def video_kin(dev,video, timestamp): global run print timestamp cv.ShowImage('RGB',cv.fromarray(video)) cv.WaitKey(10) freenect.runloop(video=video_kin)
if df[j, i] > df_lim: try: l = points.pop() l.remove() except IndexError: pass new_l = plt.plot(i, j, 'ro', ms=20) points.extend(new_l) #print('*'*40) plt.draw() return return depth def body(*args): if not keep_running: raise freenect.Kill def handler(signum, frame): global keep_running keep_running = False print('Press Ctrl-C in terminal to stop') signal.signal(signal.SIGINT, handler) freenect.runloop(depth=get_depth(), body=body)
#!/usr/bin/env python import freenect import rospy import cv2 import matplotlib.pyplot as plt import numpy as np mdev = freenect.open_device(freenect.init(), 0) freenect.set_depth_mode(mdev, freenect.RESOLUTION_HIGH, freenect.DEPTH_REGISTERED) # freenect.runloop(dev=mdev) def display_depth(dev, data, timestamp): d = np.array(data.copy()) # with open('depth_'+str(timestamp)+'.npy', 'w+') as f: # np.save(f, d, allow_pickle=True) d[d > 2000] = np.mean(d[d < 2000].flatten()) plt.imshow(d) plt.show() # if cv2.WaitKey(10) == 27: # keep_running = False # d = freenect.sync_get_depth()[0] freenect.runloop(dev=mdev, depth=display_depth) # plt.imshow(d, interpolation='nearest') # plt.show()
#!/usr/bin/env python import freenect import cv cv.NamedWindow('RGB') def display(dev, data, timestamp): image = cv.CreateImageHeader((data.shape[1], data.shape[0]), cv.IPL_DEPTH_8U, 3) # Note: We swap from RGB to BGR here cv.SetData(image, data[:, :, ::-1].tostring(), data.dtype.itemsize * 3 * data.shape[1]) cv.ShowImage('RGB', image) cv.WaitKey(5) freenect.runloop(rgb=lambda *x: display(*freenect.rgb_cb_np(*x)))
print(".") global i, working if not working: working = True depths[i] = depth filtered_depth = np.median(depths, axis=0) pointclouds.append(point_cloud(filtered_depth)) timestamps.append(timestamp) i += 1 i = i % n working = False if __name__ == "__main__": parser = OptionParser() parser.add_option("-o", "--output", dest="output", help="Output data in .npz format to OUTPUTFILE", metavar="OUTPUTFILE") (options, args) = parser.parse_args() context = freenect.init() device = freenect.open_device(context, 0) freenect.set_depth_mode(device, freenect.RESOLUTION_MEDIUM, freenect.DEPTH_MM) try: print("Capturing...") freenect.runloop(dev=device, depth=depth_callback) except KeyboardInterrupt: if options.output: print("Dumping...") np.savez_compressed(options.output, tangoPointclouds=pointclouds, tangoPointcloudTimestamps=timestamps)
global keep_running #result = draw_canny(data) data = frame_convert2.video_cv(data) result = data.copy() t_end = datetime.datetime.now() t_delta = t_end - t_start cv2.putText(result, str(1000000/t_delta.microseconds), (0, 25), cv2.FONT_HERSHEY_PLAIN, 2, (127, 0, 0), 2) cv2.imshow('RGB', result) if cv2.waitKey(10) == 27: keep_running = False def body(*args): if not keep_running: raise freenect.Kill print('Press ESC in window to stop') freenect.runloop(depth=display_depth, video=display_rgb, body=body) """freenect.runloop(depth=None, video=display_rgb, body=body)"""
# raise freenect.Kill if has_warned: return if latest_rgb is None: return latest_depth = data if not is_too_close(latest_rgb, latest_depth): return warn_to_son() #has_warned = True #np.save('np_depth.npy', latest_depth) #np.save('np_rgb.npy', latest_rgb) #keep_running = False def process_rgb(dev, data, timestamp): global latest_rgb latest_rgb = data def body(*args): if not keep_running: raise freenect.Kill print('Press ESC in window to stop') freenect.runloop(depth=process_depth, video=process_rgb, body=body)
keep_running = True img = 0 def capture(dev, data, timestamp): global keep_running global img img = frame_convert.video_cv(data) keep_running = False def endCapture(*args): if not keep_running: raise freenect.Kill freenect.runloop(video=capture, body=endCapture) ###################ALGORITHM START########################################### cv.SaveImage("tmp.png", img) #better solution? img = cv.LoadImage("tmp.png", cv.CV_LOAD_IMAGE_GRAYSCALE) ################# #cv.CvtColor( img, img, cv.CV_RGB2GRAY ); eig_image = cv.CreateMat(img.height, img.width, cv.CV_32FC1) temp_image = cv.CreateMat(img.height, img.width, cv.CV_32FC1) lx = 0 ly = 0 i = 1 totalx = 0 for (x,y) in cv.GoodFeaturesToTrack(img, eig_image, temp_image, 16, 0.04, 5.0, blockSize = 25 ,useHarris = True): #print "good feature at", x,y c = cv.Scalar(255) cv.Rectangle(img, (x-8, y-8), (x+8, y+8), c)
import freenect import time import random import signal keep_running = True last_time = 0 def body(dev, ctx): global last_time if not keep_running: raise freenect.Kill if time.time() - last_time < 3: return last_time = time.time() led = random.randint(0, 6) tilt = random.randint(0, 30) freenect.set_led(dev, led) freenect.set_tilt_degs(dev, tilt) print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev))) def handler(signum, frame): """Sets up the kill handler, catches SIGINT""" global keep_running keep_running = False print('Press Ctrl-C in terminal to stop') signal.signal(signal.SIGINT, handler) freenect.runloop(body=body)