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

How to scale a high - resolution image to a low - resolution one? #1286

Open
wangwenfeng0 opened this issue Dec 26, 2024 · 2 comments
Open

Comments

@wangwenfeng0
Copy link

Description

#PoseLandmarkerRunner.cs
_textureFramePool = new Experimental.TextureFramePool(imageSource.textureWidth, imageSource.textureHeight, TextureFormat.RGBA32, 10);
// NOTE: we can share the GL context of the render thread with MediaPipe (for now, only on Android)
var canUseGpuImage = options.baseOptions.delegateCase == Tasks.Core.BaseOptions.Delegate.GPU &&
SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3 &&
GpuManager.GpuResources != null;
using var glContext = canUseGpuImage ? GpuManager.GetGlContext() : null;

  while (true)
  {
    if (isPaused)
    {
      yield return new WaitWhile(() => isPaused);
    }

    if (!_textureFramePool.TryGetTextureFrame(out var textureFrame))
    {
      yield return new WaitForEndOfFrame();
      continue;
    }

    // Build the input Image
    Image image;
    
    if (canUseGpuImage)
    {
      yield return new WaitForEndOfFrame();
      textureFrame.ReadTextureOnGPU(imageSource.GetCurrentTexture(), flipHorizontally, flipVertically);
      image = textureFrame.BuildGpuImage(glContext);
    }
    else
    {   
      req = textureFrame.ReadTextureAsync(imageSource.GetCurrentTexture(), flipHorizontally, flipVertically);
      yield return waitUntilReqDone;

      if (req.hasError)
      {
        Debug.LogError($"Failed to read texture from the image source, exiting...");
        break;
      }
                
      image = textureFrame.BuildCPUImage();
      textureFrame.Release();
    }

When I get the "Image image" data, how can I resize the image to reduce computational time consumption while keeping the input image at a high resolution.
thank you very much.

@homuler
Copy link
Owner

homuler commented Dec 29, 2024

I think generating an Image instance based on downscaled pixel data (= downscale it by yourself) would be a straightforward approach, but if you can modify the MediaPipe CalculatorGraph, it should be also possible to downscale the image using the ImageTransformationCalculator or GlScalerCalculator.

@wangwenfeng0
Copy link
Author

The new version of 0.10.20 Assets Package will be released soon?

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