Canon eos SDK 2.14 を使用して、ライブ ストリーミングと撮影を行っています。カメラはキャノン1200D
以下はカメラ設定です:
ライブストリーミングモード:有効
AFモード:フレキシ
以下はコードです
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();
}
}
上記のコードには2つのメソッドがあります
- startCameraLive()
- onFaceCapture()
最初にライブ ビューを開始し、ダウンロードした画像を継続的に表示します。ユーザーがキャプチャ ボタンをクリックすると、2 番目の方法が実行されます。両方のメソッドは以下のように呼び出されます
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
loop = true;
cameraWorker = new CameraWorker();
cameraWorker.startCameraLive();
}
});
このような2番目の方法
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);
ただし、カメラが動かなくなると、ライブ ビュー モードが無効になります。
この問題を解決するにはどうすればよいでしょうか。また、この問題の根本的な原因を知りたいと考えています。例外はまったくありません:(
助けてください...