I have an executable file developed using opencv library in c. I want to execute it from my website (webserver : apache) using a php script. The problem i'm facing is that, t开发者_JAVA技巧he executable code opens a window(kind of gui, opened using cvNamedWindow) when called from terminal but it doesn't do that when called from the embedded php script. For execution i have tried exec, system, passthru etc but all these failed.
to be more clear : name of executable -> gui, name of phpscript(page) ->abcd.php
@terminal if i type "./gui" ... window opens.
@ terminal, if itype "php abcd.php" window opens
abcd.php is part of my website. In web browser if i open "http://...../abcd.php", window DOESNOT open. Although other things in the executable work perfectly. They get printed if i pass them back as arguments to exec.
Any solutions??
Update
thanks for the replies.. I'll put my question this way.. There is an executable which runs on the client. It has a gui through which user can connect to the server and receive a video stream which can be seen inside the gui. This executable runs fine when executed on terminal. Since php can also call an executable, i am trying through a web page so that i can add some more features. But the program is NOT executing the same way as it was, when executed at terminal.
If you just need a window for the app to run properly, you could try creating a fake one by running it in a virtual X-server using xvfb. This is not going to be very efficient, but at least your app will execute without crashing.
Now if you are talking about launching the app on the client, I don't think that is something that you could reasonably expect to work unless the client actually downloads the code you are trying to run and voluntarily executes your program. In general, web browsers are not supposed to run native machine code from arbitrary web sites.
I had the same problem as you and it has taken two months for me to solve this problem.
Finally, I put opencv_highgui220d.dll
and opencv_core220d.dll
in the dir of the index.php
and it works!
More details, the following is my environment:
OS: Windows Vista SP1
HTTP server: Appserv2.5.10(Apache2.2.8 + php5.2.6)
Root: C:/Appserv/www/test
Root contains.
index.php:
<?php
exec("cv.exe", $out, $val);
echo $val;
?>
cv.cpp:
#include "stdafx.h"
#include <cv.h>
#include <highgui.h>
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
Mat img = imread("a.jpg");
if(!img.data) return -1;
imwrite("b.jpg",img);
return 0;
}
Use Visual Studio 2010 to compile,
Project setting:
Use Run-Time Library: /Mtd
VC++ > Include Directories:
C:\Program Files\OpenCV2.2\include
C:\Program Files\OpenCV2.2\include\opencv
VC++ > Library Directory
C:\Program Files\OpenCV2.2\lib
Linker > Additional Dependencies:
C:\Program Files\OpenCV2.2\lib\opencv_core220d.lib
C:\Program Files\OpenCV2.2\lib\opencv_highgui220d.lib
C:\Program Files\OpenCV2.2\lib\opencv_video220d.lib
C:\Program Files\OpenCV2.2\lib\opencv_ml220d.lib
C:\Program Files\OpenCV2.2\lib\opencv_legacy220d.lib
C:\Program Files\OpenCV2.2\lib\opencv_imgproc220d.lib
After Building, put cv.exe
into web root, but get error message and get return value: 0xc0000135
( In $val
).
Google the code and know it is loss some dll, use Dependency walker (http://www.dependencywalker.com/) to know it needs opencv_highgui220d.dll
and opencv_core220d.dll
.
So put them into web root.
精彩评论