Ejemplo n.º 1
0
def doloop():
    global depth, rgb
    while True:
        # Get a fresh frame
        (depth, _), (rgb, _) = sync_get_depth(), sync_get_rgb()

        # Build a two panel color image
        d3 = np.dstack((depth, depth, depth)).astype(np.uint8)
        da = np.hstack((d3, rgb))

        # Simple Downsample
        cv.ShowImage("both", np.array(da[::2, ::2, ::-1]))
        cv.WaitKey(5)
Ejemplo n.º 2
0
def doloop():
    global depth, rgb
    while True:
        # Get a fresh frame
        (depth, _), (rgb, _) = sync_get_depth(), sync_get_rgb()

        # Build a two panel color image
        d3 = np.dstack((depth, depth, depth)).astype(np.uint8)
        da = np.hstack((d3, rgb))

        # Simple Downsample
        cv.ShowImage('both', np.array(da[::2, ::2, ::-1]))
        cv.WaitKey(5)
Ejemplo n.º 3
0
def DrawPointCloud():
    global CloudSample, CloudPointSize
    #Camera Position/Orient
    glTranslatef(CameraPos[0] / 2, CameraPos[1] / 2, -CameraPos[2] / 2)
    glRotatef(-CameraRotate[1], 1, 0, 0)
    glRotatef(-CameraRotate[0], 0, 1, 0)

    DrawBlocks()

    #get the kinecty goodness
    depth, tstamp = freenect.sync_get_depth()
    rgb, tstamp = freenect.sync_get_rgb()
    X, Y = np.meshgrid(range(640), range(480))
    #downsample size
    dd = CloudSample
    pointsize = CloudPointSize
    q = depth

    #to the cloud!
    projpts = project(q[::dd, ::dd], X[::dd, ::dd], Y[::dd, ::dd])
    xyz, uv = projpts

    #use the rgb for texture
    if not rgb is None:
        rgb_ = (rgb.astype(np.float32) * 4 + 70).clip(200,
                                                      255).astype(np.uint8)
        glBindTexture(TEXTURE_TARGET, rgbtex)
        glTexSubImage2D(TEXTURE_TARGET, 0, 0, 0, 640, 480, GL_RGB,
                        GL_UNSIGNED_BYTE, rgb_)

    # Draw the points from the kinect
    glPointSize(pointsize)
    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_TEXTURE_COORD_ARRAY)
    glVertexPointerf(xyz)
    glTexCoordPointerf(uv)
    glEnable(TEXTURE_TARGET)
    glColor3f(1, 1, 1)
    glDrawElementsui(GL_POINTS, np.array(range(len(xyz))))
    #sys.stdout.write("xyz length: " + str(len(xyz)) + '\n')
    #sys.stdout.write("uv length:" + str(len(uv)) +'\n')
    glDisableClientState(GL_VERTEX_ARRAY)
    glDisableClientState(GL_TEXTURE_COORD_ARRAY)
    glDisable(TEXTURE_TARGET)
Ejemplo n.º 4
0
def DrawPointCloud():
    global CloudSample,CloudPointSize
    #Camera Position/Orient
    glTranslatef(CameraPos[0]/2,CameraPos[1]/2,-CameraPos[2]/2)
    glRotatef(-CameraRotate[1],1,0,0)
    glRotatef(-CameraRotate[0],0,1,0)        

    DrawBlocks()
    
    #get the kinecty goodness
    depth,tstamp=freenect.sync_get_depth()
    rgb, tstamp=freenect.sync_get_rgb()
    X,Y = np.meshgrid(range(640),range(480))
    #downsample size
    dd=CloudSample
    pointsize=CloudPointSize
    q=depth

    #to the cloud!
    projpts = project(q[::dd,::dd],X[::dd,::dd],Y[::dd,::dd])        
    xyz, uv = projpts    
    
    #use the rgb for texture
    if not rgb is None:
        rgb_ = (rgb.astype(np.float32) * 4 + 70).clip(200,255).astype(np.uint8)
        glBindTexture(TEXTURE_TARGET, rgbtex)
        glTexSubImage2D(TEXTURE_TARGET, 0, 0, 0, 640, 480, GL_RGB, GL_UNSIGNED_BYTE, rgb_);    

    # Draw the points from the kinect
    glPointSize(pointsize)
    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_TEXTURE_COORD_ARRAY)
    glVertexPointerf(xyz)
    glTexCoordPointerf(uv)
    glEnable(TEXTURE_TARGET)
    glColor3f(1,1,1)
    glDrawElementsui(GL_POINTS, np.array(range(len(xyz))))
    #sys.stdout.write("xyz length: " + str(len(xyz)) + '\n')
    #sys.stdout.write("uv length:" + str(len(uv)) +'\n')
    glDisableClientState(GL_VERTEX_ARRAY)
    glDisableClientState(GL_TEXTURE_COORD_ARRAY)
    glDisable(TEXTURE_TARGET)    
