def captureImage(): global captureSoundSeq if (captureSoundSeq == 1): sdInit.play() if (captureSoundSeq == 2): sdConf.play() if (captureSoundSeq == 3): sdBegin.play() captureSoundSeq = captureSoundSeq + 1 if (captureSoundSeq > 3): captureSoundSeq = 1 camera = pygame.camera.Camera(DEVICE, (800, 480), "RGB") camera.start() sleep(.25) camGrab = camera.get_image() #create a new animation canvas animFrame = pygame.Surface(lastScreen.get_size()) animFrame = animFrame.convert() pygame.draw.rect(animFrame, (0, 0, 0), (0, 0, 800, 480)) lastScreen.blit(animFrame, (0, 0)) capture = True camGrab = pygame.transform.flip(camGrab, False, True) while capture: if camera.query_image(): captureSurface = camera.get_image() # flipping image captureSurface = pygame.transform.flip(captureSurface, False, True) display.blit(captureSurface, (0, 0)) pygame.display.flip() if shutterButton.is_pressed: pygame.image.save(display, ("CapturedImages/" + photoFileName)) shutterSound.play() flashFrame = pygame.Surface(lastScreen.get_size()) flashFrame = flashFrame.convert() pygame.draw.rect(display, (255, 255, 255), (0, 0, 800, 480)) pygame.display.flip() sleep(.25) capture = False for event in pygame.event.get(): if event.type == QUIT: pygame.quit() appRunning = False break if event.type == KEYDOWN: if event.key == K_ESCAPE: pygame.quit() appRunning = False break camera.stop() return
def camstream(): pygame.init() clock = pygame.time.Clock() pygame.camera.init() pprint.pprint(pygame.camera.list_cameras()) display = pygame.display.set_mode(screen_size, pygame.FULLSCREEN) camera = pygame.camera.Camera(DEVICE, camera_size) camera.start() actual_camera_size = camera.get_size() pprint.pprint(actual_camera_size) screen = pygame.surface.Surface(screen_size, 0, display) frame = pygame.surface.Surface(camera_size, 0, display) detect = pygame.surface.Surface(detect_size, 0, display) capture = True while capture: for event in pygame.event.get(): if event.type == KEYDOWN: if event.key == K_s: capture = False elif event.type == KEYDOWN: if event.key == K_s: pygame.image.save(screen, FILENAME) elif event.key == K_q: capture = False if camera.query_image(): camera.get_image(frame) pygame.transform.scale(frame, screen_size, screen) pygame.transform.flip(screen, True, False) # make a rect in the middle of the screen capture_rect = pygame.draw.rect(screen, (255, 255, 255), (390, 230, 20, 20), 1) # get the average color of the area inside the rect capture_colour = pygame.transform.average_color( screen, capture_rect) pygame.transform.scale(screen, detect_size, detect) pygame.transform.laplacian(detect, detect) # pygame.transform.threshold(detect, capture_colour, (90, 170, 170), (0, 0, 0), 2) display.blit(screen, (0, 0)) # fill the upper left corner with that color display.fill(capture_colour, (0, 0, 24, 24)) display.blit(detect, detect_origin) pygame.display.flip() dt = clock.tick(10) camera.stop() pygame.quit() return
time.sleep(2) #To save video file #path = ('/home/pi/Documents/Obje.avi') #fourcc = cv2.VideoWriter_fourcc(*'XVID') #video_writer = cv2.VideoWriter(path,-1, 1, (160,128), True) # if not video_writer : # print ("!!! Failed VideoWriter: invalid parameters") # sys.exit(1) #camera.start_recording('/home/pi/Documents/Obje.h264') while on: start = datetime.now() if camera.query_image(): snapshot = camera.get_image() snapshot1 = pygame.transform.scale(snapshot, resolution) frame = pygame.surfarray.pixels3d( pygame.transform.rotate( pygame.transform.flip(snapshot1, True, False), 90)) if image_d == 1: frame = rgb2gray(frame) #for frame1 in camera.capture_continuous(rawCapture, format="bgr",use_video_port=True): t1 = cv2.getTickCount() # Acquire frame and expand frame dimensions to have shape: [1, None, None, 3] # i.e. a single-column array, where each item in the column has the pixel RGB value # frame = frame1.array
from cvEyeTrack import Draw_Cross print("Imported pygame, numpy, opencv and cvEyeTracking lib") raw_input("Press Enter to capture an image (in pygame)") pygame.init() pygame.camera.init() size = width,height = 640,480 display = pygame.display.set_mode(size,0) camList = pygame.camera.list_cameras() # TODO: err if none found camera = pygame.camera.Camera(camList[0],size,"RGB") camera.start() for i in range(100): if camera.query_image(): # ready to take an image? break snapshot = camera.get_image() camera.stop() display.blit(snapshot,(0,0,)) pygame.display.flip() pygame.display.flip() print("Captured an image") raw_input("Press Enter to convert into opencv format") npy = surfarray.pixels3d(snapshot) ipl = adaptors.NumPy2Ipl(npy)
from pygame import surfarray from cvEyeTrack import Draw_Cross print("Imported pygame, numpy, opencv and cvEyeTracking lib") raw_input("Press Enter to capture an image (in pygame)") pygame.init() pygame.camera.init() size = width, height = 640, 480 display = pygame.display.set_mode(size, 0) camList = pygame.camera.list_cameras() # TODO: err if none found camera = pygame.camera.Camera(camList[0], size, "RGB") camera.start() for i in range(100): if camera.query_image(): # ready to take an image? break snapshot = camera.get_image() camera.stop() display.blit(snapshot, ( 0, 0, )) pygame.display.flip() pygame.display.flip() print("Captured an image") raw_input("Press Enter to convert into opencv format") npy = surfarray.pixels3d(snapshot)
def captureImage(): global captureSoundSeq if (captureSoundSeq == 1): sdInit.play() if (captureSoundSeq == 2): sdConf.play() if (captureSoundSeq == 3): sdBegin.play() captureSoundSeq = captureSoundSeq + 1 if (captureSoundSeq > 3): captureSoundSeq = 1 camera = pygame.camera.Camera(DEVICE, (800, 480), "RGB") camera.start() sleep(.25) camGrab = camera.get_image() #create a new animation canvas animFrame = pygame.Surface(lastScreen.get_size()) animFrame = animFrame.convert() pygame.draw.rect(animFrame, (0, 0, 0), (0, 0, 800, 480)) lastScreen.blit(animFrame, (0, 0)) capture = True camGrab = pygame.transform.flip(camGrab, False, True) # ------- REVEAL CAMERA ## ## if camera.query_image(): ## camGrab = camera.get_image() ## camGrab = pygame.transform.flip(camGrab, True, False) # ---------------------- Replace smiley face with cam shot # ---------------------- Open black bars while capture: if camera.query_image(): captureSurface = camera.get_image() # flipping captureSurface = pygame.transform.flip(captureSurface, False, True) ## screenArray = pygame.surfarray.pixels3d( captureSurface ) ## screenArray[:,::7] = (0, 0, 0) # add horiz lines every N pixels down ## for xpx in range(0,5): ## vertscanline=random.randint(0,445) ## pygame.draw.line(captureSurface, (255,255,255), (0,vertscanline), (800,vertscanline),1) #Scanlines ## pygame.draw.rect(captureSurface, (255,255,255), (random.randint(-800,800),random.randint(-480,480), random.randint(0,800),2)) #Mosaic1 ## thresholded = pygame.surface.Surface((800,480), 0, display) ## pygame.transform.threshold(thresholded,captureSurface,(255,255,255),(90,170,170),(0,0,0),2, thresholded, True) ## del screenArray ## ## #update image in memory and reresh it to display ## ## display.blit(thresholded, (0,0)) ## pygame.display.flip() display.blit(captureSurface, (0, 0)) pygame.display.flip() if shutterButton.is_pressed: pygame.image.save(display, ("CapturedImages/" + photoFileName)) shutterSound.play() flashFrame = pygame.Surface(lastScreen.get_size()) flashFrame = flashFrame.convert() pygame.draw.rect(display, (255, 255, 255), (0, 0, 800, 480)) pygame.display.flip() sleep(.25) capture = False for event in pygame.event.get(): if event.type == QUIT: pygame.quit() appRunning = False break if event.type == KEYDOWN: if event.key == K_ESCAPE: pygame.quit() appRunning = False break camera.stop() return
#log# args = ['drawCross.py'] #log# It is safe to make manual edits below here. #log#----------------------------------------------------------------------- _ip.magic("logstart ") import pygame import pygame.camera from pygame.locals import * import numpy pygame.init() pygame.camera.init() size = width,height = 640,480 display = pygame.display.set_mode(size,0) camList = pygame.camera.list_cameras() # TODO: err if none found camera = pygame.camera.Camera(camList[0],size,"RGB") # starting in RGB mode - this means frame comes in size (640,480,3) (1MB each?) camera.start() camera.query_image() # ready to take an image? snapshot = camera.get_image() camera.stop() display.blit(snapshot,(0,0,)) pygame.display.flip() pygame.display.flip() import opencv from pygame import surfarray npy = surfarray.pixels3d(snapshot) ipl = opencv.adaptors.NumPy2Ipl(npy) import CvEyeTrack import vEyeTrack import cvEyeTrack from cvEyeTrack import Draw_Cross #?Draw_Cross green = opencv.CV_RGB(0,255,0)
#log#----------------------------------------------------------------------- _ip.magic("logstart ") import pygame import pygame.camera from pygame.locals import * import numpy pygame.init() pygame.camera.init() size = width, height = 640, 480 display = pygame.display.set_mode(size, 0) camList = pygame.camera.list_cameras() # TODO: err if none found camera = pygame.camera.Camera( camList[0], size, "RGB" ) # starting in RGB mode - this means frame comes in size (640,480,3) (1MB each?) camera.start() camera.query_image() # ready to take an image? snapshot = camera.get_image() camera.stop() display.blit(snapshot, ( 0, 0, )) pygame.display.flip() pygame.display.flip() import opencv from pygame import surfarray npy = surfarray.pixels3d(snapshot) ipl = opencv.adaptors.NumPy2Ipl(npy) import CvEyeTrack import vEyeTrack import cvEyeTrack