안드로이드 스튜디오 캡처 이미지 더 빠르게 (android studio capture image faster)


문제 설명

안드로이드 스튜디오 캡처 이미지 더 빠르게 (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İERAndrea Caruso)

참조 문서

  1. android studio capture image faster (CC BY‑SA 2.5/3.0/4.0)

#capture #camera #handler #Android #surfaceview






관련 질문

Java 제네릭: 캡처를 사용한 컴파일 실패 (Java generics: compilation failure using captures)

Python 함수 호출에서 stdout 출력을 캡처하는 방법은 무엇입니까? (How to capture stdout output from a Python function call?)

캡처한 이미지 캡처 및 공유를 구현하고 싶습니다. (I want to implement capture and sharing captured image)

Ambilight용 Python 화면 캡처(더 적은 리소스 집약적) (Python Screen Capture for Ambilight (less resource intensive))

Windows에서 "비디오 컨트롤러"에 대한 Java 액세스 (Java Access To "Video Controller" In Windows)

libpcap으로 PPP 패킷을 스니핑하는 방법은 무엇입니까? (How to sniff PPP packet with libpcap?)

DVB-T 스틱에서 AVI 파일로 캡처하는 방법 (How to capture from a DVB-T Stick to an AVI-File)

xlib를 사용하여 키 누름 이벤트 캡처 (capture key press event using xlib)

앱에서 HTTPS 트래픽을 캡처하고 싶지만 작동하지 않습니다. (I want to Capture HTTPS Traffic from app but it does not work)

Selenium-wire Python을 사용하여 네트워크 트래픽을 캡처하는 동안 다른 형식의 로그 보기 (Seeing logs in a different format while capturing network traffic using selenium-wire python)

Android 애플리케이션의 특정 프레임 내 자동 촬영 기능 (Auto picturing feature within specific frame in Android application)

안드로이드 스튜디오 캡처 이미지 더 빠르게 (android studio capture image faster)







코멘트