opencv c ++,cvSaveImage 从 php 执行程序时不保存
opencv c++, cvSaveImage not saving when program is executed from php
我正在OS X(狮子)上使用opencv c ++(eclipse)编写一个人脸检测应用程序。 该程序加载图像文件,检测人脸,然后将每个人脸保存到单独的文件中。 该程序 100% 工作,因为它是从命令行或在 eclipse 中。 然后我编写了一个用于文件上传的 php 脚本,以便有人可以上传 jpg 或 png 文件,然后脚本使用唯一的文件名保存照片。 然后在 php 脚本结束时,我让它执行人脸检测程序。
我不确定从命令行运行应用程序并让 php 调用应用程序运行有什么区别。 这是我下面的代码。
C++ 中的函数:
cvNamedWindow ("ROI", CV_WINDOW_AUTOSIZE);
cvCvtColor( clone, gray, CV_RGB2GRAY );
cvSetImageROI ( gray, *r);
//// * rectangle = cvGetImageROI ( clone );
*r = cvGetImageROI ( gray );
cvShowImage ("ROI", gray);
k++;
char *name=0;
name=(char*) calloc(512, 1);
sprintf(name, "/Users/jason/Sites/jason.dev/images/proc_images/Image%d.png", k);
cvSaveImage(name, gray);
PHP脚本:
<?php
mysql_connect("127.0.0.1:3306","xxxx","xxxx");
mysql_select_db("opencv_development");
$uploaddir = "images/";
$file = basename($_FILES['uploadedfile']['name']);
$stamp = date("YmdHis");
$random = rand(0, 999);
$newName = $uploaddir . $stamp . $random . $file;
if ($_FILES['uploadedfile']['size']> 300000) //Limiting image at 300K
{
exit("Your file is too large.");
}
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $newName)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
mysql_query("INSERT INTO recv_img (photo_name) VALUES ('$newName')");
shell_exec("./opencv '$newName'");
?>
正如我上面所说,如果我从终端运行应用程序,那么它会输出单个人脸文件。当它从php脚本执行时,图像加载到应用程序中,它执行人脸检测,但不保存单个人脸文件。
如果需要任何进一步的信息,或者我不清楚某事,请告诉我。 任何帮助将不胜感激!
cvSaveImage
返回的整数可以帮助您查找是否存在错误。
在测试和查看OpenCV源代码后,似乎最新版本不使用cvSetErrStatus
来处理文件错误,但errno
似乎设置正确。
if(!cvSaveImage(name, gray)) {
int error = cvGetErrStatus();
const char * errorMessage = 0;
if (error) {
errorMessage = cvErrorStr(error);
} else {
error = errno; // needs #include <cerrno>
errorMessage = strerror(error); // #include <cstring>
}
std::cout << errorMessage << std::endl;
// with "echo shell_exec("./opencv '$newName'");" in php
}
如果返回的错误是"权限被拒绝",您可以检查用户是否真的是您认为的用户,然后echo shell_exec('whoami');
。
相关文章:
- 程序在执行程序的其余部分之前退出
- libprotobuf 检查在 Mac OS 上执行程序时失败
- 是否可以依赖函数范围的静态变量来执行程序关闭期间调用的方法?
- 在另一台 PC 上执行程序时加载 SDL2 共享库时出错
- 从 GUI 文件资源管理器执行程序,并且不生成终端
- 测试操作系统时执行程序集"sti"时虚拟框崩溃
- 数据库连接并将数据从C ++程序保存到MySQL
- Windows桌面程序保存您的计算机会话 - 基于程序崩溃时的恢复会话
- 重新执行C++程序会加快速度
- 如何用共享库替换可执行C++程序的功能?
- 编译并执行C#程序中的C++代码
- 如果我在 Linux 上更改C++动态共享库,而我的可执行程序在其上使用,会发生什么
- 在C++中,系统如何将这些对象中的每一个与执行程序的窗口相关联?
- 命令行参数执行C 程序
- 有没有办法在C++应用程序的多次执行中保存值?
- 按 e 执行程序C++
- 在返回另一个函数的函数中执行程序期间出错
- 如何使用"trusty"映像在本地执行C++程序的Travis CI?
- opencv c ++,cvSaveImage 从 php 执行程序时不保存
- 在Emacs中保存-编译-执行c++程序的快捷方式