通过在Linux / Apache的PHP脚本访问USB摄像头 [英] Accessing USB webcam via a PHP script on Linux/Apache

查看:876
本文介绍了通过在Linux / Apache的PHP脚本访问USB摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用USB网络摄像头(在小C ++ / OpenCV的应用程序),并从PHP脚本调用它。我的测试应用程序是这样的:

I want to use a USB webcam (in a small C++/OpenCV application) and call it from a PHP script. My test app looks like this:

int main( int argc, char **argv )
{
    cv::VideoCapture C( 0 );

    cout << "C.isOpened() = " << boolalpha << C.isOpened() << endl;

    return 0;
}

PHP脚本是这样的:

The PHP script looks like this:

<?php
exec( escapeshellcmd( '/thepath/theapp' ), $output, $result );

var_dump( $output );
?>

当我直接在命令行中调用这个程序,它会返回真正

When I call this app directly from the command line, it returns true.

当我通过这样的PHP调用应用程序 PHP -f /the_php_script.php 返回真正

When I call the app via php like this php -f /the_php_script.php it returns true.

当我打电话通过PHP从一个HTML文件(按钮)通过AJAX调用,它通过Apache的应用程序,然后返回

When I call the app via php called by AJAX from a html file (with a button), it passes through Apache and then returns false.

所以,我的应用程序工作正常。我的PHP脚本也没关系。但是有一个许可或像这样的prevents PHP的东西,通过Apache访问网络摄像头(带OpenCV库进行初始化)的但权限是足以让应用程序运行

So, my app works fine. My php script works fine too. But there is a permission or something like this that prevents php, via Apache to access the webcam (to initialize it with OpenCV library), but the permission is sufficient to allow the app to run.

有人能帮助我吗?任何想法?

Could someone help me? Any idea?

谢谢!

编辑1:

随着一个建议,我试图用一个PHP脚本,开始我的应用程序,而无需使用AJAX的。我得到了相同的结果,即OpenCV的的无法的初始化服务器上​​的USB摄像头。

Following a suggestion, I tried to used a php script to start my app without the use of AJAX. I obtained the same results, i.e. OpenCV cannot initialized the USB webcam on the server.

推荐答案

有关的那些人可以通过这个问题感兴趣......

For those whom may be interested by the problem...

我面临的问题是两方面:初始化通过从客户端调用PHP脚本的USB摄像头,并开始从这个PHP脚本的应用程序的 的,可以写映像到磁盘文件夹中的 /无功/网络/图片

The problem I was facing was two-fold: initializing the USB webcam via a php script called from the client and starting an application from this php script that could write images to disk in the folder /var/www/images.


  1. 要启用USB摄像头,我只是给用户的 www数据的(阿帕奇)添加到组中的视频的。我发现它通过看我自己的帐号!我看见了,我是这个组的成员,所以它很自然到Apache添加到它太

  2. 要允许应用程序(即从相机拍摄图像)将它们存储在文件夹 /无功/网络/图片我观察到的子文件夹图片属于用户的的,是小组的成员的的。由于这是Apache的运行过的PHP脚本,叫我的申请,我换图片的所有者的 www数据的。

  1. To enable the USB camera, I just had to add the user www-data (Apache) to the group video. I found it by looking at my own account: I saw that I was a member of this group so it seemed natural to add Apache to it too!
  2. To allows the application (that captures images from the camera) to store them in the folder /var/www/images I observed that the subfolder images belonged to user root and was a member of group root. Since it was Apache that ran the php script that called my application, I switched the owner of images to www-data.

正如我们在法国的说...的的!

As we say in French... Voilà!

感谢大家谁给了我一些提示!

Thanks to all of you who gave me some hints!

这篇关于通过在Linux / Apache的PHP脚本访问USB摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