Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

While runing 3 camera's using this taking almost 50% of CPU #43

Open
rajeshamudala opened this issue Dec 7, 2024 · 2 comments
Open

Comments

@rajeshamudala
Copy link

rajeshamudala commented Dec 7, 2024

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

         ' 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;
              }
          }`
    

Can we optimize the performance and is there anyway to run the calculations on GPU

@secile
Copy link
Owner

secile commented Dec 25, 2024

as to using GPU, please see issue #44.
as to supports monochrome camera, please see issue #45.

@secile secile closed this as completed Dec 25, 2024
@secile
Copy link
Owner

secile commented Dec 25, 2024

As I check your modified BufferToBitmap_Bytes_V2().

  • original BuffetToBitmap is designed to return non compressed image data, but you compress image to jpeg file.
    (this is your modified version, it is okey.)

  • compressing image may require some CPU power. You had better do not compress image?

  • You are now using OpenCvSharp function.
    I think it may because you have to read monochrome image type(called Y8 or Y800).
    I have never use monochrome Y800 image format, but as I googled, it is not so difficult to read data.
    If you do not use OpenCvSharp and read Y800 by yourself, it may be possible to reduce CPU usage.

  • As I told issue How to set the video feed and still capture to a single channel (monochrome) #45, I have a plan to support Y800 future,
    but currently, I do not have monochrome USB camera.
    After I get monochrome USB camera, I will try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants