Raspberry Pi Omxplayer OpenCV

Raspberry Pi Omxplayer OpenCV

您好,我正在努力提高自己,我对 Raspberry Pi 很感兴趣。我想用 raspberry pi、raspberry pi 摄像头和 tft 屏幕开发一个学生项目。它包括,当 raspi cam 检测到人脸时,显示一部电影,而没有检测到任何人脸时显示另一部电影。我写了如下代码。我使用了 python opencv omxplayer 库。当我运行代码时,如果没有检测到人脸,则没有视频播放但是如果检测到人脸,视频打开和关闭非常严重,视频不出现,只有黑影来来去去快速筛选。感谢您的帮助。问候

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 )

这里的问题出在 while 指令中。当程序在 while 循环中检测到人脸时。这里程序继续杀掉omxplayer,开始播放电影。
尝试删除 while 循环并查看代码是否有效。