Precision of RGB Gain

Discussion related to "under the hood" OpenMV topics.
User avatar
chrisPyres66
Posts: 144
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Precision of RGB Gain

Postby chrisPyres66 » Tue Jun 04, 2019 9:18 am

Dear all,

I try to understand how works the gain in OV7725 camera and i am lost without speaking about analog gain.

Firstly, there is the main gain at register address 0x00 which can be used with these both python functions where the gain is in db :
- sensor.set_auto_gain( False, gain_db=(1 to 32db) )
- sensor.get_gain_db()

Secondly, there are the 3 white balance gains at register address 0x01 to 0x03 which can be used with these both python functions where the gain is in db :
- sensor.set_auto_whitebal(False, rgb_gain_db=(-42 to 6db for three colors)
- sensor.get_rgb_gain_db()

I red the c language code, and i did not succeed to understand the equation between db gains and register values ?
Why the ranges are differents for same 8 bits registers ?

I tested to use the main gain in db and i did not succeed to have a good precision.
Here is my code test :

Code: Select all

import sensor, image, time
sensor.reset()                     
sensor.set_pixformat(sensor.GRAYSCALE) 
sensor.set_framesize(sensor.VGA)   
sensor.skip_frames(time = 500)   
sensor.set_auto_whitebal(False)
sensor.set_auto_exposure(False)
gainstart=1
gainstep=0.5
gainend=32
gaindb = gainstart
while(True):
   img = sensor.snapshot()  
   sensor.set_auto_gain(False,gain_db=gaindb)
   time.sleep(100)
   getgaindb=sensor.get_gain_db()
   diff = abs(gaindb - getgaindb)
   print(diff, gaindb, getgaindb)
   gaindb += gainstep
   if gaindb > gainend :
      gaindb = gainstart
where i can have difference of 2db ...

Could you help me to use these gains ?
Thanks,
User avatar
kwagyeman
Posts: 3829
Joined: Sun May 24, 2015 2:10 pm

Re: Precision of RGB Gain

Postby kwagyeman » Tue Jun 04, 2019 12:23 pm

Hi, I turned the values into db because they are unitless otherwise and mean different things on every camera. Please do not expect the values to 100% matchup always for writing and reading. There is quite a bit of precision loss because of how the conversion step works.

Please see the C code for what is actually going on. You can directly read the registers if you don't like the driver wrapper I provided. This will give you the exact values.
Nyamekye,
User avatar
chrisPyres66
Posts: 144
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Re: Precision of RGB Gain

Postby chrisPyres66 » Thu Jun 06, 2019 11:45 am

Thanks,

I tried to modify the gain register at address 0x00 and read the db gain with sensor.get_gain_db().

Here is the code, and it is not linear between register and the db gain.

Code: Select all

import sensor, image, time
sensor.reset()                     
sensor.set_pixformat(sensor.GRAYSCALE) 
sensor.set_framesize(sensor.VGA)   
sensor.skip_frames(time = 500)   
sensor.set_auto_whitebal(False)
sensor.set_auto_exposure(False)
sensor.set_auto_gain(False)
reggain = 0
while(True):
   img = sensor.snapshot()  
   sensor.__write_reg(0x00, reggain)
   time.sleep(100)   
   getgaindb=sensor.get_gain_db()
   print( reggain, "%.1f" % getgaindb)
   reggain += 1
   if reggain > 255 :
      reggain = 0
I red the c language code, and did an excel sheet to understand this :
4 MSB seems to be a factor of 4 LSB like this :
- High = 1 << total_number_of_bit_to_1_of_the_4x_MSB (between 1 to 4, but it is not ordered)
- Low = ( 4xLSB / 16 ) + 1
- db = 20 x ln ( High x Low ) / ln (10)

I dont get the equation and how to use this register without your db way.
I did not find any appnote from omnivision about how to use the 0v7725 gain register ?

Thanks,
User avatar
kwagyeman
Posts: 3829
Joined: Sun May 24, 2015 2:10 pm

Re: Precision of RGB Gain

Postby kwagyeman » Thu Jun 06, 2019 1:06 pm

There's no app note from Omnivision. I'm guessing that's how it works based on an appnote from the OV2640 and OV9965 as that's how OmniVision likes to control their gain registers. It may not actually be correct. Please assume the value you put into the reg is completely opaque.

...

Regarding auto_gain/exposure, I have some fixes to the OV7725 driver coming soon that improve the image quality.
Nyamekye,
User avatar
kwagyeman
Posts: 3829
Joined: Sun May 24, 2015 2:10 pm

Re: Precision of RGB Gain

Postby kwagyeman » Thu Jun 06, 2019 1:06 pm

Omnivision likes to make the top 4 bits of registers a integer gain and the bottom 4 bits a fractional gain of 1/16.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: Houkouha, MSN [Bot] and 5 guests