简体   繁体   English

如何在相机预览中消除滚动快门效果?

[英]How to remove rolling shutter effect in camera preview?

I'm trying to send data to my phone by filming a blinking LED.我正在尝试通过拍摄闪烁的 LED 来将数据发送到我的手机。 This works fine most of the time, but for some frames I get a rolling shutter effect in my camera preview, which messes up my data transfer.这在大多数情况下都可以正常工作,但是对于某些帧,我的相机预览中会出现滚动快门效果,这会扰乱我的数据传输。 Is there a way to remove this rolling shutter effect?有没有办法消除这种卷帘效应?

I am working with Google's cameraAPI2 and a Nexus 6 (but I've seen the same effect on a Samsung S7).我正在使用 Google 的 cameraAPI2 和 Nexus 6(但我在三星 S7 上看到了同样的效果)。 I record at 20 fps and the LED blinks at a frequency of 20 Hz.我以 20 fps 的速度录制,LED 以 20 Hz 的频率闪烁。 My images have a format of 320x240 with YUV_420_888.我的图像格式为 320x240,带有 YUV_420_888。 Here are my current settings for a CaptureRequest:这是我当前对 CaptureRequest 的设置:

CONTROL_AE_MODE CONTROL_AE_MODE_OFF CONTROL_AE_MODE CONTROL_AE_MODE_OFF

CONTROL_AWB_MODE CONTROL_AWB_MODE_OFF CONTROL_AWB_MODE CONTROL_AWB_MODE_OFF

EDGE_MODE EDGE_MODE_OFF EDGE_MODE EDGE_MODE_OFF

CONTROL_MODE CONTROL_MODE_OFF CONTROL_MODE CONTROL_MODE_OFF

SENSOR_EXPOSURE_TIME 500000 SENSOR_EXPOSURE_TIME 500000

SENSOR_FRAME_DURATION 50000000 SENSOR_FRAME_DURATION 50000000

I've already tried playing with exposure time and frame duration to no effect.我已经尝试过使用曝光时间和帧持续时间,但没有效果。 The same effect can be observed by simply opening the stock camera app and filming a LED close up.只需打开股票相机应用程序并拍摄 LED 近景,即可观察到相同的效果。 Example例子

The right half of the picture shows the old frame and the left half shows the new frame.图片右半部分为旧框架,左半部分为新框架。

Is there a way to fix this?有没有办法来解决这个问题? Does Android have camera vsync? Android 有摄像头垂直同步吗?

Edit : I changed the frequencies to 20Hz.编辑:我将频率更改为 20Hz。

Edit 2 : I got it working by performing Canny Edge Detection and then Standard Hough Line Transformation on the image using opencv.编辑 2 :我通过使用 opencv 对图像执行 Canny 边缘检测和标准霍夫线变换来使其工作。 After getting the line coordiantes from the Hough Line Transformation, I checked if the line is horizontal.从霍夫线变换中得到线坐标后,我检查了线是否水平。 Then I split the image along this line and only used the larger area for my calculations.然后我沿着这条线分割图像,只使用较大的区域进行计算。

Rolling shutter effects stem from the fact that cameras with CMOS image sensor most often read out the pixel data sequentially, row by row (or column by column), so separate rows/columns that make up one image frame are not captured at the same point in time.卷帘快门效应源于具有 CMOS 图像传感器的相机通常逐行(或逐列)顺序读取像素数据,因此构成一个图像帧的单独行/列不会在同一点捕获及时。

There is no "camera vsync" since rolling shutter is a physical property of how the image sensor is built.没有“相机垂直同步”,因为卷帘快门是图像传感器构建方式的物理属性。

Apart from switching to a global shutter image sensor (like a CCD or some newer CMOS sensors) you can try increasing the shutter speed/reducing exposure time of your camera to minimize the problem.除了切换到全局快门图像传感器(如 CCD 或一些较新的 CMOS 传感器)之外,您还可以尝试提高相机的快门速度/减少曝光时间以尽量减少问题。

You can consult this question as a concrete direction how to find out available shutter speeds for your camera.您可以参考这个问题作为如何找出相机可用快门速度的具体方向。

Update: what you can try is setting the shutter speed of your camera to the fastest setting and then matching your LED blinking frequency with your camera frame rate (1/30s).更新:您可以尝试将相机的快门速度设置为最快设置,然后将 LED 闪烁频率与相机帧速率(1/30 秒)相匹配。 This way the blinking of the LED should always be at the same time point of the image acquisition and you shouldn't get any problems with rolling shutter effects anymore.这样,LED 的闪烁应该始终在图像采集的同一时间点,并且您不应该再遇到卷帘快门效果的任何问题。

Update2: as discussed in the comments, your setup now seems to work like this. Update2:正如评论中所讨论的,您的设置现在似乎是这样工作的。 You have a LED that can change it's state (on or off) every 50 ms.您有一个 LED 可以每 50 毫秒更改一次 state(开或关)。 You have a camera that captures a scene over the course of 50 ms to produce one image.您有一台相机,它可以在 50 毫秒的时间内捕获一个场景以生成一张图像。 Leftmost column is at the beginning of these 50 ms, rightmost column is at the end of these 50 ms (or vice versa, you need to figure that out).最左边的列是这 50 毫秒的开始,最右边的列是这 50 毫秒的结束(反之亦然,你需要弄清楚)。 Since the 50 ms period of the LED is not synchronized with the 50 ms capture time of the camera, a state change of the LED will probably happen in the middle of the camera image that is produced, this splits the image apart in a dark and a bright half.由于 LED 的 50 ms 周期与相机的 50 ms 捕获时间不同步,因此 LED 的 state 变化可能会发生在所产生的相机图像的中间,这会将图像在黑暗中分开,明亮的一半。

Here is how a random LED sequence might look like on the image:以下是随机 LED 序列在图像上的样子:

LED sequence:   ... 0  |  1  |  1  |  0  |  1  |  0  |  0  |  0 ...

Image sequence: ... | 0 1 | 1 1 | 1 0 | 0 1 | 1 0 | 0 0 | 0 0 | ...

The pipes denote when the LED may change state and when the image finishes one frame capture.管道表示 LED 何时可能更改 state 以及图像何时完成一帧捕获。

As you can see in the drawing, assuming the frequencies are the same the divide in the image between old and new state is always going to stay at the same image column.正如您在图中看到的,假设频率相同,新旧 state 之间的图像分界将始终保持在同一图像列。 All you have to do is detect where the line divides the image (should be doable with some computer vision) and then only always look at one half of the image to see if that half changes.您所要做的就是检测线在哪里分割图像(应该可以通过一些计算机视觉实现),然后只查看图像的一半以查看那一半是否发生变化。 Ideally you should look at the half which is recorded later since that one is giving you the most up to date information from the LED.理想情况下,您应该查看稍后记录的那一半,因为那会为您提供来自 LED 的最新信息。

I hope that helps.我希望这会有所帮助。

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

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