如何在Android的每一帧上从相机中裁剪实时供稿? [英] How can I crop the live feed from the camera on each frame on Android?

查看:258
本文介绍了如何在Android的每一帧上从相机中裁剪实时供稿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有要裁剪的摄像机的视频预览.

但是裁剪窗口正在逐帧改变(裁剪窗口的大小和位置).

我该如何在Android上实现此目标(flutter,kotlin,java,nativescript等,都无所谓),以便能够在视图中显示实时裁剪结果并将结果保存到文件中? /p>

我不需要代码,我只是不知道要使用哪些库和api(也链接文档),以及如何解决该问题的概念.

如何逐帧裁剪摄像机的实时视频并预览并保存到文件?

创建了(部分)我在Javascript中想要的东西,只是为了说明我的意思.在Javascript中,我使用HTML视频标签(可以从网络摄像头获取提要),然后创建Canvas,可以读取视频标签的每一帧作为数据,并逐帧精确地选择我想要的内容.

 let a = 10;
 processor.computeFrame = function computeFrame() {
       let frame = ctx.getImageData(a,0, this.width*0.5 +a, this.height); // here I use a moving window from left to right for the crop
       ctx2.drawImage(frame, 0, 0); // and draw it back to the view (second canvas)
       a +=0.1; //move the window
};

如何在Android中解决此问题?

我不希望有一个完整的代码...如果您有任何好的文章,教程或文档,我应该开始阅读以实现这一目标,那将是完美的!

有趣的文章

解决方案

如果您只想裁剪预览,则可以使用TextureView并更新其 CameraX And​​roid支持库可以为您节省很多时间设置高质量的路径,尽管我认为您仍然需要对ImageCapture用例的输出进行裁剪.

I have the video preview from the camera which I want to crop.

But the cropping window is changing frame by frame (size and position of the cropping window).

How could I achieve this on Android (flutter, kotlin, java, nativescript,.. doesn't matter) to be able to show the live cropping results in a view and also be able to save the result to file?

I don't want the code, I just don't know which libraries and api's to use (link too documentation) and how the concept should be solved for this problem.

How to crop the live video from camera frame by frame and preview and save to file?

I created (partially) what I want in Javascript, just to show what I mean. In Javascript I use a HTML Video-tag (this could get the feed from the Webcam) then I create a Canvas and can read each frame of the video-tag as data and select exactly what I want from frame to frame.

 let a = 10;
 processor.computeFrame = function computeFrame() {
       let frame = ctx.getImageData(a,0, this.width*0.5 +a, this.height); // here I use a moving window from left to right for the crop
       ctx2.drawImage(frame, 0, 0); // and draw it back to the view (second canvas)
       a +=0.1; //move the window
};

How can I solve this in Android?

I don't expect a fully working code... if you have any good articles, tutorials or documentation where I should start to read to achieve this, it would be perfect!

Interesting article:

解决方案

If you just wanted to crop preview, you could use a TextureView and update its transform matrix to match your desired crop rectangle.

If all you need is an occasional screen grab at the same resolution as preview for saving, you could use TextureView.getBitmap to read the cropped view to a Bitmap, and then save it.

If you need a higher-resolution or higher-quality capture, you'll need a separate output from the camera. Options are either capturing JPEG, decoding it, cropping the resulting Bitmap, and re-encoding it (assuming you want to save a JPEG, anyway), or capturing uncompressed YUV, cropping it, and then converting it to a Bitmap.

The CameraX Android support library might save you a lot of time in setting up the high-quality path, though I think you still need to do the cropping yourself for the output of the ImageCapture use case.

这篇关于如何在Android的每一帧上从相机中裁剪实时供稿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