嗨,我正在尝试改进自己,我对树莓派感兴趣。我想开发一个学生项目与覆盆子皮,覆盆子皮相机和tft屏幕。它包括,当raspi摄像机检测到一张脸时,显示一部电影,而不检测到任何面部显示另一部电影。我写了如下代码。我使用了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 )发布于 2017-01-26 13:42:38
这里的问题是在时间指令内。当程序在while循环中检测到一张脸时。在这里,程序继续杀死omxplayer并启动电影。
尝试删除while循环并查看代码是否有效。
https://stackoverflow.com/questions/41874352
复制相似问题