简体   繁体   English

使用 Android 的相机 2 拍摄灰度照片

[英]Taking grayscale picture with Android's camera2

I am creating an app for taking pictures and sending them via http POST to my server.我正在创建一个用于拍照并通过 http POST 将它们发送到我的服务器的应用程序。 Since I only need grayscale data on the server side, it would by much better to just take the grayscale picture and not having to convert it.由于我只需要服务器端的灰度数据,所以只拍摄灰度图片而不需要转换它会好得多。 I am using Camera2 API and I have an issue with setting properties for CaptureRequest.Builder instance.我正在使用Camera2 API ,但在设置CaptureRequest.Builder实例的属性时CaptureRequest.Builder问题。 With this:有了这个:

final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE, CaptureRequest.CONTROL_EFFECT_MODE_NEGATIVE);

It takes a negative photo.它需要一张负片。 But this:但是这个:

final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE, CaptureRequest.CONTROL_EFFECT_MODE_MONO);

Does absolutely nothing.绝对什么都不做。 No grayscale.没有灰度。 just a normal picture.只是一张普通的图片。

You need to look at the list of supported effects on your device, to see if MONO is actually supported by it.您需要查看设备上支持的效果列表,看看它是否真的支持 MONO。

If you only care about luminance, you could just capture YUV_420_888 buffers instead of JPEG, and only send the Y buffer to the server.如果你只关心亮度,你可以只捕获 YUV_420_888 缓冲区而不是 JPEG,并且只将 Y 缓冲区发送到服务器。 That won't get you automatic JPEG encoding, though.但是,这不会让您自动进行 JPEG 编码。

Also note that generally under the hood, JPEG images are encoded in YUV;另请注意,通常在引擎盖下,JPEG 图像以 YUV 编码; so if you dig into your JPEG decoder library, you may be able to get the image data before conversion to RGB, and simply ignore the chroma channels.因此,如果您深入研究 JPEG 解码器库,您可能能够在转换为 RGB 之前获取图像数据,而只需忽略色度通道。

captureRequestBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE,CameraMetadata.CONTROL_EFFECT_MODE_MONO);

你可以用这个`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM