Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to create a CGI script that will take a picture and save it to the location I give it. I'm using the Raspberry Pi and the Pi camera module with the uv4l driver. I have also chosen to use Apache2.

Currently the script runs with no errors given and no errors in the Apache error log, but the image doesn't get saved. The camera does open because the red light appears on it. I also check to see if the image is empty which it isn't.

So far I have tried changing folder permissions so that the user pi owns everything. I have also tried to save over an already existing file but it never gets updated. I have never used Apache2 or CGI scripting before so I feel that the problem lies in there but I'm not entirely sure what to search because I am getting no errors. Any suggestions would be greatly appreciated.

#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;
}

I'm using this command to compile:

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    
share|improve this question

1 Answer 1

up vote 0 down vote accepted

I fixed my own problem. The method imwrite() was saving over an already existing image without write permissions.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.