def take_photo(): global photo canvas.bind(key_codes.EKeySelect, None) camera.stop_finder() photo = camera.take_photo(size=(640, 480)) handle_redraw(None) photo.save(fname + ".jpg")
def quit(): global running running = 0 camera.stop_finder() #Close the viewfinder camera.release() #Release the camera so that other programs can use it app_lock.signal() appuifw.app.set_exit()
def videocamera(): global keyboard i = len(os.listdir("E:\\Videos\\")) video_savepath = u"E:\\Videos\\vid%d.mp4" % i canvas = appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=None) appuifw.app.body = canvas camera.stop_finder() camera.start_finder(vf, size=(240, 196)) recording = False running = True while running: if keyboard.pressed(EScancodeSelect): if not recording: vid = camera.start_record( video_savepath, video_callback) #Start recording the video recording = True else: camera.stop_record() #Stop recording videocamera() #Restart the camera in video mode if keyboard.pressed(EScancodeRightSoftkey) and recording: camera.stop_record() quit() appuifw.app.menu = [(u"Exit", quit)] e32.ao_yield()
def camquit(): camera.stop_finder() camera.release() # get main menu back appuifw.app.menu = menu_list # clean all bindings canvas.bind(key_codes.EKeySelect, None)
def quit(): global running running=0 camera.stop_finder() #Close the viewfinder camera.release() #Release the camera so that other programs can use it app_lock.signal() appuifw.app.set_exit()
def videocamera(): global keyboard i=len(os.listdir("E:\\Videos\\")) video_savepath=u"E:\\Videos\\vid%d.mp4" % i canvas=appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=None) appuifw.app.body=canvas camera.stop_finder() camera.start_finder(vf, size=(240,196)) recording=False running=True while running: if keyboard.pressed(EScancodeSelect): if not recording: vid=camera.start_record(video_savepath, video_callback) #Start recording the video recording=True else: camera.stop_record() #Stop recording videocamera() #Restart the camera in video mode if keyboard.pressed(EScancodeRightSoftkey) and recording: camera.stop_record() quit() appuifw.app.menu=[(u"Exit", quit)] e32.ao_yield()
def test_start_record(self): def video_cb(err, code): self.failIf(err, "Error while recording") if self.counter: self.failUnlessEqual(code, camera.EPrepareComplete, "State is not proper") else: self.failUnlessEqual(code, camera.EOpenComplete, "State is not proper") self.counter += 1 def finder_cb(im): appuifw.app.body.blit(im) self.counter = 0 video_filename = 'test_video.3gp' appuifw.app.body = appuifw.Canvas() self.delete_files_if_exist([video_filename], save_path) try: camera.start_finder(finder_cb) camera.start_record(save_path + video_filename, video_cb) e32.ao_sleep(5) camera.stop_record() camera.stop_finder() except RuntimeError, e: print >> sys.stderr, "Error recording a video :", e raise
def close(self, pos = (0, 0)): self.canvas.bind(key_codes.EButton1Down, None) appuifw.app.screen = 'normal' appuifw.app.orientation = 'portrait' camera.stop_finder() camera.release()
def stop(): global stopp global stopr stopp = True stopr = True camera.stop_finder() cnvCallback() appuifw.app.menu = mainmenu_stopped
def set_zoom_half_max(): global zoom, z1, z2, z3 zoom = camera.max_zoom() / 2 z1 = "0" z2 = str(camera.max_zoom() / 4) z3 = "X " + str(camera.max_zoom() / 2) pic = camera.take_photo('RGB', resolution, zoom) camera.stop_finder() camera.start_finder(vf, size=(240, 180))
def set_zoom_0(): global zoom, z1, z2, z3 zoom=0 z1="X 0" z2=str(camera.max_zoom()/4) z3=str(camera.max_zoom()/2) pic=camera.take_photo('RGB', resolution, zoom) camera.stop_finder() camera.start_finder(vf, size=(240,180))
def new_view(): camera.stop_finder() message(appuifw.app.body) camera.take_photo( mode="JPEG_Exif", size=camera.image_sizes()[-1], # should be the smallest available exposure=exposure_modes[exposure_mode], white_balance=white_modes[white_mode]) start_view()
def handleTabs(self, tabIndex): if tabIndex == 0: if(self.imagerOn == 1): camera.stop_finder() self.imagerOn = 0 self.displayGUI() elif tabIndex == 1: self.initImager() else: self.displayGUI()
def shoot(): global state camera.stop_finder() pic_time = time.ctime() pos_string = u"Lat: " + str(pos['latitude']) + u" Long: " + str(pos['longitude']) pos_string = pos_string + " " + pic_time photo = camera.take_photo(size = (640, 480)) w, h = photo.size photo.rectangle((0, 0, w, 15), fill = (255,0,255)) photo.text((5,12), pos_string, fill = (255, 255, 255)) w, h = canvas.size canvas.rectangle((0,0,w,h), fill=(255,255,255)) canvas.text((20,h - 20), u"Picture ready", fill = (0,0,0)) canvas.blit(photo, target = (0, 0, w, 0.75 * w), scale = 1) pic_time = pic_time.replace(":","-") filename = "E:\\Images\\" + pic_time.replace(" ", "_") + ".jpg" photo.save(filename)
def run(self): Dialog.refresh(self) try: camera.start_finder(self.redraw) except: note(LABELS.loc.pt_err_cant_start_viewf,"error") return None while (not self.taken) and (not self.cancel): e32.ao_yield() try: camera.stop_finder() camera.release() except: note(LABELS.loc.pt_err_cant_stop_viewf,"error") return self.filename
def run(self): # setup screen appuifw.app.screen = 'large' appuifw.app.title = u'Magic Video' appuifw.app.exit_key_handler = self.stop appuifw.app.body = appuifw.Canvas(event_callback=self.event) appuifw.app.menu = [(u"Effortless (2x2)", lambda: self.new_game(4)), (u"Easy (3x3)", lambda: self.new_game(9)), (u"Medium (4x4)", lambda: self.new_game(16)), (u"Hard (5x5)", lambda: self.new_game(25)), (u"Impossible (6x6)", lambda: self.new_game(36)), (u"Help", self.help), (u"About Magic Video", self.about)] self.prerender_text() camera.start_finder(self.draw) # start camera self.lock = e32.Ao_lock() self.lock.wait() camera.stop_finder() camera.release()
def photo(): global info info = u"Taking photo..." start_time = time.time() camera.stop_finder() message(appuifw.app.body) p = camera.take_photo( mode="JPEG_Exif", size=(1600, 1200), flash=flash_modes[flash_mode], exposure=exposure_modes[exposure_mode], white_balance=white_modes[white_mode]) filename = time.strftime("E:\\Images\\%d%m%y-%H%M%S.jpg") f = open(filename, "w") f.write(p) f.close() appuifw.app.body.blit(graphics.Image.open(filename), scale=1) time.sleep(2) start_time = 0 start_view()
def take_photo(): canvas.bind(key_codes.EKeySelect, None) camera.stop_finder() show_text(u"Hold still!") image = camera.take_photo(size = (640, 480)) s = canvas.size canvas.blit(image,target=(0,0,s[0],(s[0]/4*3)), scale=1) show_text(u"Uploading to Flickr...") image.save(IMG_FILE) jpeg = file(IMG_FILE, "r").read() params = {'api_key': API_KEY, 'title': 'InstaFlickr', 'auth_token': flickr_token,\ 'photo': jpeg} ret = flickr_signed_call(params) canvas.clear((255, 255, 255)) if ret: show_text(u"Photo sent ok!") else: show_text(u"Network error")
def quit(): camera.stop_finder() camera.release() app_lock.signal()
def exit_key_handler(self): camera.stop_finder() self.canvas = None appuifw.app.exit_key_handler = None self.script_lock.signal()
def stop_finder(self): camera.stop_finder() self.finder_on = 0 appuifw.note(u"Viewfinder stopped")
def photocamera(): global keyboard, z1, z2, z3, zoom, r1, r2, resolution, q, q1, q2 #We set the tabs of the application def handle_tabs(index): global lb, videocamera if index == 0: photocamera() if index == 1: videocamera() appuifw.app.set_tabs([u"Photo", u"Video"], handle_tabs) #In order to be able to take several pictures and videos, we add a number to the end of their filenames. #This number is obtained by checking how many files of that type are saved on the device i = len(os.listdir("E:\\Images\\")) photo_savepath = u"E:\\Images\\pic%d.jpg" % i #Make the background a canvas; needed for key capturing canvas = appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=None) appuifw.app.body = canvas #The default resolution is 0.8 megapixels and the default zoom level is 0 resolution = (1024, 768) r1 = "X 1024x768" r2 = "640x480" zoom = 0 z1 = "X 0" z2 = str(camera.max_zoom() / 4) z3 = str(camera.max_zoom() / 2) #These functions set the resolution, zoom and image quality to the selected value def set_res_vga(): global resolution, r1, r2 resolution = (640, 480) r1 = "1024x768" r2 = "X 640x480" def set_res_08(): global resolution, r1, r2 resolution = (1024, 768) r1 = "X 1024x768" r2 = "640x480" def set_zoom_0(): global zoom, z1, z2, z3 zoom = 0 z1 = "X 0" z2 = str(camera.max_zoom() / 4) z3 = str(camera.max_zoom() / 2) pic = camera.take_photo('RGB', resolution, zoom) camera.stop_finder() camera.start_finder(vf, size=(240, 180)) def set_zoom_quarter_max(): global zoom, z1, z2, z3 zoom = camera.max_zoom() / 4 z1 = "0" z2 = "X " + str(camera.max_zoom() / 4) z3 = str(camera.max_zoom() / 2) pic = camera.take_photo('RGB', resolution, zoom) camera.stop_finder() camera.start_finder(vf, size=(240, 180)) def set_zoom_half_max(): global zoom, z1, z2, z3 zoom = camera.max_zoom() / 2 z1 = "0" z2 = str(camera.max_zoom() / 4) z3 = "X " + str(camera.max_zoom() / 2) pic = camera.take_photo('RGB', resolution, zoom) camera.stop_finder() camera.start_finder(vf, size=(240, 180)) def set_qual_50(): global q, q1, q2 q = 50 q1 = "High" q2 = "X Low" def set_qual_100(): global q, q1, q2 q = 100 q1 = "X High" q2 = "Low" #In order for the viewfinder to correspond to the zoom level, we must take a picture (without saving it), close and open the viewfinder #These steps are necessary because of the way the functions are currently defined in PyS60, and have a slight impact on performance #Future releases of PyS60 may have optimized functions pic = camera.take_photo('RGB', resolution, zoom) camera.stop_finder() camera.start_finder(vf, size=(240, 180)) #We now create a loop that "waits" for keys to be pressed running = True while running: if keyboard.pressed(EScancodeSelect): pic = camera.take_photo('RGB', resolution, zoom) #Take the picture pic.save(photo_savepath, quality=q) #Save it photocamera() #Restart camera in photo mode if keyboard.pressed(EScancodeRightSoftkey): quit() appuifw.app.menu = [(u"Zoom", ((u"%s" % z1, set_zoom_0), (u"%s" % z2, set_zoom_quarter_max), (u"%s" % z3, set_zoom_half_max))), (u"Resolution", ((u"%s" % r1, set_res_08), (u"%s" % r2, set_res_vga))), (u"Quality", ((u"%s" % q1, set_qual_100), (u"%s" % q2, set_qual_50))), (u"Exit", quit)] e32.ao_yield()
def stop(): camera.stop_finder() cnvCallback() appuifw.app.menu = [(u'Start', start), (u'Exit', __exit__)]
def take_picture(): camera.stop_finder() pic = camera.take_photo(size = (640,480)) w,h = canvas.size canvas.blit(pic,target=(0, 0, w, 0.75 * w), scale = 1) pic.save('e:\\Images\\picture1.jpg')
def capture( ): camera.stop_finder( ) cnvCallback( ) appuifw.app.menu = [(u'Start', start), (u'Exit', __exit__)] img.save(u'E:\\Images\\viewfinder.png') appuifw.note(u'Saved', 'info')
def shoot(): camera.stop_finder() photo = camera.take_photo(size=(640, 480)) w, h = canvas.size canvas.blit(photo, target=(0, 0, w, 0.75 * w), scale=1) photo.save('e:\\Images\\photo.jpg')
def quit(): camera.stop_finder() app_lock.signal()
def stop_finder(self): camera.stop_finder() self.finder_on=0 appuifw.note(u"Viewfinder stopped")
def exit_key_handler(self): camera.stop_finder() self.canvas=None appuifw.app.exit_key_handler = None self.script_lock.signal()
def exit(): camera.stop_finder() app_lock.signal()
def capture_cb(): global photo photo=camera.take_photo() camera.stop_finder() lock.signal()
def quit(): camera.stop_finder() camera.release() myLock.signal()
def photocamera(): global keyboard, z1, z2, z3, zoom, r1, r2, resolution, q, q1, q2 #We set the tabs of the application def handle_tabs(index): global lb, videocamera if index==0:photocamera() if index==1:videocamera() appuifw.app.set_tabs([u"Photo", u"Video"], handle_tabs) #In order to be able to take several pictures and videos, we add a number to the end of their filenames. #This number is obtained by checking how many files of that type are saved on the device i=len(os.listdir("E:\\Images\\")) photo_savepath=u"E:\\Images\\pic%d.jpg" % i #Make the background a canvas; needed for key capturing canvas=appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=None) appuifw.app.body=canvas #The default resolution is 0.8 megapixels and the default zoom level is 0 resolution=(1024, 768) r1="X 1024x768" r2="640x480" zoom=0 z1="X 0" z2=str(camera.max_zoom()/4) z3=str(camera.max_zoom()/2) #These functions set the resolution, zoom and image quality to the selected value def set_res_vga(): global resolution, r1, r2 resolution=(640, 480) r1="1024x768" r2="X 640x480" def set_res_08(): global resolution, r1, r2 resolution=(1024, 768) r1="X 1024x768" r2="640x480" def set_zoom_0(): global zoom, z1, z2, z3 zoom=0 z1="X 0" z2=str(camera.max_zoom()/4) z3=str(camera.max_zoom()/2) pic=camera.take_photo('RGB', resolution, zoom) camera.stop_finder() camera.start_finder(vf, size=(240,180)) def set_zoom_quarter_max(): global zoom, z1, z2, z3 zoom=camera.max_zoom()/4 z1="0" z2="X " + str(camera.max_zoom()/4) z3=str(camera.max_zoom()/2) pic=camera.take_photo('RGB', resolution, zoom) camera.stop_finder() camera.start_finder(vf, size=(240,180)) def set_zoom_half_max(): global zoom, z1, z2, z3 zoom=camera.max_zoom()/2 z1="0" z2=str(camera.max_zoom()/4) z3="X " + str(camera.max_zoom()/2) pic=camera.take_photo('RGB', resolution, zoom) camera.stop_finder() camera.start_finder(vf, size=(240,180)) def set_qual_50(): global q, q1, q2 q=50 q1="High" q2="X Low" def set_qual_100(): global q, q1, q2 q=100 q1="X High" q2="Low" #In order for the viewfinder to correspond to the zoom level, we must take a picture (without saving it), close and open the viewfinder #These steps are necessary because of the way the functions are currently defined in PyS60, and have a slight impact on performance #Future releases of PyS60 may have optimized functions pic=camera.take_photo('RGB', resolution, zoom) camera.stop_finder() camera.start_finder(vf, size=(240,180)) #We now create a loop that "waits" for keys to be pressed running=True while running: if keyboard.pressed(EScancodeSelect): pic=camera.take_photo('RGB', resolution, zoom) #Take the picture pic.save(photo_savepath, quality=q) #Save it photocamera() #Restart camera in photo mode if keyboard.pressed(EScancodeRightSoftkey):quit() appuifw.app.menu=[(u"Zoom", ((u"%s" % z1, set_zoom_0), (u"%s" % z2, set_zoom_quarter_max), (u"%s" % z3, set_zoom_half_max))), (u"Resolution", ((u"%s" % r1, set_res_08), (u"%s" % r2, set_res_vga))), (u"Quality", ((u"%s" % q1, set_qual_100), (u"%s" % q2, set_qual_50))), (u"Exit", quit)] e32.ao_yield()
def stop( ): camera.stop_finder( ) cnvCallback( ) appuifw.app.menu = [(u'Start', start), (u'Exit', __exit__)]
def capture(): camera.stop_finder() cnvCallback() appuifw.app.menu = [(u'Start', start), (u'Exit', __exit__)] img.save(u'E:\\Images\\viewfinder.png') appuifw.note(u'Saved', 'info')