0

In my understanding of spec sheets from digital cameras, each output color pixel is made out 4 real pixels on the CCD. However, when reading from a camera, for example using OpenCV, one can get as much as NxMx3 pixels. The two green pixels get averaged.

For what I understood, OpenCV let's you transform from RGB images to grayscale, but couldn't find a way of getting the raw values from the CCD. Of course, it could be that there is a lower level limitation (i.e. the transformation to color space happens on the electronics and not on the computer). Or that there is some interpolation and hence, there are in reality NxM pixels and not NxMx4 pixels in a camera.

Is there any way of getting RAW data from a camera with OpenCV, or is there any information stored in RAW files acquired with commercial cameras?

uı6ʎɹnɯ ꞁəıuɐp
  • 3,431
  • 3
  • 40
  • 49
Aquiles Carattino
  • 910
  • 1
  • 10
  • 23
  • If we're talking about CFA (Bayer) arrays, then there are NxM monochomatic pixels with colour filters arranged in a 2x2 tiled pattern (RGGB and 3 other variants). When demoisaicing, each 2x2 group of CFA pixels becomes a 2x2 group of RGB pixels -- the 8 missing intensities are calculated from the 4 known values. – Dan Mašek Aug 25 '18 at 14:06
  • As for whether you can get raw data from a camera using OpenCV's `VideoCapture` component, that will largely depend on the specific camera and backend you're using. From what I recall, few do give you that option (mostly the industrial camera ones) -- you'll need to dig through [the](https://docs.opencv.org/3.4.2/d4/d15/group__videoio__flags__base.html) [docs](https://docs.opencv.org/3.4.2/dc/dfc/group__videoio__flags__others.html) and even source code. Probably better acquire using other toolkit, and use OpenCV for processing. – Dan Mašek Aug 25 '18 at 14:12
  • 1
    for example FLIR Blackfly cameras can send you bayer pattern instead of RGB pixels. Often such a capturing mode is called raw8, raw12 etc. naming the bits per pixel – Micka Aug 25 '18 at 15:18
  • This may help... https://www.dpreview.com/forums/thread/3495861 – Mark Setchell Aug 25 '18 at 20:08
  • Thanks for the link @MarkSetchell! I will read it carefully, seems quite on topic. Now I see that maybe OpenCV is not the way to go, but still, I am wondering what would be the way to go either with a reflex or with cheaper webcams, in the end all produce the same output. I have used some cameras (like Thorlabs') which exist both with and without the Bayer filter, but still, I never managed to get the pre-demosaicing data. – Aquiles Carattino Aug 26 '18 at 17:51
  • This answer suggests RAW images do contain Bayer data... https://photo.stackexchange.com/a/86174 – Mark Setchell Aug 27 '18 at 16:20
  • Mark, you nailed it! Rawpy is showing exactly what I wanted. I checked with my Nikon raw images and apparently they do actually contain the pre-Bayer demosaicing information. Thanks a lot! – Aquiles Carattino Aug 28 '18 at 14:55

0 Answers0