2014-02-25 33 views
0

我想創建一個CGI腳本,將拍攝一張照片,並將其保存到我給它的位置。我正在使用uv4l驅動程序使用Raspberry Pi和Pi相機模塊。我也選擇使用Apache2。樹莓派CGI腳本與OpenCV不保存圖像

當前腳本運行時沒有錯誤,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  

回答

0

我固定我自己的問題。方法imwrite()保存在已有的沒有寫權限的圖像上。