php 接摄像头数据,通过在Linux / Apache的PHP脚本访问USB摄像头

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;

}

The PHP script looks like this:

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

var_dump( $output );

?>

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

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

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.

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?

Thanks!

EDIT 1:

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...

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.

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!

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!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值