문제 설명
안드로이드 스튜디오 캡처 이미지 더 빠르게 (android studio capture image faster)
카메라 응용 프로그램 프로젝트가 있고 200ms 간격으로 두 장의 사진을 찍고 싶습니다. 그러나 일반적으로 450‑550ms 간격으로 사진을 촬영합니다. 어떻게 하면 사진을 더 빨리 찍을 수 있습니까? 카메라 표면 보기를 열고 버튼 핸들러를 누르면 타이머가 시작되고 시간이 60000밀리초에 도달하면 카메라가 첫 번째 이미지를 캡처하고 200ms 후에 두 번째 이미지를 캡처합니다.
제목
public class camerax_timer extends AppCompatActivity {
private TextureView textureView;
TextView editColor;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camerax_timer);
editColor=findViewById(R.id.textcolor);
textureView = findViewById(R.id.view_finder);
textureView.post((Runnable)(new Runnable()
{
public final void run()
{
startCamera();
}
}));
textureView.addOnLayoutChangeListener(new View.OnLayoutChangeListener()
{
@Override
public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft,
int oldTop, int oldRight, int oldBottom)
{
updateTransform();
}
});
Button button_ileri=findViewById(R.id.ileri_image);
button_ileri.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent =new Intent(camerax_timer.this,veri_hesaplama.class);
startActivity(intent);
}
});
}
private void startCamera()
{
PreviewConfig.Builder previewConfig = new PreviewConfig.Builder();
Preview preview = new Preview(previewConfig.build());
preview.setOnPreviewOutputUpdateListener(new Preview.OnPreviewOutputUpdateListener()
{
@Override
public void onUpdated(Preview.PreviewOutput output)
{
ViewGroup parent = (ViewGroup) textureView.getParent();
parent.removeView(textureView);
parent.addView(textureView, 0);
textureView.setSurfaceTexture(output.getSurfaceTexture());
updateTransform();
}
});
ImageCaptureConfig.Builder imageCaptureConfig = new ImageCaptureConfig.Builder();
final ImageCapture imageCapture = new ImageCapture(imageCaptureConfig.build());
final Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
imageCapture.takePicture(new ImageCapture.OnImageCapturedListener() {
@Override
public void onCaptureSuccess(ImageProxy image, int rotationDegrees) {
ImageView imageView = findViewById(R.id.img1);
imageView.setImageBitmap(imageProxyToBitmap(image));
imageView.setRotation(rotationDegrees);
image.close();
}
});
}
}, 60000);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
imageCapture.takePicture(new ImageCapture.OnImageCapturedListener() {
@Override
public void onCaptureSuccess(ImageProxy image, int rotationDegrees) {
ImageView imageView = findViewById(R.id.img2);
imageView.setImageBitmap(imageProxyToBitmap(image));
imageView.setRotation(rotationDegrees);
image.close();
}
});
}
}, 60200);
}
});
CameraX.bindToLifecycle(this, preview, imageCapture);
}
private void updateTransform()
{
Matrix matrix = new Matrix();
float centerX = textureView.getWidth() / 2f;
float centerY = textureView.getHeight() / 2f;
float rotationDegrees = 0;
matrix.postRotate(‑rotationDegrees, centerX, centerY);
textureView.setTransform(matrix);
}
private Bitmap imageProxyToBitmap(ImageProxy image)
{
ImageProxy.PlaneProxy planeProxy = image.getPlanes()[0];
ByteBuffer buffer = planeProxy.getBuffer();
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}
}
</code></pre>
참조 솔루션
방법 1:
Every device camera and every device OS has its time to be ready to take a photo, expecially after taking another photo.
The best solution for you is to take a video and then load and analyze it.
To register a video, you can use the MediaRecorder class.
To get single frames from the video, you should use the wseemann.media.FFmpegMediaMetadataRetriever library, because the standard MediaMetadataRetriever is a little bugged.
This library allows you to get single frame this way:
tempImage = retriever.getFrameAtTime(time, MediaMetadataRetriever.OPTION_CLOSEST);
where
- "tempImage" is a Bitmap,
- "retriever" is a FFmpegMediaMetadataRetriever,
- "time" is the time you want to take the frame from in microseconds.
(by Mehmet DİRİER、Andrea Caruso)
참조 문서