this is the whole code .. containing the camera interface and the gui interface ..
Code: Select all
"""
#! /usr/bin/python3
"""
from picamera import PiCamera
from time import sleep
from Tkinter import *
import tkFont
import tkFileDialog
import RPi.GPIO as GPIO
from PIL import ImageTk,Image
import serial
ser = serial.Serial('/dev/ttyAMA0', baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
sleep(1)
"""
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, GPIO.LOW)
"""
win = Tk()
win.title('User Interface')
#win.title("First GUI")
#win.geometry('800x480')
win.geometry('1024x615')
camera = PiCamera()
camera.rotation = 180
font1 = tkFont.Font(family = 'Helvetica', size = 19, weight = 'bold')
font2 = tkFont.Font(family = 'Helvetica', size = 17, weight = 'bold')
def sendFile():
with open("image.jpg", "rb") as fDst:
buffer= fSrc.read()
SendLong(len(buffer))
for byte in buffer:
SendByte(byte)
def openPreview():
#camera.start_preview()
#camera.start_preview(alpha=100)
#camera.start_preview(fullscreen=False,window=(50,100,300,220))
camera.resolution = (400, 240)
camera.start_preview(fullscreen=False, window=(0,125,400,240))
def stopPreview():
camera.stop_preview()
def exitProgram():
print("Exit Button pressed")
#GPIO.cleanup()
win.quit()
def captureImage():
global img
camera.capture('/home/pi/Desktop/image.jpg')
img = ImageTk.PhotoImage(Image.open("/home/pi/Desktop/image.jpg"))
canvas.create_image(0, 59, anchor=NW, image=img)
def loadImage1():
global img
img = Image.open('image1.jpg')
img = img.resize((400, 240))
img.save('resized_image.jpg')
imgDir = "/home/pi/Desktop/resized_image.jpg"
img = ImageTk.PhotoImage(Image.open(imgDir))
canvas.create_image(0, 59, anchor=NW, image=img)
def loadImage2():
global img
img = Image.open('image2.jpg')
img = img.resize((400, 240))
img.save('resized_image.jpg')
imgDir = "/home/pi/Desktop/resized_image.jpg"
img = ImageTk.PhotoImage(Image.open(imgDir))
canvas.create_image(0, 59, anchor=NW, image=img)
def loadImage3():
global img
img = Image.open('image3.jpg')
img = img.resize((400, 240))
img.save('resized_image.jpg')
imgDir = "/home/pi/Desktop/resized_image.jpg"
img = ImageTk.PhotoImage(Image.open(imgDir))
canvas.create_image(0, 59, anchor=NW, image=img)
def browseFile():
camera.stop_preview()
global img
fname = tkFileDialog.askopenfilename(filetypes = (("Image files", "*.jpg"), ("All files", "*")))
#print fname
img = Image.open(fname)
img = img.resize((400, 240))
img.save('resized_image.jpg')
imgDir = "/home/pi/Desktop/resized_image.jpg"
img = ImageTk.PhotoImage(Image.open(imgDir))
canvas.create_image(0, 59, anchor=NW, image=img)
"""
def rotateImage():
global img
img = Image.open("/home/pi/Desktop/resized_image.jpg")
img = ImageTk.PhotoImage(img.rotate(90))
img.save('resized_image.jpg')
img = ImageTk.PhotoImage(Image.open("/home/pi/Desktop/resized_image.jpg"))
canvas.create_image(0, 59, anchor=NW, image=img)
"""
frame1 = Frame(win, width = 400, height = 480)#, background = 'red')
frame1.pack(side = BOTTOM)
frame1.pack(expand=True, fill=BOTH)
frame2 = Frame(win, width = 400, height = 480)#, background = 'blue')
frame2.pack(side = BOTTOM)
frame2.pack(expand=True, fill=BOTH)
frame3 = Frame(win, width = 400, height = 480)#, background = 'green')
frame3.pack(side = LEFT)
frame3.pack(expand=True, fill=BOTH)
frame4 = Frame(win, width = 400, height = 480)#, background = 'yellow')
frame4.pack(side = LEFT)
frame4.pack(expand=True, fill=BOTH)
#frame5 = Frame(win, width = 200, height = 220, background = 'violet')
#frame5.pack(side = RIGHT)
#frame5.pack(expand=True, fill=BOTH)
#frame5.pack(expand=True)
#frame5.grid(row = 0, column = 0)
openPreviewButton = Button(frame1, text = "OPEN PREVIEW", font = font1, command = openPreview, height = 1, width =14 )
openPreviewButton.pack(side = LEFT)
closePreviewButton = Button(frame1, text = "CLOSE PREVIEW", font = font1, command = stopPreview, height = 1, width =15 )
closePreviewButton.pack(side = LEFT)
captureButton = Button(frame1, text = "CAPTURE", font = font1, command = captureImage, height =1 , width = 9)
captureButton.pack(side = LEFT)
sendButton = Button(frame1, text = "SEND", font = font1, command = sendFile, height = 1 , width = 5, bg = 'green', fg = 'white')
sendButton.pack(side = LEFT)
exitButton = Button(frame1, text = "EXIT", font = font1, command = exitProgram, height = 1 , width = 5, bg = 'red', fg = 'white')
exitButton.pack(side = LEFT)
browseImageButton = Button(frame2, text = "BROWSE IMAGE", font = font1, command = browseFile, height = 1 , width = 14, bg = 'orange', fg = 'white')
browseImageButton.pack(side = LEFT)
loadImg1Button = Button(frame2, text = "LOAD IMG 1", font = font1, command = loadImage1, height = 1 , width = 12)
loadImg1Button.pack(side = LEFT)
loadImg2Button = Button(frame2, text = "LOAD IMG 2", font = font1, command = loadImage2, height = 1 , width = 12)
loadImg2Button.pack(side = LEFT)
loadImg3Button = Button(frame2, text = "LOAD IMG 3", font = font1, command = loadImage3, height = 1 , width = 12)
loadImg3Button.pack(side = LEFT)
canvas = Canvas(frame4, width = 800, height = 480)
canvas.pack(side = LEFT)
"""
finally:
ser.close()
pass
"""
win.mainloop()