简体   繁体   English

通过Java .jar捕获时,Gphoto2无法保存图像(Raspberry Pi-Raspbian)

[英]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. 我正在编写一个GUI应用程序,该应用程序使用Raspbian中的gphoto2包从相机获取图像。 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. 当我在终端中手动输入命令gphoto2 --capture-image-and-download ,相机会拍摄一张图像并将其保存到当前文件夹中。 However, when I execute the same command via a button in my Java code, the camera takes the image but it is not saved. 但是,当我通过Java代码中的按钮执行相同的命令时,相机会拍摄图像,但不会保存图像。 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. 从bash重定向的输出表示图像已保存到相机(我可以应付),但是图像既没有保存到相机也没有保存到当前目录,实际上,它似乎根本没有保存。

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. 如果问题出在我的bash命令或Java代码中,我无法解决。 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. 我不确定它是否重要,但是Pi是通过PuTTY ssh通过Debian笔记本电脑上的X11转发进行控制的。 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. Java是用Netbeans 8编写的。GPhoto2是2.4.14版,相机是Canon EOS 1100D,尽管我怀疑这最后一个事实对要求来说是多余的。

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. bash的输出仅被发送直到拍摄照片为止。 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. 因此解决方案是在gphoto2命令之前添加一个sudo Simple solution in the end but a frustrating situation! 最终简单的解决方案却令人沮丧!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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