1

I have an embedded linux board with a LAMP server running. Everything works fine. So my problem is now to call a python script from a website. That's my python script:

#!/usr/bin/env python2

import cv2.cv as cv
print cv.__version__
print '<br>'
capture = cv.CaptureFromCAM(0)

print  capture
print '<br>'
img = cv.QueryFrame(capture)
cv.SaveImage("/srv/http/BMWneu.jpg",img)
print 'Picture taken'

It is executable and runs fine in the commandline in arch linux. But if I start it from the web interface only party will be executed in the script. So only the print commands and the include is working.

My php file looks like this:

<?php
$result=shell_exec("python2 capture.py");

echo $result
?>

And the output in the browser is this:

2.4.12.2

Picture taken

So both opencv commands are being ignored. Can anybody help me?

Sven R.
  • 1,049
  • 17
  • 24
Elron27
  • 31
  • 3
  • 1
    Sounds like the user under which the webserver is run doesn't have permission to access the camera and / or write to disk. Capture the `stderr` and see what traceback is being produced: `shell_exec("python2 capture.py 2>&1");` – Martijn Pieters Mar 11 '16 at 08:15
  • There is a second line that is empty. So it looks like `capture` is empty. What happens if you execute the Python script directly in the shell? –  Mar 11 '16 at 08:15
  • if i run it directly in the shell i get: 2.4.12.2

    Picture taken so everything works fine. @ Martijn Pieters: If i put your code in the php nothing happens anymore.
    – Elron27 Mar 11 '16 at 08:44
  • @Elron27: sorry, not a PHP dev here. All I did was consult the `shell_exec` documentation to see if and how you could include the stderr output from a command in the result captured. – Martijn Pieters Mar 11 '16 at 09:04
  • I didn't managed to make the stderr output even with the `shell_exec` documentation. But i figured out that the php script is the `http` user on my linux board. Is it possible that he are not allowed to execute the cv2 command? Does anybody know how to do the settings for the userrights? – Elron27 Mar 14 '16 at 08:06

0 Answers0