OpenCV imwrite is not working
<p>I have a simple OpenCV application that takes a video stream from the webcam, and when the <code>spacebar</code> is pressed it captures the current image and freezes on that image. When I try to use the <code>cv::imwrite()</code> method to save the picture to disk, it does not work. The code successfully compiles but it does not save the image. It is returning a false value as well from the call. I am not sure if this is an issue of type of image or something else, but I seem to be stumped.</p>

<p>Here is the code for my current cpp class:</p>

<pre><code>#include &lt;iostream&gt;

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace std;
using namespace cv;

Mat picture;
char key;

class FacialRec {

};

int main() {
    //Starting the video
    VideoCapture videoCapture(0);

    if (!videoCapture.isOpened()) {
        cout &lt;&lt; "Unable to open video file." &lt;&lt; endl;
        return 1;
    }

    namedWindow("Webcam", CV_WINDOW_AUTOSIZE);

    while(true) {
        Mat frame;
        videoCapture.retrieve(frame);
        bool success = videoCapture.read(frame);

        if (!success) {
            cout &lt;&lt; "Could not read from video file" &lt;&lt; endl;
            return 1;
        }

        imshow("Webcam", frame);
        key = waitKey(30);

        if (key == 27) { //escape key pressed: stop program
            cout &lt;&lt; "ESC pressed. Program closing..." &lt;&lt; endl;
            break;
        }else if (key == ' ') { //spacebar pressed: take a picture
            picture = frame;
            key = -1;

            while (true) {
                imshow("Webcam", picture);

                key = waitKey(30);

                if (key == 27 || key == 32) {
                    cout &lt;&lt; "ESC or SPACE pressed. Returning to video..." &lt;&lt; endl;
                    break;
                }

                if (key == 115) {
                    //trying to save to current directory
                    bool maybe = imwrite("/testimage.jpg", picture);
                    // maybe bool is always getting value of 0, or false
                   cout &lt;&lt; "s was pressed. saving image " &lt;&lt; maybe &lt;&lt; endl;
                }   
            }
        }

    }

    return 0;
}
</code></pre>