Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Raspberry Pi Python Photo Booth

I'm working on making a photo booth running on a Raspberry Pi using Python and OpenCV. I found a great code example of how to capture images from a web cam here. http://joseph-soares.com/programacao/python/python-opencv-salvar-imagem-da-camera-no-disco/

The code that is provided alone works perfect on both the Pi and on my Windows PC. When I start adding code to this I'm having issues. I can no longer see what the web cam is seeing on the Pi and on Windows it is hit or miss. They are both capturing pictures though. In Windows it will actually display the image taken in the frame. If I revert back to the original code, again it works just fine.

I'm basically using a loop to give a count down before the picture is taken and flashing a light on the Arduino to represent the digit output that will be added in. I originally thought it was a memory issue on the Pi but it not working on my desktop is making me think otherwise. Any help would be appreciated.

Here is my current code:

import time, cv 
from datetime import datetime 
import pyfirmata 
import serial 

board = pyfirmata.Arduino('/dev/ttyACM0')

board = pyfirmata.Arduino('COM7')

arduino.open()

start an iterator thread so

serial buffer doesn't overflow

iter8 = pyfirmata.util.Iterator(board) iter8.start() greenLED = board.get_pin('d:13:o') debug = 1 def captureImage(): snapped = cv.QueryFrame(capture) cv.SaveImage(datetime.now().strftime('%Y%m%d_%Hh%Mm%Ss%f') + '.jpg', snapped) if __name__ == '__main__': capture = cv.CaptureFromCAM(0) cv.NamedWindow('Webcam') try: while True: for n in range(0, 4): frame = cv.QueryFrame(capture) cv.ShowImage('Webcam', frame)
                cv.WaitKey(10) 

                if debug: print "count down" 
                for i in range (0, 5): 
                     print i 
                     greenLED.write(1) 
                     time.sleep(1) 
                     greenLED.write(0) 
                     time.sleep(0.2) 
                     i+=1 

                greenLED.write(1) 
                time.sleep(0.2) 
                print "Say Cheese" 
                captureImage() 
                greenLED.write(0) 
                if debug: print "Waiting for 5 seconds" 
                time.sleep(5) 
                n+=1 

           break 

      capture = None   
      cv.DestroyAllWindows() 
      board.exit() 

 except KeyboardInterrupt: 
      cv.DestroyAllWindows() 
      board.exit()

click to hide/show revision 2
No.2 Revision

updated 2013-08-02 14:57:33 -0600

berak gravatar image

Raspberry Pi Python Photo Booth

I'm working on making a photo booth running on a Raspberry Pi using Python and OpenCV. I found a great code example of how to capture images from a web cam here. http://joseph-soares.com/programacao/python/python-opencv-salvar-imagem-da-camera-no-disco/

The code that is provided alone works perfect on both the Pi and on my Windows PC. When I start adding code to this I'm having issues. I can no longer see what the web cam is seeing on the Pi and on Windows it is hit or miss. They are both capturing pictures though. In Windows it will actually display the image taken in the frame. If I revert back to the original code, again it works just fine.

I'm basically using a loop to give a count down before the picture is taken and flashing a light on the Arduino to represent the digit output that will be added in. I originally thought it was a memory issue on the Pi but it not working on my desktop is making me think otherwise. Any help would be appreciated.

Here is my current code:

import time, cv 
from datetime import datetime 
import pyfirmata 
import serial 

board #board = pyfirmata.Arduino('/dev/ttyACM0')

pyfirmata.Arduino('/dev/ttyACM0') board = pyfirmata.Arduino('COM7')

arduino.open()

#arduino.open() # start an iterator thread so

so # serial buffer doesn't overflow

overflow iter8 = pyfirmata.util.Iterator(board) iter8.start() greenLED = board.get_pin('d:13:o') debug = 1 def captureImage(): snapped = cv.QueryFrame(capture) cv.SaveImage(datetime.now().strftime('%Y%m%d_%Hh%Mm%Ss%f') + '.jpg', snapped) if __name__ == '__main__': capture = cv.CaptureFromCAM(0) cv.NamedWindow('Webcam') try: while True: for n in range(0, 4): frame = cv.QueryFrame(capture) cv.ShowImage('Webcam', frame)
                 cv.WaitKey(10) 

                 if debug: print "count down" 
                 for i in range (0, 5): 
                      print i 
                      greenLED.write(1) 
                      time.sleep(1) 
                      greenLED.write(0) 
                      time.sleep(0.2) 
                      i+=1 

                 greenLED.write(1) 
                 time.sleep(0.2) 
                 print "Say Cheese" 
                 captureImage() 
                 greenLED.write(0) 
                 if debug: print "Waiting for 5 seconds" 
                 time.sleep(5) 
                 n+=1 

            break 

       capture = None   
       cv.DestroyAllWindows() 
       board.exit() 

  except KeyboardInterrupt: 
       cv.DestroyAllWindows() 
       board.exit()

Raspberry Pi Python Photo Booth

I'm working on making a photo booth running on a Raspberry Pi using Python and OpenCV. I found a great code example of how to capture images from a web cam here. http://joseph-soares.com/programacao/python/python-opencv-salvar-imagem-da-camera-no-disco/

The code that is provided alone works perfect on both the Pi and on my Windows PC. When I start adding code to this I'm having issues. I can no longer see what the web cam is seeing on the Pi and on Windows it is hit or miss. They are both capturing pictures though. In Windows it will actually display the image taken in the frame. If I revert back to the original code, again it works just fine.

I'm basically using a loop to give a count down before the picture is taken and flashing a light on the Arduino to represent the digit output that will be added in. I originally thought it was a memory issue on the Pi but it not working on my desktop is making me think otherwise. Any help would be appreciated.

Here is my current code:

import time, cv 
from datetime import datetime 
import pyfirmata 
import serial 

#board = pyfirmata.Arduino('/dev/ttyACM0') 
board = pyfirmata.Arduino('COM7') 
#arduino.open() 

# start an iterator thread so 
# serial buffer doesn't overflow 
iter8 = pyfirmata.util.Iterator(board) 
iter8.start() 

greenLED = board.get_pin('d:13:o') 

debug = 1 

def captureImage(): 
     snapped = cv.QueryFrame(capture) 
     cv.SaveImage(datetime.now().strftime('%Y%m%d_%Hh%Mm%Ss%f') + '.jpg', snapped) 

if __name__ == '__main__': 
     capture = cv.CaptureFromCAM(0) 
     cv.NamedWindow('Webcam') 
     try: 
          while True: 
               for n in range(0, 4): 
                    frame = cv.QueryFrame(capture) 
                    cv.ShowImage('Webcam', frame) 

                    cv.WaitKey(10) 

                    if debug: print "count down" 
                    for i in range (0, 5): 
                         print i 
                         greenLED.write(1) 
                         time.sleep(1) 
                         greenLED.write(0) 
                         time.sleep(0.2) 
                         i+=1 

                    greenLED.write(1) 
                    time.sleep(0.2) 
                    print "Say Cheese" 
                    captureImage() 
                    greenLED.write(0) 
                    if debug: print "Waiting for 5 seconds" 
                    time.sleep(5) 
                    n+=1 

               break 

          capture = None   
          cv.DestroyAllWindows() 
          board.exit() 

     except KeyboardInterrupt: 
          cv.DestroyAllWindows() 
          board.exit()