Arducam 64mp gain problem tuning file

Hi,

I recently found a weird behaviour on the new Arducam 64mp Hawkeye:
While taking a video the gain seems to stick always on the upper edge (tuning file allows only 6) and we get a stable brightness.
If I allow more than 6 the gain starts jumping between some states and the image is flashing (daylight).
If I dimm the lights the image stabilizes since the gain is sticking to the new higher edge.

I just want to increase the brightness in low light conditions, which looks great with higher gains, but now under daylight I get this weird flashing…

Can someone explain this behaviour?

Best regards
Daniel

Hi,
Sorry for keeping you waiting.
If you want to fulfill your project’s requirements, you need to adjust the tuning file on your side. You can refer to the official document.

Hi Dion,

thank you very much for the answer!
I already worked with this document a long time and maybe I am just missing something.

The goal: I want to increase the image brightness for a 30fps video especially at low light conditions.

I tried to increase it via "base_ev " which is useless (dimming is working though), since a maximum “gain” of “6” is allowed. → Even with default “base_ev” the image wants to get brighter, but it simply can not, due to the limited gain list in the tuning file.

If I then just increase the allowed “gain” values (up to “10.0”) the image looks perfect at low light conditions, but at daylight a flashing occurs. The “AGC” seems to go crazy.

Can you reproduce the problem by just extending the gain list in the tuning file up to 10.
Am I doing something wrong or is the problem out of my hand?

I am using just a simple "libcamera-vid -n -t 0 --width 1920 --height 1080 --framerate 30 -b 3000000… " command and the following tuning file where only the “gain” list is extended until “10.0”:

