来自图库视频的姿势检测

Pose detection from a gallery video

我正在尝试 运行 ML Kit 通过使用以下代码对来自 phone 图库的视频进行姿势检测(我尝试遵循文档 Detect Poses with ML KIT):

public class MainActivity extends AppCompatActivity {
    Button pick;
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        pick = findViewById(R.id.elegir);
        videoView = findViewById(R.id.video);
        mc = new MediaController(MainActivity.this);
        videoView.setMediaController(mc);

        pick.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                Intent pickintent = new Intent(Intent.ACTION_GET_CONTENT);
                pickintent.setType("video/*");
                startActivityForResult(pickintent, 1);
            }
        });
    }

    @Override
    public void onActivityResult(int requestcode, int resultcode, Intent data){
        super.onActivityResult(requestcode, resultcode, data);
        if(requestcode == 1 ){
            Uri videouri = data.getData();
            PoseDetectorOptions options =
                    new PoseDetectorOptions.Builder()
                            .setDetectorMode(PoseDetectorOptions.STREAM_MODE)
                            .build();
            PoseDetector poseDetector = PoseDetection.getClient(options);

            InputImage image = null;
            try {
                image = InputImage.fromFilePath(getApplicationContext(), videouri);
            } catch (IOException e) {
                e.printStackTrace();
            }

            Task<Pose> result =
                    poseDetector.process(image)
                            .addOnSuccessListener(
                                    new OnSuccessListener<Pose>() {
                                        @Override
                                        public void onSuccess(Pose pose) {
                                            // Task completed successfully
                                            // ...
                                         
                                        }
                                    })
                            .addOnFailureListener(
                                    new OnFailureListener() {
                                        @Override
                                        public void onFailure(@NonNull Exception e) {
                                            // Task failed with an exception
                                            // ...
                                            
                                        }
                                    });
        }
    }
}

错误日志:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.mlkit, PID: 11193
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/video:31 flg=0x1 }} to activity {com.example.mlkit/com.example.mlkit.MainActivity}: java.lang.NullPointerException: InputImage can not be null
        at android.app.ActivityThread.deliverResults(ActivityThread.java:5015)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:5056)
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.NullPointerException: InputImage can not be null
        at com.google.android.gms.common.internal.Preconditions.checkNotNull(com.google.android.gms:play-services-basement@@17.6.0:2)
        at com.google.mlkit.vision.common.internal.MobileVisionBase.processBase(com.google.mlkit:vision-common@@16.5.0:11)
        at com.google.mlkit.vision.pose.internal.PoseDetectorImpl.process(com.google.mlkit:pose-detection-common@@17.1.0-beta3:2)
        at com.example.mlkit.MainActivity.onActivityResult(MainActivity.java:93)
        at android.app.Activity.dispatchActivityResult(Activity.java:8310)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:5008)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:5056) 
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7656) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 

我想知道在这种情况下 运行 姿势检测的正确方法。我知道 InputImage 出了问题,但我不知道如何修复它

class 称为 InputImage 而不是 InputVideo,因此当您使用 fromFilePath 时,它需要一个图像文件而不是视频文件。

以下是 Github 关于使用视频文件作为输入的一些回答:https://github.com/googlesamples/mlkit/issues?q=is%3Aissue+in%3Atitle+%22video+file%22+

基本上,您需要将视频分成单独的帧并为每个帧构造 InputImage。