簡體   English   中英

我的應用無法識別 usb 外置攝像頭(前后攝像頭都可以識別,即使我可以使用它們),我正在使用 Android Camera2 API

[英]My app doesn’t recognize the usb external camera (front and back camera are recognized, even i can use them), I’m using the Android Camera2 API

我的應用無法識別 usb 外置攝像頭(前后攝像頭都可以識別,即使我可以使用它們),我正在使用 Android Camera2 API。 我沒有使用它(ICameraProvider 接口),因為我真的不知道如何使用它。 我已經在motorola one action (Android 10.0) 和 LG 3 stylus (Android 7.0) 上對其進行了測試。

第一個問題:我需要使用ICameraProvider接口嗎,怎么用? https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/master/camera/provider/2.4/ICameraProvider.hal

第二個問題:“外部 USB 相機”Android 文檔的實施部分是針對開發人員的,還是我應該做任何步驟? https://source.android.com/devices/camera/external-usb-cameras

第三個問題:我應該根我的手機嗎?

我的一些代碼(此代碼僅識別前后攝像頭,但不識別 usb 攝像頭):

package com.example.camera10;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.hardware.usb.UsbManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CameraManager;



import java.util.HashMap;


@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class IdCameras extends AppCompatActivity {

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_id_cameras);

        Intent intent = getIntent();




        CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
        try {
            String[] idList = manager.getCameraIdList();

            Log.d("Available Cameras", String.valueOf(idList.length));

            TextView textView = findViewById(R.id.textView);
            textView.setText(String.valueOf(idList.length));

            int maxCameraCnt = idList.length;

            for (int index = 0; index < maxCameraCnt; index++) {
                String cameraId = manager.getCameraIdList()[index];



                Log.d("Camera", cameraId);
                CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
                StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
            }
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }

        // Capture the layout's TextView and set the string as its text

    }
}

在此處輸入圖像描述

Android 手機不需要支持外部網絡攝像頭。 您找到的說明適用於制造商,以幫助他們使網絡攝像頭顯示在攝像頭2 API 中。

如果制造商沒有決定支持網絡攝像頭,您的選擇是使用 USB API 並在您的應用程序中實現完整的 UVC 網絡攝像頭堆棧(有可用的庫)。 或者,如果您只關心特定的 Android 設備,並且可以為其制作自定義圖像,則可以按照找到的說明在設備上啟用網絡攝像頭支持。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM