so I'm trying to execute a python file version 3.9 file using php via VScode and safari browser I spent hours trying to figure out what is the problem because it keep giving me null result
here is my code on php file
<?php
$result = shell_exec("/usr/bin/python3 fr/fr_load.py");
var_dump($result);
?>
I tried other python file with only print command and they worked just fine so my connection is fine but I can't figure out what is the problem
my python code is
#!/usr/bin/python3
#import the required libraries
import cv2
import joblib
from sys import exit
from sklearn.feature_extraction.text import CountVectorizer
import pandas as pd
# function to detect face from image
def face_detection(image_to_detect):
#converting the image to grayscale since its required for eigen and fisher faces
image_to_detect_gray = cv2.cvtColor(image_to_detect, cv2.COLOR_BGR2GRAY)
# load the pretrained model for face detection
# haarcascade is recommended for Eigenface
face_detection_classifier = cv2.CascadeClassifier('php/fr/models/haarcascade_frontalface_default.xml')
# detect all face locations in the image using classifier
all_face_locations = face_detection_classifier.detectMultiScale(image_to_detect_gray)
# if no faces are detected
if (len(all_face_locations) == 0):
return None, None
#splitting the tuple to get four face positions
x,y,width,height = all_face_locations[0]
#[0] cuz we assume we have only one face on our data set
#calculating face coordinates
face_coordinates = image_to_detect_gray[y:y+width, x:x+height]
#for traning and testting all images should be at same size (for egien)
face_coordinates = cv2.resize(face_coordinates,(500,500)) #we can use any number fit for us
#return the face detected and face location
return face_coordinates, all_face_locations[0] #all_face_locations[0] beacuse there is only one face in each image
names =[]
names.append("steve jobs")
names.append("ali alramadan")
names.append("hillary clinton")
#########load recognition model for later use ###########
face_classifier = cv2.face.EigenFaceRecognizer_create()
face_classifier.read("php/fr/models/our model.yml")
######## prediction ##############
#path of the image we want to test and predict
image_to_classify = cv2.imread("php/fr/dataset/testing/load.jpg")
#make a copy of the image cuz we dont want to ruin the actual image by writing on it
image_to_classify_copy = image_to_classify.copy()
#get the face from the image
face_coordinates_classify, box_locations = face_detection(image_to_classify_copy)
#if no faces are returned
if face_coordinates_classify is None:
print("There are no faces in the image to classify")
exit()
#if face is returned then predict the face
name_index, distance = face_classifier.predict(face_coordinates_classify) #if distance is big then there is big different between the train image and test image
name = names[name_index]
distance = abs(distance)
print(name)
#draw bounding box and text for the face detected
(x,y,w,h) = box_locations
cv2.rectangle(image_to_classify,(x,y),(x+w, y+h),(0,255,0),2)
cv2.putText(image_to_classify,name,(x,y-5),cv2.FONT_HERSHEY_PLAIN,2.5,(0,255,0),2)
#show the image in window
cv2.imshow("Prediction "+name, cv2.resize(image_to_classify, (500,500)))
cv2.waitKey(0)
cv2.destroyAllWindows()
any suggestions please?