Coder Social home page Coder Social logo

Investigate GPU filters about picamera HOT 7 OPEN

waveform80 avatar waveform80 commented on April 28, 2024
Investigate GPU filters

from picamera.

Comments (7)

waveform80 avatar waveform80 commented on April 28, 2024

This thread seems to suggest that there may soon be an MMAL path to get textures to OpenGL which may obviate the need to dig into OpenMAX

from picamera.

waveform80 avatar waveform80 commented on April 28, 2024

Digging into OpenGL/ES at the moment. The pyopengl project looks like the best bet for ctypes-based header conversions for the GL libraries. On the plus side, GL/ES headers now seem to be converted (looking at the Launchpad code). On the downside, they're not in the Raspbian packaged version (haven't checked PyPI yet) so either we need to incorporate a hack to account for that in our Raspbian packaged version, or we make it an optional dependency and tell users to install the PyPI version for now until Raspbian catches up (I'm tempted by the latter).

On API design: I suspect we may be able to get away with a single new parameter for the various capture/record/preview methods - something like gl_scene which accepts an object to use as the GL scene. When unspecified or None, everything operates as before. When specified, use a GL specific rendering path.

For cooked output this should be relatively easy to incorporate - the GL stuff goes before the encoders in the pipeline so it's just like the resizer - shouldn't be too difficult to incorporate. However, raw captures are another matter - can we even get YUV/RGB/etc. output from a GL scene? Even if we can it'll probably look very different at the call level to the existing raw capture stuff. Depending on difficult, I may have to leave raw capture from GL scenes as a future effort.

from picamera.

fedtf avatar fedtf commented on April 28, 2024

Any news about this? I don't know much about OpenGL and Raspberry internals, but I'm trying to investigate into the topic. (By the way, thanks so much for the great documentation!)

It looks like this kind of functionality is available in raspistill with --gl* arguments. Concerning the implementation, I guess one place to look at is here, but, searching through shared libraries in /opt/vc/lib, I found neither functions from RaspiTex.c nor some VCOS functions used there. Namely, I failed to find vcos_semaphore_post and vcos_semaphore_wait, which is weird since functions for creating and deleting semaphores are available in libvcos.so. Not sure whether the same can be done with MMAL.

from picamera.

byronformwalt avatar byronformwalt commented on April 28, 2024

You might look into the latest version of raspicam which you need to compile from source. I've tested it out, and it works. 100% MMAL and OpenGL (no OpenMAX). It demonstrates how to use OpenGLESv2 for realtime capture and rendering to textures. On my system (RPi3 Model B, Camera V1) I can do 1024x1024 from 720p at approximately 60 fps. Given this info, it is surely possible to use Python ctypes to build and register custom MMAL components that facilitate building an OpenGLESv2-based image processing pipeline. The alternative I see would be to add GPU acceleration for OpenCV to the Pi. The last I checked, GPU acceleration via OpenCV was still not supported for this platform.

from picamera.

fedtf avatar fedtf commented on April 28, 2024

This is exactly what I'm looking into. The link in my comment goes to one of the files in the raspicam source responsible for passing textures to OpenGL. I'm just confused with the absence of some VCOS functions in the shared libraries, which will be needed in order to port this to python.

from picamera.

byronformwalt avatar byronformwalt commented on April 28, 2024

Ok, I see what you mean, now. You threw me off when you referenced raspistill instead of raspicam, and I didn't open your link the first time. Sorry about that. ...Indeed neither vcos_semaphore_post nor vcos_semaphore_wait is defined in the namespace of libvcos.so or any other shared library.

Instead, you will find vcos_semaphore_wait defined in /opt/vc/interface/vcos/pthreads/vcos_platform.h beginning on line 251:

/*
 * Counted Semaphores
 */
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_semaphore_wait(VCOS_SEMAPHORE_T *sem) {
   int ret;
   /* gdb causes sem_wait() to EINTR when a breakpoint is hit, retry here */
   while ((ret = sem_wait(sem)) == -1 && errno == EINTR)
      continue;
   vcos_assert(ret==0);
   return VCOS_SUCCESS;
}

... and vcos_semaphore_post is defined in the same file beginning on line 341:

VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_semaphore_post(VCOS_SEMAPHORE_T *sem) {
   int rc = sem_post(sem);
   vcos_assert(rc == 0);
   (void)rc;
   return VCOS_SUCCESS;
}

sem_post and sem_wait are the underlying function calls being made into the shared library called libpthread.so . That is where several other basic semaphore operations are implemented:

pi@raspirox:/usr/lib/arm-linux-gnueabihf $ lddump libpthread.so |grep sem_
    sem_close()
    sem_destroy()
    sem_getvalue()
    sem_init()
    sem_open()
    sem_post()
    sem_timedwait()
    sem_trywait()
    sem_unlink()
    sem_wait()

It would be nice if there were a great set of documentation for this platform? It seems none of us ever has the time to make one. I hope this helps answer you're concern.

from picamera.

byronformwalt avatar byronformwalt commented on April 28, 2024

from picamera.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.