java - 佳能相机在一段时间后卡住 - 1200D EOS sdk java

标签 java live-streaming canon-sdk

我们正在使用佳能eos sdk 2.14 进行直播和拍摄。 相机是佳能1200D

以下是相机设置:

直播模式:启用

自动对焦模式:灵活

下面是代码

import java.awt.image.BufferedImage;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.SwingWorker;

import edsdk.api.CanonCamera;
import edsdk.api.commands.FocusModeCommand.Mode;

public class CameraWorker {
    static CanonCamera camera = null;
    public SwingWorker<Void, Void> liveViewWorker = null, shootWorker = null;

    public void startCameraLive() {
        try {
            camera = new CanonCamera();
            if (camera != null && camera.openSession()) {
                if (camera.beginLiveView()) {
                    camera.setFocusMode(Mode.AUTO);
                    camera.setLiveViewMode(true);
                    liveViewWorker = new SwingWorker<Void, Void>() {
                        @Override
                        protected Void doInBackground() throws Exception {
                            try {
                                while (continueLoop) {
                                    try {
                                        Thread.sleep(100);
                                        camera.setLiveViewMode(true);
                                        final BufferedImage image = camera.downloadLiveView();

                                        if (image != null) {
                                                    ///set image to live view
                                        }else{
                                        System.out.println("NO LIVE VIEW>>>>>>>>>>>>>>>>>>>>>>");
                                        }
                                    } catch (Exception e) {
                                        System.out.println("Exception Occured while getting Live View....");
                                        e.printStackTrace();
                                    }
                                }
                            } catch (Exception e2) {
                                e2.printStackTrace();
                            }
                            return null;
                        }

                        protected void done() {
                            try {
                                camera.endLiveView();
                                camera.closeSession();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    };
                    liveViewWorker.execute();
                }else{
                System.out.println("Live View not started.....");
                }
            }
        } catch(Exception e){
            e.printStackTrace();
        }
    }

      public void onFaceCapture() {
          shootWorker = new SwingWorker<Void, Void>() {
                BufferedImage croppedFaceImage;
                @Override
                protected Void doInBackground() throws Exception {
                    File[] camPictures = camera.shoot();

                    if (camPictures != null && camPictures.length > 0) {
                        for (File curFile : camPictures){
                            try {
                                byte[] imageBuffer = FileNDirUtils.getFileBytes(curFile.getAbsolutePath());

                            }catch(Exception e1){
                                System.out.println("ERRORR:::::::::>>>>>>>>"+e1.getMessage());
                            }
                        }
                    }else{
                        System.out.println("camPictures Null");
                    }
                    return null;
                }
                protected void done() {
                    try {

                    ////////set final image to display


                    } catch(Exception e1){
                        System.out.println("ERRORR:::::::::>>>>>>>>"+e1.getMessage() +" reason ::: "+e1.getCause());
                        e1.printStackTrace();
                    }
                    finally {
                        System.out.println("Done in finally........1");
                    }
                }
            };
            shootWorker.execute();
        }
}

在上面的代码中我有两种方法

  1. 启动摄像头直播()
  2. onFaceCapture()

首先我启动实时取景并连续显示下载的图像,当用户单击捕获按钮时,将执行第二个方法。这两种方法的调用如下

SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
        loop = true;
        cameraWorker = new CameraWorker();
        cameraWorker.startCameraLive();
    }
});

第二种方法是这样的

SwingUtilities.invokeLater(new Runnable() {
         @Override
         public void run() {
             timerDisplay.setVisible(false);
             face_position_msg.setVisible(false);
             cameraWorker = new CameraWorker();
             cameraWorker.onFaceCapture();
         }
   });

现在的问题:::

在 5 或 6 次迭代后,相机卡住了,没有任何功能。一切都卡住,关闭应用程序并重新启动应用程序后它不起作用。我们需要拔下相机插头或手动按下相机上的拍摄按钮才能重新开始工作。

一开始设置为启用的直播模式自动变为禁用。我们需要重新设置它。

在 startCameraLive() 中我们设置:::

camera.setFocusMode(Mode.AUTO);

camera.setLiveViewMode(true);

但当相机卡住时,实时取景模式仍会被禁用。

我们怎样才能摆脱这个卡住,我们想知道这个问题的根本原因是什么。一点也不异常(exception):(

请帮忙...

最佳答案

您是否尝试查看 Swingworkers 方法是否适用于:

System.out.println(javax.swing.SwingUtilities.isEventDispatchThread());

或者可能在您的类中添加“extends SwingWorker”?

关于java - 佳能相机在一段时间后卡住 - 1200D EOS sdk java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40067859/

相关文章:

graph - 有没有办法将图形转换为数据?

javascript - 在网站上播放实时视频流

java - JButton 未放置在与其 JPanel 相同的位置

java - 在java中获取zip文件夹中的文件作为字符串

java - Android 媒体编解码器 : How long does it take to decode and display one video frame

ffmpeg - 如何在 ffmpeg 中解密和录制 mpd(破折号)直播视频?

c++ - 通过 Canon EOS SDK (c++) 浏览 SD 卡上的图像

linux-device-driver - Canon DSLR Video 使用 v4l2loopback 和 EDSDK Liveview 环回?

c# - EdsCreateImageRef() 方法给出 EDS_ERR_FILE_FORMAT_UNRECOGNIZED

java - 如何读取 csv 并从每一行中创建 map 列表?