0

I'm working with image recognition (marker detection) and was looking into image downsampling pre-recognition to boost performance. Reasoning is I'll downsample the image, run the detection algorithm on that and then interpolate the marker coordinates using the downsampling factor. I thought that downsampling cost would be trivial since it's being done all the time by our gpu .

So I tried using opencv to downsample and saw that not only did I not get any improvements, it actually took even longer. I then figured it was because I was making the cpu do it, so I looked into downsampling using opengl mipmaps or even shaders but from what I've read it still remains a costly task, taking tens or even hundreds of milliseconds to halve common image resolutions.

My question is, if downsampling is being continuously done with apparent ease (think resizing an image on any image viewer or any texture in a videogame) why is it so slow using the most common methods? Is there some secret technique or am I just not understanding something?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
UB-
  • 123
  • 3
  • 12
  • How big are your textures? How are you uploading them to the GL API and reading back the result? It's entirely possible it's the upload and readback cost is the expensive part rather than the downsample itself. – solidpixel Nov 09 '16 at 16:46
  • @solidpixel usually doing 1280x720 -> 640x480. Loading it from ram using glTexImage2D, generating mipmaps(glGenerateMipmap) and then getting second mipmap using glGetTexImage – UB- Nov 09 '16 at 16:54
  • 1
    @AlexButera so why do you need `glGetTexImage`? This is the exact reason your approach is slow. AFAIR, you can always provide the needed mipmap level explicitly, without having to move pixel data back and forth and create a new texture object. – hidefromkgb Nov 09 '16 at 17:01
  • Are you using desktop OpenGL or OpenGL ES? – Nicol Bolas Nov 09 '16 at 17:07
  • @NicolBolas ES 1.1 – UB- Nov 09 '16 at 17:09

1 Answers1

0

You can set your image as texture and use this texture on quad. Changing texture coordinates you'll be able to do any transformation on your image. And it's very fast method. Bottleneck here is copying image from host to device and back.

Andrey Smorodov
  • 10,649
  • 2
  • 35
  • 42
  • 1
    No texturing filtering will be able to repair the damage for anything higher than a 2:1 down-sample though. Higher downsampling rates in a single pass start discarding data rather than filtering it. – solidpixel Nov 09 '16 at 16:45
  • What does this mean? What is a quad? Are you talking about opengl? – UB- Nov 22 '16 at 16:19
  • Yes, I mean OpenGL. Upload your image as texture to GPU memory, bind it to quad and draw it to buffer then copy result back. – Andrey Smorodov Nov 23 '16 at 11:28