Ejemplo n.º 5
0
def main():
	pygame.init()
	cv.NamedWindow('Depth')
	screen = pygame.display.set_mode((480,640))
	pygame.display.set_caption("Shoot")
	clock = pygame.time.Clock()
	x, y = 0, 0
	running = True
	load = True
	shoot = False
	change = False
	ball_load = True
	while running:
		depth, _ = freenect.sync_get_depth()
		rgb, _ = freenect.sync_get_rgb()
		
		if load :
			bullet = load_bullet()
			bullet_rect = bullet.get_rect()
			load = False
		
		if ball_load :
			ball = load_ball()
			ball_rect = ball.get_rect()
			y_axis = random.randrange(20, 610)
			ball_rect.move_ip(430, y_axis)
			ball_load = False
		
		if depth[240, 20] > 2000 :
			shoot = True
			change = True
		elif depth[470, 520] > 1800 :
			x, y = 0, 5
			change = True
		elif depth[20, 620] > 1700 :
			x, y = 0, -5
			change = True
	
		for event in pygame.event.get() :
			if event.type == QUIT:
				running = False
			elif event.type == KEYDOWN and event.key == K_ESCAPE:
				running = False
			elif event.type == KEYDOWN and event.key == K_UP:
				x, y = 0, -5
			elif event.type == KEYDOWN and event.key == K_DOWN:
				x, y = 0, 5
			elif event.type == KEYDOWN  and event.key == K_RIGHT:
				shoot = True

			bullet_rect.move_ip(x, y)
			screen.fill(THECOLORS['white'])
			screen.blit(bullet, bullet_rect)
			screen.blit(ball, ball_rect)
		

		if change :
			bullet_rect.move_ip(x, y)
			screen.fill(THECOLORS['white'])
			screen.blit(bullet, bullet_rect)
			screen.blit(ball, ball_rect)
			change = False

		if shoot :
			x, y = 10, 0
			bullet_rect.move_ip(x, y)
			screen.fill(THECOLORS['white'])
			screen.blit(bullet, bullet_rect)
			screen.blit(ball, ball_rect)
			if bullet_rect.x > 430 and bullet_rect.y < y_axis+30 and bullet_rect.y > y_axis-30:
				ball_rect.move_ip(x,y)
				screen.fill(THECOLORS['white'])
				screen.blit(ball, ball_rect)
				del(ball)
				del(bullet)
				screen.fill(THECOLORS['white'])
				load = True
				shoot = False
				ball_load = True
			elif bullet_rect.x > 480 :
				del(bullet)
				load = True
				shoot = False
				ball_load = False
							
				
		pygame.display.update()		
		pygame.display.flip()
		clock.tick(50)
		cv.ShowImage('Depth', depth.astype(np.uint8))
		cv.WaitKey(10)
Ejemplo n.º 6
0
cv.NamedWindow('Depth')
pygame.init()
screen = pygame.display.set_mode((480,640))
pygame.display.set_caption("Shoot")
clock = pygame.time.Clock()
bullet = pygame.image.load(os.path.join('data','bullet.png'))
bullet2 = pygame.image.load(os.path.join('data','bullet.png'))
chimp = pygame.image.load(os.path.join('data','chimp.jpg'))
bullet_rect = bullet.get_rect()
bullet2_rect = bullet2.get_rect()
bullet2_rect.move_ip(240,320)
angle = 0

while 1:
	depth, timestamp = freenect.sync_get_depth()
	rgb, timestamp = freenect.sync_get_rgb()
#	final = np.zeros((480,640,3), dtype=np.uint8)	
#	for i in xrange(120, 360, 2):
#		for j in xrange(160, 480, 2):
#			if depth[i,j] > 1400:
#				final[i,j]  = rgb[i,j]
	if depth[440,620] > 2000 :
		angle = 180
		bullet_rect.move_ip([sin((angle+90)*0.0174)*9, cos((angle+90)*0.0174)*9])
	elif depth[440, 20] > 2000 :
		angle = 270
		bullet_rect.move_ip([sin((angle+90)*0.0174)*9, cos((angle+90)*0.0174)*9])
	elif depth[20, 620] > 2000 :
		angle = 0
		bullet_rect.move_ip([sin((angle+90)*0.0174)*9, cos((angle+90)*0.0174)*9])
	elif depth[20, 20] > 2000 :
Ejemplo n.º 7
0
def get_video():
	return freenect.sync_get_rgb()[0][120:360, 160:480]
Ejemplo n.º 8
0
#!/usr/bin/env python
import freenect
import matplotlib.pyplot as mp

mp.ion()
mp.figure(1)
image_depth = mp.imshow(freenect.sync_get_depth()[0], interpolation='nearest', animated=True)
mp.figure(2)
image_rgb = mp.imshow(freenect.sync_get_rgb()[0], interpolation='nearest', animated=True)

while 1:
    mp.figure(1)
    image_depth.set_data(freenect.sync_get_depth()[0])
    mp.figure(2)
    image_rgb.set_data(freenect.sync_get_rgb()[0])
    mp.draw()
Ejemplo n.º 9
0
#!/usr/bin/env python
import freenect
import matplotlib.pyplot as mp

mp.ion()
mp.figure(1)
image_depth = mp.imshow(freenect.sync_get_depth()[0],
                        interpolation='nearest',
                        animated=True)
mp.figure(2)
image_rgb = mp.imshow(freenect.sync_get_rgb()[0],
                      interpolation='nearest',
                      animated=True)

while 1:
    mp.figure(1)
    image_depth.set_data(freenect.sync_get_depth()[0])
    mp.figure(2)
    image_rgb.set_data(freenect.sync_get_rgb()[0])
    mp.draw()
Ejemplo n.º 10
0
#!/usr/bin/env python
import freenect
import cv
import numpy as np

cv.NamedWindow('Depth')
cv.NamedWindow('RGB')

while 1:
    depth, timestamp = freenect.sync_get_depth()
    rgb, timestamp = freenect.sync_get_rgb()
    cv.ShowImage('Depth', depth.astype(np.uint8))
    cv.ShowImage('RGB', rgb.astype(np.uint8))
    cv.WaitKey(10)