Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 带有OpenCV的Raspberry Pi CGI脚本不保存图像_C++_Opencv_Apache2_Cgi_Raspberry Pi - Fatal编程技术网

C++ 带有OpenCV的Raspberry Pi CGI脚本不保存图像

C++ 带有OpenCV的Raspberry Pi CGI脚本不保存图像,c++,opencv,apache2,cgi,raspberry-pi,C++,Opencv,Apache2,Cgi,Raspberry Pi,我正在尝试创建一个CGI脚本,它将拍摄一张照片并保存到我指定的位置。我正在使用Raspberry Pi和带有uv4l驱动程序的Pi摄像头模块。我还选择使用Apache2 当前,脚本运行时没有给出任何错误,Apache错误日志中也没有错误,但映像没有保存。相机确实打开了,因为它上面出现了红灯。我还检查图像是否为空 到目前为止,我已尝试更改文件夹权限,以便用户pi拥有一切。我还试图保存一个已经存在的文件,但它从未得到更新。我以前从未使用过Apache2或CGI脚本,所以我觉得问题就在这里,但我不完全

我正在尝试创建一个CGI脚本,它将拍摄一张照片并保存到我指定的位置。我正在使用Raspberry Pi和带有uv4l驱动程序的Pi摄像头模块。我还选择使用Apache2

当前,脚本运行时没有给出任何错误,Apache错误日志中也没有错误,但映像没有保存。相机确实打开了,因为它上面出现了红灯。我还检查图像是否为空

到目前为止,我已尝试更改文件夹权限,以便用户pi拥有一切。我还试图保存一个已经存在的文件,但它从未得到更新。我以前从未使用过Apache2或CGI脚本,所以我觉得问题就在这里,但我不完全确定搜索什么,因为我没有得到任何错误。如有任何建议,将不胜感激

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char** argv){

    cv::VideoCapture cap(-1);
    if (!cap.isOpened()){
            cout << "Content-type:text/html\r\n\r\n";
            cout << "<html>";
            cout << "<h1> Camera didn't open </h1>";
            cout << "</html>";
            return -1;
    }
    //cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
    //cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
    int count = 40;
    cv::Mat frame;
    bool bSuccess = cap.read(frame);
    while (count != 0){
            count--;
    }
    if (!bSuccess){

            cout << "Content-type:text/html\r\n\r\n";
            cout << "<html>";
            cout << "<h1> Photo did't work get read in</h1>";
            cout << "</html>";

            return 0;
    }

    cout << "Content-type:text/html\r\n\r\n";
    cout << "<html>";
    cout << "<h1> Photo Taken + Saved</h1>";
    cout << "</html>";
    cv::imwrite("/var/www/photos/Current.png", frame);

    return 0;
}

我解决了自己的问题。imwrite()方法在没有写入权限的情况下对已存在的映像进行保存

g++ -lopencv_core -lopencv_highgui -L/usr/lib/uv4l/uv4lext/armv6l -luv4lext -Wl,-  rpath,'/usr/lib/uv4l/uv4lext/armv6l' time.cpp -o test_script.cgi