嗨,我正在努力提高自己,我對樹莓派感興趣。我想用樹莓派,樹莓派相機和TFT屏幕開發一個學生項目。它包括,當拉斯比凸輪檢測到一個臉部時,顯示一部電影,同時沒有檢測到任何臉部顯示其他電影。我寫了如下的代碼。我用python opencv omxplayer庫。當我運行代碼時,如果沒有檢測到臉部,沒有視頻正在播放,但如果檢測到臉部,視頻會非常嚴肅地打開和關閉,視頻不會出現,只有黑色陰影快速出現在屏幕上。感謝您的幫助。問候Raspberry Pi Omxplayer OpenCV
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
import os
import numpy
from subprocess import Popen
#setup movies
movie1 = ("my_movie1_path")
movie2 = ("my_movie2_path")
camera = PiCamera()
camera.resolution = (320, 240)
camera.framerate = 60
rawCapture = PiRGBArray(camera, size=(320, 240))
# Load a cascade file for detecting faces
face_cascade = cv2.CascadeClassifier('my_path/lbpcascade_frontalface.xml')
t_start = time.time()
fps = 0
# Capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
image = frame.array
# Use the cascade file we loaded to detect faces
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray)
print "1"
While True:
if len(faces) > 0 :
os.system('killall omxplayer.bin')
omcx = Popen(['omxplayer', '-b', movie2])
else :
os.system('killall omxplayer.bin')
omcx = Popen(['omxplayer', '-b', movie1])
#print "Found " + str(len(faces)) + " face(s)"
print "2"
rawCapture.truncate(0)
我認爲你應該在這裏解釋更好的問題。我無法理解最後一句話。 –
感謝您的重播,我編輯。 –