{
    "version": 2.0,
    "target": "bcm2835",
    "algorithms": [
        {
            "rpi.focus":{
                
            }
        },
        {
            "rpi.black_level":
            {
                "black_level": 4096
            }
        },
        {
            "rpi.dpc":
            {
            }
        },
        {
            "rpi.lux":
            {
                "reference_shutter_speed": 29966,
                "reference_gain": 2.03,
                "reference_aperture": 1.0,
                "reference_lux": 910,
                "reference_Y": 13551
            }
        },
        {
            "rpi.noise":
            {
                "reference_constant": 0,
                "reference_slope": 2.271
            }
        },
        {
            "rpi.geq":
            {
                "offset": 151,
                "slope": 0.00766
            }
        },
        {
            "rpi.sdn":
            {
                "deviation":3.7,
                "strength":0.75	
            }
        },
        {
            "rpi.awb":
            {
                "priors":
                [
                    {
                        "lux": 0, "prior":
                        [
                            2000, 1.0, 3000, 0.0, 13000, 0.0
                        ]
                    },
                    {
                        "lux": 800, "prior":
                        [
                            2000, 0.0, 6000, 2.0, 13000, 2.0
                        ]
                    },
                    {
                        "lux": 1500, "prior":
                        [
                            2000, 0.0, 4000, 1.0, 6000, 6.0, 6500, 7.0, 7000, 1.0, 13000, 1.0
                        ]
                    }
                ],
                "modes":
                {
                    "auto":
                    {
                        "lo": 2500,
                        "hi": 8000
                    },
                    "incandescent":
                    {
                        "lo": 2500,
                        "hi": 3000
                    },
                    "tungsten":
                    {
                        "lo": 3000,
                        "hi": 3500
                    },
                    "fluorescent":
                    {
                        "lo": 4000,
                        "hi": 4700
                    },
                    "indoor":
                    {
                        "lo": 3000,
                        "hi": 5000
                    },
                    "daylight":
                    {
                        "lo": 5500,
                        "hi": 6500
                    },
                    "cloudy":
                    {
                        "lo": 7000,
                        "hi": 8600
                    }
                },
                "bayes": 1,
                "ct_curve":
                [
                    2700.0, 0.8952, 0.3556, 3000.0, 0.8303, 0.3715, 4000.0, 0.6272, 0.4695, 4150.0, 0.5957, 0.4938, 6500.0, 0.4706, 0.6255
                ],
                "sensitivity_r": 1.0,
                "sensitivity_b": 1.0,
                "transverse_pos": 0.01339,
                "transverse_neg": 0.01002
            }
        },
        {
            "rpi.agc":
            {
                "metering_modes":
                {
                    "centre-weighted":
                    {
                        "weights":
                        [
                            3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0
                        ]
                    },
                    "spot":
                    {
                        "weights":
                        [
                            2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                        ]
                    },
                    "matrix":
                    {
                        "weights":
                        [
                            1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
                        ]
                    }
                },
                "exposure_modes":
                {
                    "normal":
                    {
                        "shutter":
                        [
                            100, 10000, 30000, 30100, 30200, 30300, 30400, 30500
                        ],
                        "gain":
                        [
                            1.0, 2.0, 4.0, 6.0, 7.0, 8.0, 9.0, 10.0
                        ]
                    },
                    "short":
                    {
                        "shutter":
                        [
                            100, 5000, 10000, 20000, 120000
                        ],
                        "gain":
                        [
                            1.0, 2.0, 4.0, 6.0, 6.0
                        ]
                    }
                },
                "constraint_modes":
                {
                    "normal":
                    [
                        {
                            "bound": "LOWER", "q_lo": 0.98, "q_hi": 1.0, "y_target":
                            [
                                0, 0.5, 1000, 0.5
                            ]
                        }
                    ],
                    "highlight":
                    [
                        {
                            "bound": "LOWER", "q_lo": 0.98, "q_hi": 1.0, "y_target":
                            [
                                0, 0.5, 1000, 0.5
                            ]
                        },
                        {
                            "bound": "UPPER", "q_lo": 0.98, "q_hi": 1.0, "y_target":
                            [
                                0, 0.8, 1000, 0.8
                            ]
                        }
                    ]
                },
                "y_target":
                [
                    0, 0.16, 1000, 0.165, 10000, 0.17
                ]
            }
        },
        {
            "rpi.alsc":
            {
                "omega": 1.3,
                "n_iter": 100,
                "luminance_strength": 0.5,
                "calibrations_Cr":
                [
                    {
                        "ct": 6500, "table":
                        [
                            2.189, 2.197, 2.203, 2.204, 2.203, 2.195, 2.189, 2.189, 2.189, 2.194, 2.204, 2.212, 2.215, 2.218, 2.213, 2.211,
                            2.196, 2.202, 2.206, 2.205, 2.201, 2.192, 2.189, 2.183, 2.184, 2.191, 2.198, 2.211, 2.218, 2.219, 2.218, 2.213,
                            2.198, 2.206, 2.206, 2.205, 2.199, 2.191, 2.182, 2.177, 2.177, 2.184, 2.196, 2.207, 2.219, 2.225, 2.225, 2.219,
                            2.199, 2.206, 2.206, 2.202, 2.197, 2.187, 2.176, 2.164, 2.164, 2.177, 2.188, 2.205, 2.218, 2.229, 2.229, 2.223,
                            2.203, 2.203, 2.204, 2.199, 2.194, 2.178, 2.164, 2.147, 2.142, 2.163, 2.178, 2.199, 2.216, 2.228, 2.228, 2.224,
                            2.206, 2.206, 2.203, 2.199, 2.192, 2.175, 2.149, 2.139, 2.133, 2.139, 2.165, 2.193, 2.212, 2.225, 2.225, 2.224,
                            2.208, 2.208, 2.208, 2.203, 2.193, 2.175, 2.149, 2.139, 2.133, 2.139, 2.165, 2.193, 2.211, 2.225, 2.225, 2.224,
                            2.215, 2.217, 2.217, 2.213, 2.204, 2.189, 2.172, 2.149, 2.147, 2.162, 2.172, 2.194, 2.211, 2.223, 2.223, 2.223,
                            2.222, 2.224, 2.229, 2.226, 2.214, 2.204, 2.188, 2.172, 2.171, 2.172, 2.184, 2.198, 2.211, 2.221, 2.221, 2.217,
                            2.224, 2.231, 2.233, 2.231, 2.226, 2.214, 2.201, 2.188, 2.184, 2.184, 2.191, 2.198, 2.211, 2.212, 2.214, 2.207,
                            2.224, 2.233, 2.235, 2.234, 2.229, 2.219, 2.209, 2.198, 2.191, 2.191, 2.196, 2.201, 2.203, 2.208, 2.204, 2.195,
                            2.219, 2.226, 2.234, 2.234, 2.231, 2.222, 2.212, 2.203, 2.196, 2.196, 2.198, 2.202, 2.202, 2.203, 2.195, 2.192
                        ]
                    }
                ],
                "calibrations_Cb":
                [
                    {
                        "ct": 6500, "table":
                        [
                            1.329, 1.329, 1.329, 1.337, 1.347, 1.355, 1.363, 1.367, 1.366, 1.359, 1.351, 1.342, 1.331, 1.321, 1.319, 1.317,
                            1.329, 1.329, 1.334, 1.339, 1.349, 1.358, 1.367, 1.373, 1.373, 1.366, 1.356, 1.344, 1.333, 1.322, 1.319, 1.315,
                            1.329, 1.334, 1.339, 1.349, 1.356, 1.365, 1.373, 1.379, 1.376, 1.373, 1.361, 1.348, 1.339, 1.329, 1.319, 1.315,
                            1.337, 1.343, 1.349, 1.356, 1.365, 1.374, 1.379, 1.383, 1.383, 1.376, 1.367, 1.356, 1.346, 1.337, 1.327, 1.319,
                            1.345, 1.351, 1.358, 1.366, 1.374, 1.379, 1.384, 1.387, 1.387, 1.382, 1.374, 1.364, 1.354, 1.344, 1.334, 1.326,
                            1.352, 1.358, 1.366, 1.374, 1.379, 1.386, 1.391, 1.393, 1.391, 1.387, 1.379, 1.369, 1.358, 1.347, 1.336, 1.326,
                            1.356, 1.362, 1.369, 1.377, 1.385, 1.389, 1.393, 1.395, 1.394, 1.388, 1.379, 1.369, 1.358, 1.347, 1.336, 1.326,
                            1.356, 1.362, 1.369, 1.377, 1.383, 1.388, 1.393, 1.394, 1.393, 1.387, 1.377, 1.367, 1.356, 1.346, 1.334, 1.326,
                            1.353, 1.359, 1.364, 1.369, 1.377, 1.383, 1.388, 1.389, 1.387, 1.381, 1.371, 1.361, 1.351, 1.341, 1.331, 1.324,
                            1.349, 1.353, 1.359, 1.363, 1.368, 1.374, 1.379, 1.381, 1.381, 1.371, 1.362, 1.353, 1.344, 1.335, 1.326, 1.319,
                            1.345, 1.346, 1.349, 1.353, 1.358, 1.364, 1.369, 1.369, 1.368, 1.362, 1.354, 1.344, 1.336, 1.327, 1.319, 1.318,
                            1.345, 1.345, 1.345, 1.349, 1.353, 1.358, 1.361, 1.361, 1.361, 1.355, 1.347, 1.338, 1.331, 1.322, 1.319, 1.318
                        ]
                    }
                ],
                "luminance_lut":
                [
                    3.893, 3.682, 3.101, 2.704, 2.357, 2.074, 1.985, 1.977, 1.977, 1.977, 2.041, 2.316, 2.666, 3.057, 3.627, 3.831,
                    3.682, 3.175, 2.714, 2.418, 2.072, 1.856, 1.712, 1.636, 1.636, 1.689, 1.821, 2.028, 2.376, 2.678, 3.128, 3.627,
                    3.177, 2.839, 2.421, 2.072, 1.847, 1.579, 1.434, 1.359, 1.359, 1.416, 1.545, 1.801, 2.028, 2.376, 2.797, 3.128,
                    2.991, 2.621, 2.206, 1.851, 1.579, 1.428, 1.226, 1.151, 1.151, 1.208, 1.395, 1.545, 1.801, 2.151, 2.579, 2.949,
                    2.915, 2.479, 2.061, 1.709, 1.433, 1.226, 1.146, 1.015, 1.013, 1.127, 1.208, 1.395, 1.661, 2.001, 2.433, 2.876,
                    2.915, 2.419, 1.989, 1.641, 1.361, 1.151, 1.015, 1.007, 1.001, 1.009, 1.127, 1.325, 1.594, 1.934, 2.371, 2.876,
                    2.915, 2.419, 1.989, 1.641, 1.361, 1.151, 1.013, 1.004, 1.001, 1.005, 1.127, 1.325, 1.594, 1.934, 2.371, 2.876,
                    2.922, 2.493, 2.063, 1.709, 1.434, 1.223, 1.146, 1.012, 1.008, 1.127, 1.205, 1.399, 1.666, 2.013, 2.449, 2.884,
                    3.009, 2.634, 2.209, 1.849, 1.582, 1.434, 1.223, 1.146, 1.146, 1.205, 1.399, 1.556, 1.811, 2.168, 2.601, 2.971,
                    3.221, 2.867, 2.437, 2.088, 1.849, 1.582, 1.441, 1.365, 1.365, 1.425, 1.556, 1.811, 2.059, 2.403, 2.836, 3.186,
                    3.755, 3.221, 2.759, 2.437, 2.088, 1.871, 1.726, 1.652, 1.652, 1.711, 1.846, 2.059, 2.403, 2.748, 3.186, 3.723,
                    3.951, 3.755, 3.157, 2.739, 2.383, 2.099, 2.019, 2.016, 2.016, 2.016, 2.086, 2.353, 2.713, 3.136, 3.723, 3.911
                ],
                "sigma": 0.005,
                "sigma_Cb": 0.005
            }
        },
        {
            "rpi.contrast":
            {
                "ce_enable": 1,
                "gamma_curve":
                [
                    0, 0, 1024, 5040, 2048, 9338, 3072, 12356, 4096, 15312, 5120, 18051, 6144, 20790, 7168, 23193,
                    8192, 25744, 9216, 27942, 10240, 30035, 11264, 32005, 12288, 33975, 13312, 35815, 14336, 37600, 15360, 39168,
                    16384, 40642, 18432, 43379, 20480, 45749, 22528, 47753, 24576, 49621, 26624, 51253, 28672, 52698, 30720, 53796,
                    32768, 54876, 36864, 57012, 40960, 58656, 45056, 59954, 49152, 61183, 53248, 62355, 57344, 63419, 61440, 64476,
                    65535, 65535
                ]
            }
        },
        {
            "rpi.ccm":
            {
                "ccms":
                [
                    {
                        "ct": 2700, "ccm":
                        [
                            1.24141, 0.35437, -0.59578, -0.51309, 1.87147, -0.35838, -0.31548, -1.11436, 2.42984
                        ]
                    },
                    {
                        "ct": 3000, "ccm":
                        [
                            1.46878, -0.28074, -0.18804, -0.41877, 1.41722, 0.00154, -0.12837, -0.98072, 2.10909
                        ]
                    },
                    {
                        "ct": 4000, "ccm":
                        [
                            1.43532, -0.25531, -0.18002, -0.35574, 1.46911, -0.11336, -0.12509, -0.60778, 1.73287
                        ]
                    },
                    {
                        "ct": 4150, "ccm":
                        [
                            1.70003, -0.58839, -0.11165, -0.43727, 1.47037, -0.03311, -0.13077, -0.51345, 1.64422
                        ]
                    },
                    {
                        "ct": 6500, "ccm":
                        [
                            1.53197, -0.25773, -0.27423, -0.32591, 1.57394, -0.24803, -0.17084, -0.30841, 1.47925
                        ]
                    }
                ]
            }
        },
        {
            "rpi.sharpen":
            {
                "threshold":1.5,
                "strength":0.5,
                "limit":0.2	
            }
        }
    ]
}

Thank you very much for your support!

Hi everyone,
sorry for making confusion :smiley:
I found the problem finally… I just had to update the setup, there was a overflowing unsigned integer (-> not uint64_t) in agc.cpp which is fixed since march…

Thank you guys anyways!

Everything works fine till gain setting is raised to 9.0 as the digital gain stays at 1. When you go to gain settings of 10 as in your tuning file then the digital gain starts increasing and the image becomes more ‘white’, then the analog gains tries to drop to reduce that whiteness and then it turns dark. This hunting cycle goes on and creates the blinking white videos that you are seeing.

@piyush
Thanks for the info!
I have not fully tested the new version so far the blinking is gone…
In case the problem you just described occurs, do you know how to fix that chasing behaviour?

Keep the gain below or equal to 9 and it should be fine.