简体   繁体   中英

Gphoto2 fails to save image when captured via Java .jar (Raspberry Pi - Raspbian)

I'm writing a GUI application which takes an image from a camera using the gphoto2 package in Raspbian. When I enter the command gphoto2 --capture-image-and-download into the terminal manually, the camera takes an image and saves it to the current folder. However, when I execute the same command via a button in my Java code, the camera takes the image but it is not saved. Redirected output from bash says that the image is saved to the camera (which I could cope with) but the image is neither saved to the camera or to the current directory, in fact, it doesn't appear to be saved at all.

Here is the button code:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    Runtime com = getRuntime();
    try {
        //Reset USB Device to prevent warnings
        Process mand = com.exec("../../../usbreset /dev/bus/usb/001/005");

        //Capture image
        Process get = com.exec("gphoto2 --capture-image-and-download");

        Send Bash output(s) to text area
        BufferedReader in1 = new BufferedReader(new InputStreamReader(mand.getInputStream()));
        BufferedReader in2 = new BufferedReader(new InputStreamReader(get.getInputStream()));
        String inputLine1;
        while ((inputLine1 = in1.readLine()) != null) {
            msgArea.append(inputLine1 + "\n");
        }
        in1.close();
        String inputLine2;
        while ((inputLine2 = in2.readLine()) != null) {
            msgArea.append(inputLine2 + "\n");
        }
        in2.close();


    } catch (IOException ex) {
        Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
    }
}          

I can't work out if the problem resides in my bash commands or my Java code. I've tried both with and without a card present in the camera, and have also tried with a specified filename for the image, all to no avail. I'm not sure if it's significant but the Pi is being controlled via PuTTY ssh with X11 forwarding on a Debian laptop. Java is written in Netbeans 8. GPhoto2 is version 2.4.14 and the camera is a Canon EOS 1100D, though I suspect this last fact is surplus to requirements.

I'd be really grateful if anyone could help - this is an important part of my final year project at University, so I must be able to get it sorted soon!

Thanks in advance,

Guy

OK I've answered my own question.

The output from bash was only being sent up until the point the picture was taken. After that, terminal output was not being sent and so I was missing an error, a Permission Denied jobbie. So the solution was just to add a sudo before the gphoto2 command. Simple solution in the end but a frustrating situation!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM