' public byte[] BufferToBitmap_Bytes_V2(byte[] buffer)
{
if (buffer == null || buffer.Length == 0)
return null;
try
{
// Step 1: Create OpenCV Mat directly from the buffer
using (var mat = new OpenCvSharp.Mat(Height, Width, OpenCvSharp.MatType.CV_8UC3, buffer))
{
// Step 2: Flip the Mat vertically
//OpenCvSharp.Cv2.Flip(mat, mat, OpenCvSharp.FlipMode.X);
// Step 3: Compress the Mat to JPEG
int[] compressionParams =
{
(int)OpenCvSharp.ImwriteFlags.JpegQuality,
OCT_Config.IRIS_Image_Quality_For_Transfer
};
OpenCvSharp.Cv2.ImEncode(".jpg", mat, out var jpegData, compressionParams);
return jpegData;
}
}
catch (Exception ex)
{
// Log the error for debugging purposes
ConsoleWrapper.WriteLine($"Error in BufferToBitmap_Bytes: {ex.Message}");
return null;
}
}`
in our app we are using this library and running 3 camera's , in that 2 camera's are monochrome camera's and one is RGB camera.
when they are running amost 50% of CPU is occupying
Each camera is running on different thread
modified your usbcamera.cs class which will return byte[] after some processing steps, They are
Fliiping the camera feed , Compressing the image quality and converting to byte[]
Here is the modified class
Can we optimize the performance and is there anyway to run the calculations on GPU