Hi Marcos,
I’m not sure I follow all of your code, and I’m not familiar with the vlc library. So perhaps this advice is obvious or inappropriate.
I often want to show an image from live video cameras and place overlays on top of these images – typically static shapes. To do this, I make a subclass of a wx.Panel(), and bind Paint events to a method that redraws the image and the overlays.
class ImagePanel(wx.Panel):
def init(self, parent, **kws):
super(ImagePanel, self).init(parent, -1, size=(800, 600))
self.Bind(wx.EVT_PAINT, self.onPaint)
self.scale = 0.6 # sets scaling of raw bitmap image to that displayed on screen
probably set more stuff here
def onPaint(self, evt):
get the next full image, could be any source. Example of simple web camera:
full_image = wx.ImageFromStream(StringIO(urlopen(self.url).read()))
# scale image: usually you know the size of full image, or read it once
scaled_image = full_image.Scale((self.scaleself.full_width, self.scaleself.full_height))
# make bitmap
bitmap = wx.BitmapFromImage(scaled_image)
bmp_w, bmp_h = self.bitmap_size = bitmap.GetSize()
pan_w, pan_h = self.panel_size = self.GetSize()
pad_w, pad_h = (pan_w-bmp_w)/2.0, (pan_h-bmp_h)/2.0
# draw bitmap
dc = wx.AutoBufferedPaintDC(self)
dc.Clear()
dc.DrawBitmap(bitmap, pad_w, pad_h, useMask=True)
draw extra bits on top
dc.SetFont(wx.Font(11, wx.SWISS, wx.NORMAL, wx.NORMAL))
dc.SetPen(wx.Pen(wx.Colour((200, 0, 0)), 2, wx.SOLID))
dc.DrawLine(100, 100, 300, 100)
dc.DrawText(‘text here’, 150, 125)
I think what you’re trying to do is not (or does not need to) be a lot more complicated than that. In short, you do have to draw the overlays every time the image updates. It’s helpful to bind to size events to adjust the scale factor too, but this example is long enough. And, you might want some error checking in your actual code ;).
···
I haven’t tried this with pre-existing videos files, but this works to display images from1 to 2Mb gigE or usb3 cameras at 15 to 20 fps without flickering or performance problems, assuming the video card and network are up to the job.
I hope that’s helpful,
–Matt
On Thu, May 26, 2016 at 2:05 AM, Marcos del Amo mdelamo90@gmail.com wrote:
I think not, but I’m not really sure, I tried to paint every milisecond the label, but the flickering was insane (vlc deleting, me painting).
I’ve made some little test, in order to show you the problem.
In order to work you’ll need two images, one as a background for the label and the other to add some colour and some mp4 video.
Finally in order to use the program you’ll to have installed VLC in the custom path and add vlc.py in the same folder as the VLC.
Python should be 32 bits or the python bindings won’t work -.- (or I couldn’t make it work for 64)
This is how I’m using it but there are some tests commented, in line 301-305 is the option to put a button in the same frame as the video, and uncommenting the lines 481-482 to repaint it every milisecond that turns out as a big flickering like I explained.
Hope this help
That should be all
El miércoles, 25 de mayo de 2016, 19:59:08 (UTC+2), Emad Dlala escribió:
I’m just wondering, would a custom DC event work here?
On Wednesday, May 25, 2016, Marcos del Amo mdel...@gmail.com wrote:
I’m using sizers for other parts of the code, but in this case, I want the video and the label to ocupy the same space, I mean, I want the label on hoovering over the video, if I use a sizers won’t like a reserved space for the label? Or I am missunderstanding how sizers works (which could be a posibility)
P.S. I’ve been googlin up a bit and it seems I can use the colorkey thingy with VLC right? I look into it tomorrow…I’ve been struck for three weeks with this so thanks for the help!
El miércoles, 25 de mayo de 2016, 19:52:25 (UTC+2), Gadget Steve escribió:
On 25/05/2016 18:34, Marcos del Amo wrote:
I’m using VLC, with the python bindings. I don’t know if it supports
colorkey (I’ve never heard of it before)
I was thinking of using ||GetClientArea|
<http://www.wxpython.org/docs/api/wx.Display-class.html#GetClientArea>|() with
the frame floating on top of the video so every time the user interacts
with the player (which is gonna be a lot) the program get’s the client
area, and recalculate it’s position. It’s not perfect but at least if
the user moves the video between screens the labels will pop up on the
right positions.
Looking at your earlier post which included a part of the code you are
using absolute positioning for just about everything - you will find
that a lot of your headaches will go away if you read up a bit on and
use sizers instead. Then moving the top window will automatically
relocate and child windows within the sizers.
–
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.
–
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.