我怎样才能在安卓系统上裁剪每一帧摄像机的实时画面?[英] How can I crop the live feed from the camera on each frame on Android?

本文是小编为大家收集整理的关于我怎样才能在安卓系统上裁剪每一帧摄像机的实时画面?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有我想裁剪的相机的视频预览.

但是,裁剪窗口正在逐帧(裁剪窗口的尺寸和位置).

.

我如何在Android(Flutter,Kotlin,Java,nativecript,..没关系)上实现这一目标才能在某种程度上显示实时裁剪结果并能够保存结果?<<

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

如何逐帧从摄像头裁剪实时视频,然后预览并保存到文件?

i 创建(部分)我在Javascript中想要的东西,只是为了表明我的意思.在JavaScript中,我使用html视频标签(这可以从网络摄像头获取feed),然后创建一个帆布,并可以将视频标签的每个帧读取为数据,然后选择我想要的东西从帧到帧.

 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.getBitMap 将裁剪的视图读取到位图,然后保存.

如果您需要更高分辨率或更高质量的捕获,则需要与相机单独的输出.选项要么是捕获JPEG,对其进行解码,裁剪产生的位图并重新编码(假设您要保存JPEG),或者捕获未压缩的YUV,裁剪它,然后将其转换为位图.

camerax android支持库可能会节省您很多时间设置高质量的路径,尽管我认为您仍然需要为Imagecapture用例的输出而进行裁剪.

本文地址:https://www.itbaoku.cn/post/2091155.html

问题描述

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.