Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from gpiozero import Button as BTN
- from gpiozero import LED
- from picamera import PiCamera
- from time import gmtime, strftime, sleep
- from Tkinter import *
- from PIL import Image, ImageTk, ImageEnhance, ImageDraw, ImageFont
- from cups import *
- from io import BytesIO
- import os
- Exit_Program_btn = BTN(23)
- take_picture_btn = BTN(25)
- led = LED(8)
- output = " "
- latest_photo = '/home/pi/allseeingpi/latest.jpg'
- Temp_Pic = '/home/pi/allseeingpi/temp_pic.jpg'
- montage_file = '/home/pi/allseeingpi/montage.jpg'
- photo_banner = '/home/pi/allseeingpi/Photo_Bottom.jpg'
- Status = "Press button to start" #21
- def Exit_Program():
- camera.stop_preview()
- led.off()
- root.destroy()
- print("Tkinter window closed")
- def take_picture():
- global output
- global Temp_Pic
- global latest_photo
- global i
- #get the number from the text file and overwrite it to the next number
- num = open('/home/pi/allseeingpi/number.txt','r')
- numb = int(num.read())
- num.close()
- numbe = open('/home/pi/allseeingpi/number.txt','w')
- numbe.write(str(numb+1))
- numbe.close()
- #set the output file location and name
- output = "/home/pi/allseeingpi/image-" + str(numb) + ".png"
- #Capture picture and save to Temp_Pic
- camera.capture(Temp_Pic)
- if i==4:
- camera.stop_preview()
- led.off()
- #resize the image for keeps and montage
- tn_size = 516, 344
- #size = 1800, 1200
- jpg_img1 = Image.open(Temp_Pic)#, resize = tn_size)
- jpg_img = jpg_img1.crop((0,108,2592,1836))
- jpg_img1.close()
- #jpg_img.resize(size, Image.BICUBIC)
- jpg_tbn = jpg_img.resize(tn_size, Image.BICUBIC)
- jpg_tbn.save(latest_photo, 'jpeg')
- jpg_img.save(output, 'jpeg')
- jpg_img.close()
- jpg_tbn.close()
- def montage_pics():
- global montage_file
- global i
- global latest_photo
- #gap = 42, img_width = 516, img_height = 344
- x_offset = 687#42
- x_offset1 = 1287#642
- y_offset = 42*i+344*(i-1)
- y_offset1 = 42*(i+1)+344*i
- montage = Image.open(montage_file)
- latest_pic = Image.open(latest_photo)
- montage.paste(latest_pic, (x_offset, y_offset))
- montage.paste(latest_pic, (x_offset1, y_offset))
- if i==4:
- pic_bottom = Image.open(photo_banner)
- montage.paste(pic_bottom, (x_offset, y_offset1))
- montage.paste(pic_bottom, (x_offset1, y_offset1))
- enhancer = ImageEnhance.Brightness(montage)
- montage = enhancer.enhance(1.4)
- montage.save(montage_file)
- montage.close()
- def printPhoto():
- conn = Connection()
- printers = conn.getPrinters()
- printer_name = printers.keys()[0]
- conn.printFile(printer_name,montage_file,"TITLE",{})
- sleep(80)#should be 90sec
- #conn.cancelAllJobs(name = 'Canon_MG6100_series')
- os.system('/home/pi/allseeingpi/Restart_Cups.sh')
- sleep(5)
- def picture_sequence():
- global i
- global Status
- global var
- camera.start_preview()
- led.on()
- for x in range(4):
- i = int(x) + 1
- if x <= 2:
- pip = camera.add_overlay(Image.open('/home/pi/allseeingpi/3g.jpg').tobytes(), size = (128,192), window = (500, 150, 128, 192), format='rgb', layer = 3, alpha=128, fullscreen = False)#size=(840, 560),format='rgb', window = (100, 100, 128,192), fullscreen = False,
- Status = " Picture " + str(i) + " of 4" #22
- var.set(Status)
- sleep(0.5)
- pip.update((Image.open('/home/pi/allseeingpi/2g.jpg')).tobytes())
- #Status = " Picture " + str(i) + " of 4 in 2s " #22
- var.set(Status)
- sleep(0.5)
- pip.update((Image.open('/home/pi/allseeingpi/1g.jpg')).tobytes())
- #Status = " Picture " + str(i) + " of 4 in 1s " #22
- var.set(Status)
- sleep(0.5)
- camera.remove_overlay(pip)
- pip.close()
- Status = " Processing... "#21
- var.set(Status)
- take_picture()
- montage_pics()
- else:
- pip = camera.add_overlay(Image.open('/home/pi/allseeingpi/3g.jpg').tobytes(), size = (128,192), window = (500, 150, 128, 192), format='rgb', layer = 3, alpha=128, fullscreen = False)#size=(840, 560),format='rgb', window = (100, 100, 128,192), fullscreen = False,
- Status = " Picture " + str(i) + " of 4" #22
- var.set(Status)
- sleep(0.5)
- pip.update((Image.open('/home/pi/allseeingpi/2g.jpg')).tobytes())
- #Status = " Picture " + str(i) + " of 4 in 2s " #22
- var.set(Status)
- sleep(0.5)
- pip.update((Image.open('/home/pi/allseeingpi/1g.jpg')).tobytes())
- #Status = " Picture " + str(i) + " of 4 in 1s " #22
- var.set(Status)
- sleep(0.5)
- camera.remove_overlay(pip)
- pip.close()
- Status = " Processing... "#21
- var.set(Status)
- take_picture()
- Status = "Compiling and Printing" #22
- var.set(Status)
- montage_pics()
- printPhoto()
- Status = "Press button to start" #21
- var.set(Status)
- Exit_Program_btn.when_pressed = Exit_Program
- take_picture_btn.when_pressed = picture_sequence
- camera = PiCamera()
- camera.resolution = (2592, 1944) #Pic taken at full res to allow full preview
- camera.hflip = True
- camera.awb_mode = 'auto'
- camera.preview_fullscreen = False
- camera.preview_window = (155, 3, 840, 560)#825, 550)#(210, 150, 600, 400)
- class Window(Frame):
- # Define settings upon initialization. Here you can specify
- def __init__(self, master=None):
- # parameters that you want to send through the Frame class.
- Frame.__init__(self, master)
- #reference to the master widget, which is the tk window
- self.master = master
- #with that, we want to then run init_window, which doesn't yet exist
- self.init_window()
- def init_window(self):
- # changing the title of our master widget
- self.master.title("GUI")
- # allowing the widget to take the full space of the root window
- self.pack(fill=BOTH, expand=1)
- #Load and place background image
- load = Image.open("/home/pi/allseeingpi/background.jpg")
- render = ImageTk.PhotoImage(load)
- img = Label(self, image=render)
- img.image = render
- img.place(x=0, y=0)
- load.close()
- #Create text variable to update status to user
- txt = Label(root, textvariable=var, justify=RIGHT, bg="white", font=("Courier", 32))#, wraplength=398) anchor=S, padx = 1000, justify=CENTER,
- txt.place(x=290, y=550)
- #txt.pack()
- var.set(Status)
- root = Tk()
- root.geometry("1024x600")
- var = StringVar(root, value=" ")
- app = Window(root)
- root.overrideredirect(True) #no borders
- root.config(cursor="none")
- root.mainloop()
Add Comment
Please, Sign In to add comment