0

I build a web application and want to use PHP to exec the Python script on the Raspberry Pi. It works, but when I try to open some Python script which includes the OpenCV, nothing happens and there is no error message. I try to run this PHP in the terminal, it works fine, so I don't know what happens?

# -*- coding: utf-8 -*-

import cv2
cap = cv2.VideoCapture(0)                                       
print("VideoCapture is opened?", cap.isOpened())
while(True):
    ret, frame = cap.read()                                      
    center = (frame.shape[1]//2, frame.shape[0]//2)              

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)               
    cv2.circle(gray, center=center, radius=100, color=(0,0,255))
    cv2.imshow("frame", gray)                                    

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()            
cv2.destroyAllWindows()  
plamut
  • 3,085
  • 10
  • 29
  • 40
ye you
  • 1
  • 1
  • Possible duplicate of [Running a Python script from PHP](https://stackoverflow.com/questions/19735250/running-a-python-script-from-php) – Nigel Ren Mar 10 '18 at 07:27
  • I can use php exec the python script, only not work which the python script include the opencv. thanks. – ye you Mar 10 '18 at 07:36

1 Answers1

0

import cv2 cap = cv2.VideoCapture(0) is not valid syntax I do not know if it is the same in your script but you would have to do this instead

import cv2
cap = cv2.VideoCapture(0)
Brett M
  • 178
  • 6