I'm a beginner of pyqt, and recently I'm having a problem with it. I
hope someone could help me.
As required, I need to get a videostream from a camera, and process
every frame to add some information on it, and then display the frame
in a PyQt GUI.
But I don't know how to display the videostream in the PyQt GUI by a
efficient way.
Currently, I do these like this:
1. Get the videostream by the videocapture module (a useful module
written by Markus Gritsch) in the format of PIL images;
2. Process every PIL image and add the information;
3. Convert every PIL image to QPixmap and display it using
QLabel.setPixmap.
I think it is a very inefficient way, but I don't known how to display
the videostream in other ways, so I need your help, Thanks!
PS:I do it with Windows XP, Python 2.5.1, PyQt4.3.0
> As required, I need to get a videostream from a camera, and process
> every frame to add some information on it, and then display the frame
> in a PyQt GUI.
> But I don't know how to display the videostream in the PyQt GUI by a
> efficient way.
>
> Currently, I do these like this:
> 1. Get the videostream by the videocapture module (a useful module
> written by Markus Gritsch) in the format of PIL images;
This sounds interesting. I wasn't aware of that module.
> 2. Process every PIL image and add the information;
> 3. Convert every PIL image to QPixmap and display it using
> QLabel.setPixmap.
This could be quite inefficient, though I think there's some support for
Qt's image classes in PIL these days.
> I think it is a very inefficient way, but I don't known how to display
> the videostream in other ways, so I need your help, Thanks!
>
> PS:I do it with Windows XP, Python 2.5.1, PyQt4.3.0
If you're using a commercially-licensed Qt library, you'll have access to
the ActiveQt classes that can be used to embed ActiveX controls:
http://doc.trolltech.com/4.3/activeqt.html
Otherwise, you might find this recent thread on qt-interest to be of
interest:
http://lists.trolltech.com/qt-interest/2007-09/msg00806.html
I also tried to document ways to do this on the PyQt/PyKDE Wiki:
http://www.diotavelli.net/PyQtWiki/Multimedia_Resources
David
I read the method in the given link and learn a lot from it. I'll
try to display the data inside a QWidget directly instead of the
current way. But I still have a question, is there any way to make the
displaying of RGB data in a QWidget more quickly.
In fact, my work is to make a gui for displaying my
partners'experimental results to our teacher, the source video is no
need to be encoded to mpeg or h264 format, so I get the video from
camera in the raw format and display them without encodeing or
decoding process.
As my partners will do some experiments on the raw data, maybe add
a mark to label some area in the current frame, or change some part of
it, I get every frame as a picture before they process the picture
data, and then display the picture after their process. But displaying
the pictures one by one in my current way is so slow, I'm afraid that
time spend on it is too long and the displaying of results will be
discontinuous. So I think maybe there is another way to show these
pictures.
Look forward to more advices.^ ^
Thanks!
Kivilaya
> I read the method in the given link and learn a lot from it. I'll
> try to display the data inside a QWidget directly instead of the
> current way. But I still have a question, is there any way to make the
> displaying of RGB data in a QWidget more quickly.
You can set certain flags to ensure that the widget isn't being updated
or painted on too often. See the WA_OpaquePaintEvent and
WA_NoSystemBackground flags:
http://www.riverbankcomputing.com/Docs/PyQt4/html/qt.html#WidgetAttribute-enum
The problem may be related to the conversion process rather than the time
it takes to display the image. You mentioned that you were obtaining the
images as PIL Image objects, but these need to be converted to QImage or
QPixmap objects, so the raw data from the camera is being converted at
least twice before it reaches the screen!
> In fact, my work is to make a gui for displaying my
> partners'experimental results to our teacher, the source video is no
> need to be encoded to mpeg or h264 format, so I get the video from
> camera in the raw format and display them without encodeing or
> decoding process.
Which operating system is this on? (I'm guessing that it's Windows because
you mentioned the videocapture module.)
> As my partners will do some experiments on the raw data, maybe add
> a mark to label some area in the current frame, or change some part of
> it, I get every frame as a picture before they process the picture
> data, and then display the picture after their process.
So, do you intend to process the video and store it in a file, or do you
want to make these changes on a live video stream?
> But displaying the pictures one by one in my current way is so slow,
> I'm afraid that time spend on it is too long and the displaying of
> results will be discontinuous. So I think maybe there is another way
> to show these pictures.
Is there another way of getting the data from the camera? Perhaps the
author of videocapture has some ideas that can help you speed up the
conversion and rendering process. Maybe the Device.getBuffer() function
will provide data that can be passed directly to QPixmap.loadFromData().
David
Your advice makes me know the important thing of my question is the
way I get the source video.
I do this on the Windows XP operating system, and make these changes
on a live video stream. And I think you are right, the conversion
process takes most part of the time, and the raw data from the camera
is being converted more than twice before it reaches the screen (It is
all because of my lack of the knowledge of how to using
loadFromData()).
After I get a PIL image named im from the camera, I convert it like
this,
s = StringIO()
self.im.save(s, "PNG")
s.seek(0)
image = QImage()
image.loadFromData(s.read())
img = QPixmap.fromImage(image)
s.close()
I'm not familiar with the way of getting the data from the camera,
so in my current way, I just use a function in the videocapture module
that can save the current picture in of the camera to get the data,
and do this 15 times every minute to make the source data as a live
video stream.
So I think learn the use of QPixmap.loadFromData() and the use of
videocapture module is important for me.
Thank you for your help, your suggestion let me get more and more
familiar with the things I do and learn a lot.:)
Kivilaya