LeinadVetor
Posts: 14
Joined: Sat Aug 30, 2014 2:35 pm

picamera with GUI?

Sat Aug 30, 2014 3:04 pm

HEY GUYS!
i am new in the 'Python world' and i am (trying to) make a photobooth for my kids.
i bought a picamera and wrote a python script for it.

the python script it's simple (like the examples of the picam):
open the picamera, show the preview window, sleep for 5 seconds and take the picture.

well... until now, not big deal...

but when i try to put the preview window in the front of the tkinter window, doesn't work!
i know that it's not possible put picamera preview image to the tkinter frame, but we can fake it with preview window.
but every time that i run the program, the camera shows up for 5 seconds, take the picture and just after that the tkinter builds the window.

i am trying subprocess but nothing changed, here's the code (in the camera file):

Code: Select all

proc=Popen(["python", "gui.py"], stdout=PIPE)
output=proc.communicate()[0]

#start the camera settings, preview window and bla bla bla...


PLEAAAASE, I SERCHED FOR EVERY PAGE ON GOOGLE AND THE FORUM AND NOTHING =/

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: picamera with GUI?

Sat Aug 30, 2014 4:19 pm

Did you make sure that you imported subprocess?
There are 10 types of people: those who understand binary and those who don't.

LeinadVetor
Posts: 14
Joined: Sat Aug 30, 2014 2:35 pm

Re: picamera with GUI?

Sat Aug 30, 2014 5:09 pm

sure!
from subprocess import Popen, PIPE
right?
i dont know if i am using right the Popen. (it's right use communicate()? )

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: picamera with GUI?

Sat Aug 30, 2014 5:21 pm

If you need the output, then it is much simpler (I haven't tested it) to do the following:

Code: Select all

import subprocess
output = subprocess.check_output("python gui.py", shell=True)

print output
There are 10 types of people: those who understand binary and those who don't.

LeinadVetor
Posts: 14
Joined: Sat Aug 30, 2014 2:35 pm

Re: picamera with GUI?

Sat Aug 30, 2014 9:37 pm

hey man!
thanks for the fast reply.
put the print didn't change nothing =/
same thing here... run first one file and when the file ends, starts the other.
just need to import one time the subprocess, right?

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: picamera with GUI?

Sun Aug 31, 2014 10:45 am

Yes. Do you need the output? The following line should work. Are you sure that the gui.py is in the same directory? Id it is not, then before then change the line to:

Code: Select all

cd /home/pi/gui.py && python gui.py
Are you also sure that the gui works when called normally?
There are 10 types of people: those who understand binary and those who don't.

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: picamera with GUI?

Sun Aug 31, 2014 11:34 am

Post the code of both programs in

Code: Select all

 tags , please.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

LeinadVetor
Posts: 14
Joined: Sat Aug 30, 2014 2:35 pm

Re: picamera with GUI?

Mon Sep 01, 2014 2:39 pm

Hey man!!
I tested the script and still the same.
First the câmera shows up, sleep for 10 secs and after that runs the gui
:/

LeinadVetor
Posts: 14
Joined: Sat Aug 30, 2014 2:35 pm

Re: picamera with GUI?

Mon Sep 01, 2014 4:17 pm

oh sorry guys. i didn't saw the post above.
here is the code:
cam.py:

Code: Select all

import picamera
from time import sleep


with picamera.PiCamera() as camera:
        camera.preview_fullscreen=False
        camera.preview_window=(620, 320, 640, 480)

        camera.resolution=(640,480)
        camera.start_preview()
        camera.sharpness = 10
        camera.contrast = 30
        camera.vflip=False
        camera.hflip=False
        camera.exposure_mode = 'auto'

        sleep(10)
        #camera.stop_preview()
        #camera.close()

gui.py:

Code: Select all


from Tkinter import *
import RPi.GPIO as GPIO
import Image
from PIL import Image, ImageTk
from subprocess import Popen, PIPE

class Tela(object):
        def __init__(self,master, **kwargs):
                self.master=master
                pad=3
                self.geom='200x200+0+0'
                master.geometry("{0}x{1}+0+0".format(master.winfo_screenwidth()-pad,
master.winfo_screenheight()-pad))




        def toggle_geom(self, event):
                geom=self.master.winfo_geometry()
                print(geom,self._geom)
                self.master.geometry(self._geom)
                self._geom=geom

win = Tk()
win.title("test")
app=Tela(win)
frame = Frame(win)


frame.pack()

proc=Popen(["python","cam.py"],stdout=PIPE)
output=proc.communicate()[0]
print output


win.mainloop()

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: picamera with GUI?

Mon Sep 01, 2014 5:03 pm

You should merge the two programs.

The contents of cam.py should be copied into a function of
gui.py. Add a button to your GUI , which does call this function
when pressed.

Note that the PiCamera preview will not follow the TKInter
GUI when you move the latter - you will have to come up with
a syncronization scheme.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

LeinadVetor
Posts: 14
Joined: Sat Aug 30, 2014 2:35 pm

Re: picamera with GUI?

Mon Sep 01, 2014 5:33 pm

Thanks Ghans!
but when i wrote the first script. the two scripts were just one and didn't work out, i mean, the same thing happened:
first the preview shows up, and after the sleep time, it goes off and the GUI, starts.

i wanna the application of the photobooth already starts with the GUI (to be like a mirror) and when the button would be pressed, the capture() starts.

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: picamera with GUI?

Wed Sep 03, 2014 7:04 am

What happens if you replace the whole Popen() stuff in gui.py
with the contents of cam.py ?

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Aydan
Posts: 727
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: picamera with GUI?

Wed Sep 03, 2014 2:07 pm

In gui.py you start mainloop after calling the camera.
Mainloop starts the gui and the event loop.
You're blocking the GUI until after cam.py has finished.
What you have to do is to make a button in the gui that calls popen() (or better yet put your cam.py stuff into this function)

Regards
Aydan

Return to “General discussion”