I am trying to build a facial recognition web app. I run the image capture and processing code via python scripts, and call the python file from php.
The python code works when called via command line, but through php, the cam.read() simply does not capture any frames, and the return value is always false. I do get the cam.isOpened() value to be true though, hence I know that my camera is turned on. It's just that it isn't reading any frames when called via php.
Also, the read() function returns true when I read the frames from a video file rather than the webcam.
Any help on figuring out why would be appreciated! Could it be related to xampp permissions or so? I'm running the xampp server on macOS.
Here's my code:
test.py
import cv2
import time
cam = cv2.VideoCapture(0) #initialize webcam
time.sleep(2) #to warm up camera sensor
retL = [] #to store the frame return values
i = 0
while i < 10:
ret, frame = cam.read() #read frames from webcam
retL.append(ret)
i += 1
cam.release()
print(retL) #returns a list filled with 'False' only when the script is called from php
test.php
<?php
$a = shell_exec('/usr/local/bin/python3 test.py 2>&1');
echo $a;
?>