I have some OpenCV python code to capture images and save it to disk. This code is working fine when I run it from cmd or from PowerShell it works fine. But when I run it from PHP it runs but not works properly. Here is my python code:
import cv2, sys, json
import numpy as np
faceDetect = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cam = cv2.VideoCapture(0)
Id = 1
i = 1
while (True):
ret, img = cam.read()
grayImg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceDetect.detectMultiScale(grayImg, 1.3, 5)
for (x, y, w, h) in faces:
cv2.imwrite("dataset/user_" + str(Id) + "_" + str(i) + ".jpg", grayImg[y : y + h, x : x + w])
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
i += 1
cv2.waitKey(100)
cv2.imshow("Camera", img)
cv2.waitKey(1)
if (i > 20):
break
cam.release()
cv2.destroyAllWindows()
Here is my PHP code:
<?php
exec('C:\\Python27\\python.exe C:\\xampp\\htdocs\\atmp\\face_recognition\\dataset_creator.py');
?>
Is there any specific reason to not working properly? Any answer will be appreciated. Thanks in advance :)