我正在使用Python和OpenCV在Raspberry Pi上运行照相亭。我找到了一个很好的代码示例,说明如何从网络摄像头捕获图像。 http://joseph-soares.com/programacao/python/python-opencv-salvar-imagem-da-camera-no-disco/
单独提供的代码在Pi和我的Windows PC上都是完美的。当我开始为此添加代码时,我遇到了问题。我无法再看到网络摄像头在Pi上看到的内容,而在Windows上它会被击中或错过。他们都在捕捉图片。在Windows中,它实际上将显示帧中拍摄的图像。如果我恢复原始代码,它再次正常工作。
我基本上使用一个循环在拍摄照片之前进行倒计时并在Arduino上闪烁一个灯来表示将要添加的数字输出。我原本以为它是Pi上的内存问题但是它不能在我的桌面上工作让我想到不然。任何帮助将不胜感激。
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()