Ask Your Question

benpfeil's profile - activity

2013-08-03 07:25:07 -0600 received badge  Organizer (source)
2013-08-02 15:05:09 -0600 received badge  Student (source)
2013-08-02 14:38:31 -0600 asked a question 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()