feat: camera tuning + capturing command + raw image correction

This commit is contained in:
2026-02-17 14:42:50 +03:00
parent 9c4f12d45e
commit 5b8db82894
7 changed files with 579 additions and 70 deletions
@@ -129,7 +129,7 @@ public class BGGR_PISP_COMP1_RAW_FrameDecoder : IFrameDecoder // BGGR_PISP_COMP1
public ColorSpace.YcbcrEncodingEnum YcbcrEncodingEnum => ColorSpace.YcbcrEncodingEnum.None;
public ColorSpace.RangeEnum RangeEnum => ColorSpace.RangeEnum.Full;
public Mat Decode(int width, int height, int stride, List<byte[]> planes)
public Mat Decode(int width, int height, int stride, List<byte[]> planes, double rGain, double gGain, double bGain, int blackLevel)
{
// Дектоирование этого формата состоит из двух этапов:
// 1) Распаковка исходных данных в которых каждые 8 байт представляют 8 пикселей (это не значит что 1 байт представляет 1 пиксель!)
@@ -137,7 +137,7 @@ public class BGGR_PISP_COMP1_RAW_FrameDecoder : IFrameDecoder // BGGR_PISP_COMP1
if (planes.Count < 1)
throw new ArgumentException($"At least 1 plane expected, got {planes.Count}");
var pixelCount = width * height;
var unpackedSum = new uint[pixelCount];
@@ -153,6 +153,27 @@ public class BGGR_PISP_COMP1_RAW_FrameDecoder : IFrameDecoder // BGGR_PISP_COMP1
for (int i = 0; i < pixelCount; i++)
unpackedAvg[i] = (ushort)(unpackedSum[i] / planes.Count());
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
{
int idx = y * width + x;
double value = unpackedAvg[idx];
value = Math.Max(0, value - blackLevel);
bool isBlue = (y % 2 == 0) && (x % 2 == 0);
bool isRed = (y % 2 == 1) && (x % 2 == 1);
if (isRed)
value *= rGain;
else if (isBlue)
value *= bGain;
else
value *= gGain;
unpackedAvg[idx] = (ushort)Math.Min(value, ushort.MaxValue);
}
using var bayer = Mat.FromPixelData(height, width, MatType.CV_16UC1, unpackedAvg);
var bgr = new Mat();
Cv2.CvtColor(bayer, bgr, ColorConversionCodes.BayerRG2BGR);
+1 -1
View File
@@ -13,5 +13,5 @@ public interface IFrameDecoder
public ColorSpace.YcbcrEncodingEnum YcbcrEncodingEnum { get; }
public ColorSpace.RangeEnum RangeEnum { get; }
public Mat Decode(int width, int height, int stride, List<byte[]> planes);
public Mat Decode(int width, int height, int stride, List<byte[]> planes, double rGain, double gGain, double bGain, int blackLevel);
}