gpt4 book ai didi

python - 树莓派 Omxplayer OpenCV

转载 作者:太空宇宙 更新时间:2023-11-03 22:49:22 25 4
gpt4 key购买 nike

您好,我正在努力提高自己,我对 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 循环并查看代码是否有效。

关于python - 树莓派 Omxplayer OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41874352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com