opencv无法使用shell_exec运行py脚本打开摄像头

时间:2018-07-05 06:01:02

标签: php python linux opencv raspberry-pi

Hei,我正在对我的opencv库进行一些测试,并且已成功完成。 现在,我可以像这样用python运行一些测试脚本

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

if cap.isOpened() == False:
    print('Unable to open the camera')
else:
    print('Start grabbing, press a key on Live window to terminate')
    cv2.namedWindow('Live');
    cap.set(cv2.CAP_PROP_FRAME_WIDTH,320)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT,240)
    while( cap.isOpened() ):
        ret,frame = cap.read()
        if ret==False:
            print('Unable to grab from the camera')
            break

        cv2.imshow('Live',frame)
        #cv2.waitKey(0);
        key = cv2.waitKey(5)
        if key==255: key=-1 #Solve bug in 3.2.0
        if key >= 0:
            break
    print('Closing the camera')

cap.release()
cv2.destroyAllWindows()
print('bye bye!')
quit()

成功,然后打开相机。现在我的问题是我用shell_exec在php脚本中运行py脚本,但无法打开相机。我在python /home/pi/Documents/python_project/face_recognition/test.py目录为/ var / www / html /的终端中运行命令是成功的,它可以打开相机,但是当我返回到我的PHP脚本时仍然没有执行任何操作。这是我的PHP脚本

<?php
shell_exec("/usr/bin/python /home/pi/Documents/python_project/face_recognition/test.py");

如果我在上面的代码行中添加回显,则显示“无法再见!”

谁能知道我必须做什么?我非常感谢。谢谢

0 个答案:

没有答案