OpenCV: working with 12-bit gray raw data

In the past, I used OpenCv to process 32-bit .bmp files and got successful results. How to use Opencv functions to process 12-bit source data? My processing will be mainly operations such as searching for some of the 1000 pixels and so on.

EDIT The file I get is a .bin file. And the Pixels in Image are placed like this (the file has all the contents like this, because I am taking a picture of white paper):

(FF)(0F)(FF)(0F)(FF)(0F)(FF)(0F)(FF)(0F)(FF)(0F)(FF)(0F) 

It is clear that I can do 16-bit processing.

+4
source share
3 answers

Well, I wanted to do 16-bit processing on this image. The secret then rests on one more question .

For 16 bits I will have to switch to PNG, not bmp!

This document says that I can use 16-bit PNG in OpenCV

+3
source

From what I know, OpenCV handles 8, 16, and 32 bit images correctly.

depending on what you want to do, you should

  • or converting your 12-bit image to 8 bits (provided that it is a 12-bit encoded image with a buyer)
  • or convert it manually to 16, filling the values ​​with zeros. From what I found here , this could already be done in your image.

I would advise you to take a closer look at how your pixels fit exactly in your image before doing anything. This will help you know better which is better. A good way to do this is to use bless or another hex editor.

EDIT:

Taken from here , your data (I think) is encoded more than 16 bits with the addition

Just convert from 16 bits to 8 bits using Opencv, you should do the trick, as this is done when converting to JPEG. Have you at least tried?

+2
source

No OpenCV feature supports 12-bit data.

Read the data as "char". 3 char = 2x12 data bits. This data can be conveniently converted to 16-bit data:

  • Left shift char1 by 4 and save in short1.
  • Add it with (char2 and 0xF0) to get the first 12-bit data short1.
  • Left shift (char2 and 0x0F) by 8 and save in short2.
  • Add it with char3 to get the following 12-bit data short2.
0
source

All Articles