streaming video from camera using pyqt4 - python

I am using a thirdparty library that utilizes a circular buffer for image data and video. It has a method for getting the last image or popping it. I was wondering what would be the best way to implement video functionality in pyqt for this. Is there some video widget with a callback function that I could use? Or do I have to somehow implement parallel processing on my own? Parallel to this, suggestions on how this would be implemented in qt if you dont know how to implement it in pyqt would also be very much appreciated.
Thanks in advance!

I would pop the last image (from the circular buffer) and load it into a QPixmap. This allows you to put the image into a form that a pyqt4 gui would be able to load.
Depending on your libraries image format (straight forward bmp? jpg? png? raw pixels?), you can load the data into the QPixmap in one of two ways.
First: do it pixel by pixel (set the width and height of the image and copy each pixels value over one by one). This method is slow and I'd only resort to it if necessary.
Second: if the image is being stored in a common format (ones that are 'supported' are listed here), this becomes trivial.
Then after the image is loaded in the QPixmap, I would use QLabel.setPixmap() to display the image.
Do this with a QTimer slot at a certain rate and you'll be able to display your images in a pyqt4 gui.

Related

Draw multiple PIL.Image in python

I have a python funtion that draws a Fractal to a PIL.Image, but i want to vary the parameters of the function in realtime and to plot it to the screen. How can i plot the image and keep updating the ploted image each time the parametes of the function vary
Use matplotlib, wxPython, PyQt, PyGame, Tk/TCL or some other lib to display the image.
Draw as many images as you need, whenever you need, using any lib you need, and then display it on a screen using one of above mentioned or some other GUI libs.
If you are working with plots and math functions, matplotlib will help you most. You might even totally use it, forgoing PIL completely.
If you want to stick to PIL only, you will have to write your own show() function, that will use some external imaging software which will seemlessly change to show another image when you send it. Perhaps Irfan View would do.

python 3 pyQT4 Display image with multiply blend mode or with alpha

I'd like to set a image on top of my QT app with a multiplier blend mode (using the image as a filter), is it possible ?
The other solution that could work for me is to use a separate image in grey-scale and use it as an alpha.
I think this is potentially possible with QGraphicsPixmapItem but I am not sure at all how to use it.
Any help much appreciated
thanks

Draw with OpenGL offscreen

Is there a way to use OpenGL to draw offscreen? What I want to do is this: I want to be able to use functions like glVertex, and get the result in a 2D pixel array.
I am using Python. I tried using PyGame, but it's not working very well. The problem with PyGame is that uses a window event though i don't need it. In addition, I had to draw to scene + flip the screen twice in order to access screen pixels using glReadPixels.
An other problem is that I can't have more that one window at once.
Is there any proper way to accomplish what I am trying to do?
What you are asking for seems to be two things in one... you want an off-screen buffer (FBO) and you want to get the contents of the framebuffer in client memory.
Can you indicate which version of GL you are targeting?
If you are targeting OpenGL 3.0+, then you can use FBOs (Framebuffer Objects) and PBOs (Pixel Buffer Objects) to do this efficiently. However, since you are using glVertex, I do not think you need to bother with efficiency. I would focus on learning to use Framebuffer Objects for the time being.
If you are not using GL3 you might have access to the old EXT FBO extension, but if you do not have that even you might need a PBuffer.
Note that PBuffers and Pixel Buffer Objects are two different things even though they sound the same. Before GL3/FBOs, WGL, GLX, etc. had special platform-specific functionality called Pixel Buffers for drawing off-screen.

Scaling down a gif using pyglet

I am currently trying to make a simple image viewers that lets me view images or gifs. I've done most of the work and it's coming out how I'd like it, but I'd also like to be able to view gifs that are too big for my screen. I have a normal 1080p monitor, but the images are 1900x1300, which I understand is an odd image size for gifs. Problem is, pyglet has no obvious way to scale down gifs when drawing them. I'm using sprites, but scaling down the sprite merely returns an error, as the image itself hasn't actually changed, and is still 1900x1300.
What I need is a method to take a gif file, scale it down by 1/2, and render that gif using pyglet. I could probably use other libraries, but I'm trying to keep the project small.
Thanks!

Drawing pixels on top of Gstreamer

I'm trying to build an application in Python that can draw things on top of video. I have not found a way to do this using gstreamer + Tkinter; I don't think tk lets you do transparent Canvases. So I've looked at using gtk instead, but I'm a bit lost- I would like to be able to just drop some sort of transparent overlay on top and push pixels, but I don't think there's such a thing as a transparent DrawingArea, either. So I need a way to edit the contents of a DrawingArea after each frame of video is in it but before it's shown to the screen. I tried using expose-event but that hasn't worked.
Any suggestions on where to go from here? I want my final product to be a little interface to let the user draw lines and polygons on top of a video as well as drawing pixels programatically- and, if possible, save the result to frames and/or video. So a direction that is more likely to make that possible would be preferred.
Edit: Tried using the "handoff" signal but it flickers madly. PiTiVi has a custom Pipeline that has a state-changed signal which they use to draw lines and circles with Cairo. So this is totally doable...
Edit 2: Right, okay. PiTiVi only draws when the video is paused; I guess I can deal with that. That's what it was using the state changed signal for- you can watch for state change messages and emulate a signal. I can deal with that, but it would be really nice to draw over every frame.

Categories

Resources