waveform80 / picamera

A pure Python interface to the Raspberry Pi camera module
https://picamera.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.57k stars 357 forks source link

[Docmentation] How to find out the Bayer pattern from the CFA layout #714

Open astrorafael opened 2 years ago

astrorafael commented 2 years ago

I'm reading the excellent picamera documentation (thank you so much!) and I have now a better idea of how the sensor works. I'd like to perform some RAW Bayer data captures myself, so began reading section 4.5 Raw Bayer data captures

At some point, the example code states that the OV5647 sensor Bayer pattern is BGGR and then, it shows the equivalent pixel CFA as

GBGBGBGBGBGBGB RGRGRGRGRGRGRG GBGBGBGBGBGBGB RGRGRGRGRGRGRG

I simply do not get how the BGGR pattern is deducted from the layout.

For instance, reading 2x2 from top, left I would read GBRG For instance, reading 2x2 from bottom, left I would read RGGB

I would be very grateful if you could expand the comments so that the BGGR pattern can be easily seen from the layout depicted.

6by9 commented 2 years ago

It is contradictory. If it is BGGR, then the layout would be

BGBGBGBGBGBGBG
GRGRGRGRGRGRGR

The layout illustrated would be GBRG.

As noted just after that,

# Please note that if you use vflip or hflip to change the orientation
# of the capture, you must flip the Bayer pattern accordingly

so you need to know which sensor you are dealing with, and the flips in effect in order to be able to know the Bayer order.

Or you can look at offset 268 (if I've counted correctly) into the header which contains the Bayer order: 0 - RGGB 1 - GBRG 2 - BGGR 3 - GRBG dcraw uses this header to get the order - https://github.com/6by9/dcraw/blob/master/dcraw.c#L6466

astrorafael commented 2 years ago

Ok, so this is a typo in the example CFA layout in the documentation. Good to know. Should be trivial to fix it quickly.

I have also downloaded the OV 5647 datasheet and on page 25, figure 3-1 shows the chip CFA pattern with the BG/GR patterns as expected,