簡體   English   中英

具有OpenCV的Raspberry Pi CGI腳本不保存圖像

[英]Raspberry Pi CGI script with OpenCV not saving images

我正在嘗試創建一個CGI腳本,該腳本將拍攝一張圖片並將其保存到我給它的位置。 我正在將Raspberry Pi和Pi相機模塊與uv4l驅動程序一起使用。 我還選擇使用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;
}

我正在使用以下命令進行編譯:

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    

我解決了自己的問題。 imwrite()方法保存了沒有寫權限的現有映像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM