0

So basically im trying to run my opencv python script (detects either Blue, yellow or green) with a php code in my raspi through localhost

however it doesnt seem to run whenever i press the button to run the said script, i tried running it through the shell itself and it runs fine

This is the code for running the opencv app

if(isset($_GET['project'])){
    echo shell_exec("python3 cvtest.py");
}

and this is the python file (should return a string, which it does from shell but not when in the php file) [OpenCV app] (https://1drv.ms/u/s!ArBHaZP1appfo0cYjggXnUGVaeWf?e=owY29m)

Edit1: By the way the opencv is installed through pip-install opencv-python

Edit2: so i tried running the py app as www-data (which it does when run from localhost) and it says that "cant open camera by index 0" so how can i allow www-data to access the camera

Marc5799
  • 1
  • 4
  • Hey Marc5799 welcome to SO! `echo` in php does just that.. it echo's out the contents of something. I believe you're looking for something [like this](https://stackoverflow.com/questions/19735250/running-a-python-script-from-php) – FullStackOfPancakes Nov 10 '19 at 02:33
  • Does that mean the python app itself will not run? – Marc5799 Nov 10 '19 at 02:36
  • It will run if you call it the way it's referenced in the answer I linked to there. That's why it runs when you call it from the shell but not when you just `echo` it out here. It's not actually being run anywhere yet. – FullStackOfPancakes Nov 10 '19 at 02:39
  • Unforunately it still doesnt work, I tried doing the said steps but still not running and no indication that the python app runs (camera LED should light up at least) – Marc5799 Nov 10 '19 at 07:03
  • Maybe try browsing [this answer](https://www.raspberrypi.org/forums/viewtopic.php?t=186159) ? – FullStackOfPancakes Nov 10 '19 at 23:43
  • 1
    Thanks, that did the job. and editing some ownerships to make gpio and camera work – Marc5799 Nov 11 '19 at 07:26

0 Answers0