SHARE
TWEET
blobdetection.hpp
a guest
Jan 29th, 2020
86
in 198 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- #ifndef DEF_BLOB_DETECTION
- #define DEF_BLOB_DETECTION
- //#define USE_READ_PIXELS
- //#define ENABLE_READ_BACK
- #ifndef USE_READ_PIXELS
- #include <interface/vcsm/user-vcsm.h>
- #endif
- /* Includes & CPU stuff omitted */
- static int maskW, maskH, mapW, mapH;
- // Regions as read from the GPU memory
- typedef uint16_t BlobMapRegion;
- static BlobMapRegion *blobMapRegions;
- // Intermediate render targets
- #ifdef USE_READ_PIXELS
- static FrameRenderTarget *blobMask, *blobMap;
- #else
- static FrameRenderTarget *blobMask;
- static VCSMRenderTarget *blobMap;
- #endif
- static void initBlobDetection (int width, int height, EGL_Setup eglSetup)
- {
- maskW = width;
- maskH = height;
- mapW = maskW / 4;
- mapH = maskH / 4;
- /* Init of CPU stuff omitted */
- #ifdef USE_READ_PIXELS
- // Setup intermediate Render Targets
- blobMask = new FrameRenderTarget(maskW, maskH, GL_RGBA, GL_UNSIGNED_BYTE);
- blobMap = new FrameRenderTarget(mapW/2, mapH, GL_RGBA, GL_UNSIGNED_BYTE);
- // Allocate memory for regions map read back from the GPU
- blobMapRegions = (BlobMapRegion*)malloc(mapW * mapH * 2);
- #else
- // Setup Render Targets in Shared Memory
- vcsm_init();
- // Switch type of render target between texture and VCSM
- blobMask = new FrameRenderTarget(maskW, maskH, GL_RGBA, GL_UNSIGNED_BYTE);
- //blobMask = new VCSMRenderTarget(maskW, maskH, eglSetup.display);
- blobMap = new VCSMRenderTarget(mapW/2, mapH, eglSetup.display);
- //blobMap = new FrameRenderTarget(mapW/2, mapH, GL_RGBA, GL_UNSIGNED_BYTE);
- #endif
- }
- static void performBlobDetection(CamGL_Frame *frame, std::vector<Cluster> &blobs)
- {
- // -- GPU PART --
- // Render from camera frame source to blobMask
- shaderESBlobDetect->use();
- frame->setSource(shaderESBlobDetect, 0);
- blobMask->setTarget();
- SSQuad->draw();
- // Encode binary blob flag in source alpha into regions of full color
- // Each region is 4x4 and stores 4bit per channel in 4 channels
- shaderESBlobEncode->use();
- blobMask->setSource(shaderESBlobEncode, 0);
- blobMap->setTarget();
- SSQuad->draw();
- // -- CPU PART --
- #ifdef ENABLE_READ_BACK
- int xMin = 0, xMax = mapW, yMin = 0, yMax = mapH;
- int bufW = mapW, bufH = mapH;
- #ifdef USE_READ_PIXELS
- // Read back encoded regions map from GPU memory
- glReadPixels(0, 0, mapW/2, mapH, GL_RGBA, GL_UNSIGNED_BYTE, blobMapRegions);
- #else
- // Wait for current GL operations to finish
- glFinish();
- // Lock the blobMap shared memory so CPU can access it
- blobMapRegions = (BlobMapRegion*)blobMap->lock();
- bufW = blobMap->bufferWidth*2;
- bufH = blobMap->bufferHeight;
- #endif
- /* Processing omitted */
- #ifndef USE_READ_PIXELS
- blobMap->unlock();
- #endif
- #else // ENABLE_READ_BACK
- glFinish();
- #endif // ENABLE_READ_BACK
- }
- #endif
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
