import RPi.GPIO as GPIO import time import picamera from Tkinter import * fr=0 fram = 10 var = 256 flag1=0 flag2=0 film=0 dt = 1 GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_UP) GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP) GPIO.setup(17, GPIO.OUT) GPIO.setup(27, GPIO.OUT) GPIO.setup(22, GPIO.OUT) GPIO.output(27, False) GPIO.output(22, False) GPIO.output(17, False) def sinxv1(): global flag1 global flag2 global film GPIO.output(27, False) GPIO.output(22, 1) film = film +1 flag2=0 j=0 k=0 if camera.preview: camera.stop_preview() camera.crop = (0.05,0.05,0.90,0.90) camset() camera.start_preview() camera.start_recording('/home/pi/fotopicam/my_video%02d.h264' % film) #camera.start_recording('/home/pi/fotopicam/my_video%02d.h264' % film, intra_period = 0) dtf= 0.98542/fram start = time.time() while flag2 == 0: cfi=camera.frame.index if cfi>j+k: print(j,k,cfi) k=cfi-j while flag1 == 0: GPIO.output(17, 1) GPIO.output(17, False) #while cfi <=j: #cfi=camera.frame.index #print(cfi) j=j+1 #print(j,j) flag1=0 fin = time.time() ##dt1= fin - start ##ddt=dtf-dt1 #ddt2 = start +dtf ##print(ddt) while fin <= start +dtf*j: fin = time.time() print (j) selection2 = "frames = " + str(j) selection3 = "i-frames = " + str(k) label2.config(text = selection2) label3.config(text = selection3) camera.stop_recording() def motor1(): GPIO.output(22, 1) GPIO.output(27, 0) GPIO.output(17, 1) def motor2(): GPIO.output(17, 0) GPIO.output(22, 0) GPIO.output(27, 0) def motor3(): GPIO.output(22, 0) GPIO.output(27, 1) GPIO.output(17, 1) def motorob(): global flag1 GPIO.output(27, 0) GPIO.output(22, 1) GPIO.output(17, 1) while flag1 == 0: a =1 GPIO.output(17, False) flag1=0 #time.sleep(0.01) with picamera.PiCamera() as camera: #camera.resolution = (1296, 972) camera.resolution = (1024, 768) #camera.resolution = (800, 600) #camera.resolution = (640, 480) #camera.resolution = (768, 576) camera.hflip = 1 def prev1(): selprev(0,0.25,0.4,0.4) def prevc(): selprev(0.05,0.05,0.90,0.90) def prev2(): selprev(0.35,0.25,0.4,0.4) def prev3(): selprev(0.7,0.25,0.4,0.4) def selprev(x,y,w,h): camera.crop = (x,y,w,h) camset() camera.start_preview() def prv(): if camera.preview: camera.stop_preview() camset() camera.start_preview() def camset(): global fram fram=int(Spinbox1.get()) camera.framerate = fram camera.preview_fullscreen=CheckVar1.get() camera.preview_window = (0,0,800,600) camera.awb_mode = wb.get() #camera.awb_mode = "off" camera.awb_gains =1.2 if CheckVar2.get() == 1: camera.color_effects = (128,128) else: camera.color_effects = None camera.drc_strength = 'high' #camera.drc_strength = 'low' camera.exposure_compensation = -10 #camera.brightness = 40 camera.contrast = -10 if exp.get() == "none": camera.iso = 0 camera.shutter_speed = 0 camera.exposure_mode = "auto" elif exp.get() == "off": camera.iso = var2.get() camera.shutter_speed = int(1000000/var) camera.exposure_mode = "auto" camera.analog_gains =1 camera.digital_gains =1 #while camera.analog_gains <1: time.sleep(0.5) camera.exposure_mode = "off" else: camera.iso = var2.get() camera.shutter_speed = int(1000000/var) camera.exposure_mode = exp.get() def selp(): global var var=var/2 label.config(text= "1/" + str(var)) prv() def seln(): global var var=var*2 label.config(text= "1/" + str(var)) prv() def filenames(): #global flag2 frame = 0 while flag2 == 0: yield '/home/pi/fotopicam/image%04d.jpg' % frame frame += 1 motorob() def selcam(): global flag2 flag2=0 if camera.preview: camera.stop_preview() camera.crop = (0.05,0.05,0.90,0.90) camset() camera.start_preview() #camera.capture_sequence(filenames()) camera.capture_sequence(filenames(), use_video_port=True, quality=75) def selcam1(): global fr fr=fr+1 #camera.crop = (0,0,1,1) #camset() camera.exif_tags['IFD0.Artist'] = "RWPBB" camera.exif_tags['EXIF.FocalLength'] = '50' camera.capture("/home/pi/fotopicam/pif%03d.jpg" % fr) def camFunction(can): global flag1 flag1=1 def info(): selection2 = "ISO = " + str(camera.iso) selection3 = "exposure_mode = " + exp.get() selection4 = "white-balance = " + wb.get() label2.config(text = selection2) label3.config(text = selection3) label4.config(text = selection4) label.config(text= "1/" + str(int(1000000/camera.exposure_speed))) def sels(): camera.stop_preview() def finFunction(can): global flag2 flag2=1 camera.stop_preview() def sel(): camera.crop = (0,0,1,1) camset() camera.start_preview() GPIO.add_event_detect(23, GPIO.FALLING, callback=camFunction, bouncetime=50) GPIO.add_event_detect(24, GPIO.FALLING, callback=finFunction, bouncetime=200) root = Tk() root.title("PiCamera") CheckVar2 = IntVar() CheckVar2.set(0) CheckVar1 = IntVar() CheckVar1.set(0) var2 = IntVar() var2.set(100) exp = StringVar() exp.set("auto") wb = StringVar() wb.set("auto") mb= Menubutton (text="exposure_mode", relief=RAISED, font=('monospace',18) ) mb.menu = Menu ( mb, tearoff = 0, font=('monospace',18) ) mb["menu"] = mb.menu mb.menu.add_radiobutton ( label="off", variable=exp, value="off" ) mb.menu.add_radiobutton ( label="auto", variable=exp, value="auto" ) mb.menu.add_radiobutton ( label="none", variable=exp, value="none" ) mb.grid(row=0,column=0, sticky='w') mbwb= Menubutton (text="white-balance ", relief=RAISED, font=('monospace',18) ) mbwb.menu = Menu ( mbwb, tearoff = 0, font=('monospace',18) ) mbwb["menu"] = mbwb.menu mbwb.menu.add_radiobutton ( label="off", variable=wb, value="off" ) mbwb.menu.add_radiobutton ( label="auto", variable=wb, value="auto" ) mbwb.menu.add_radiobutton ( label="sunlight", variable=wb, value="sunlight" ) mbwb.menu.add_radiobutton ( label="cloudy", variable=wb, value="cloudy" ) mbwb.menu.add_radiobutton ( label="shade", variable=wb, value="shade" ) mbwb.menu.add_radiobutton ( label="tungsten", variable=wb, value="tungsten" ) mbwb.grid(row=0,column=2, sticky='e') labels = Label(text="shutter_speed", font=('monospace',18)) labels.grid(row=1,column=1) button = Button(text="info", command=info, font=('monospace',18)) button.grid(row=0,column=1) buttonn = Button(text="+", command=selp, font=('monospace',24), width = 3) buttonn.grid(row=2,column=0, sticky='w') buttonp = Button(text="-", command=seln, font=('monospace',24), width = 3) buttonp.grid(row=2,column=2, sticky='e') label = Label(text= "1/" + str(var), font=('monospace',18)) label.grid(row=2,column=0,columnspan=3) labeliso = Label( root, text="ISO", font=('monospace',18)) labeliso.grid(row=4,column=0,columnspan=3) scale1 = Scale(variable = var2,orient=HORIZONTAL,length=400, from_=100,to=800,tickinterval=100,resolution=10) scale1.grid(row=5,column=0,columnspan=3) button = Button(text="preview", command=sel, font=('monospace',18), height=2) button.grid(row=6,column=0) C1 = Checkbutton(text = "fullscreen", variable = CheckVar1, \ onvalue = 1, offvalue = 0, height=2, \ width =11, font=('monospace',18)) C1.grid(row=6,column=1) C2 = Checkbutton(text = "B&W", variable = CheckVar2, \ onvalue = 1, offvalue = 0, height=2, \ width = 8, font=('monospace',18)) C2.grid(row=1,column=2) buttonpstop = Button(text="Stop", command=sels, font=('monospace',18), height=2) buttonpstop.grid(row=6,column=2) buttonpcam = Button(text="Foto", command=selcam1, font=('monospace',18), height=2) buttonpcam.grid(row=10,column=1) buttonpcam = Button(text="Foto>>", command=selcam, font=('monospace',18), height=2) buttonpcam.grid(row=12,column=2) buttonprev1 = Button(text="prev+", command=prev1, font=('monospace',18), height=2) buttonprev1.grid(row=9,column=0) buttonprev2 = Button(text="prev+", command=prev2, font=('monospace',18), height=2) buttonprev2.grid(row=9,column=1) buttonprev3 = Button(text="prev+", command=prev3, font=('monospace',18), height=2) buttonprev3.grid(row=9,column=2) buttonprev4 = Button(text="crop", command=prevc, font=('monospace',18), height=2) buttonprev4.grid(row=10,column=0) buttonprev1 = Button(text=">", command=motor1, font=('monospace',18), height=2,width =3) buttonprev1.grid(row=11,column=0) buttonprev2 = Button(text="STOP MOTOR", command=motor2, font=('monospace',18), height=2) buttonprev2.grid(row=11,column=1) buttonprev3 = Button(text="<", command=motor3, font=('monospace',18), height=2,width =3) buttonprev3.grid(row=11,column=2) buttonprev1 = Button(text="Video>>", command=sinxv1, font=('monospace',18), height=2) buttonprev1.grid(row=12,column=0) Spinbox1 = Spinbox(from_=3, to=15,width =3, font=('monospace',24)) Spinbox1.grid(row=12,column=1) Spinbox1.delete(0) Spinbox1.insert(0,13) label2 = Label(font=('monospace',18)) label2.grid(row=14,column=0,columnspan=3) label3 = Label(font=('monospace',18)) label3.grid(row=15,column=0,columnspan=3) label4 = Label(font=('monospace',18)) label4.grid(row=13,column=0,columnspan=3) root.mainloop() camera.close() GPIO.cleanup()