Displaying WebCam video with Qt
Asked Answered
S

3

11

I'm using Qt 4.5 (2009.03) on Linux Gnome (Ubuntu 9.04) and would like to display video captured by my webcam in a Phonon::VideoWidget of my Qt application.

I have a first implementation using the v4l2 API where I do the YUV2 to RGB conversion and fill a QImage my self. It works well but it is not very efficient. A collegue used gStreamer to do the same thing and it was much much faster.

Since then I found out about phonon and would like to use it. Everything is configured and set up except for the binding to the webcam device as source.

I should create a MediaSource object but I don't know how to configure it. Any help would be greatly valuable.

Edit: The Phonon overview explains that it is not supported yet. But I need a solution.

Swound answered 4/9, 2009 at 11:35 Comment(4)
I wish I could do the same but with a cross platform application working on Windows, Linux and MacOS XWigeon
I now have a working version but it uses only video for linux (v4l). opencv is straightforward to plug into Qt but the image resolution is fixed to a low value and it is very low on windows. Changing the resolution parameters has no effect. With my linux version I don't have this limitation. I convert from yuv, tilt the image by 90° and copy right away into the QImage buffer. With 800x600@5fps cpu usage is very low.Swound
Do you have some piece of code to show me ? I need to do the same thing for a project.Wigeon
+2. Great question! I'm seeking a way to make Qt to display video sequences capture by webcams too. Would you release it under public license? Thanks!Menides
R
5

I know its little bit late for this question. but I was looking for the same thing and could not find pure qt solution. Here is my solution https://sourceforge.net/p/qtv4lcapture/code/HEAD/tree/

Roadside answered 25/6, 2010 at 4:32 Comment(0)
R
4

If your goal is to display the YUV image on the screen you can use the OpenGL module. Implement the conversion as a fragment shader. If you want to do something else like save the converted image to a file then it is not a good idea.

Some links:

Rebarebah answered 4/9, 2009 at 13:1 Comment(0)
D
2

Maybe you can take a look the way kapture was implemented.

Demand answered 4/9, 2009 at 12:38 Comment(1)
I checked but it fails to initialize the webcam. The code I wrote using v4l2 directly works correctly. I saw he converts images by hand too, which is not good.Swound

© 2022 - 2024 — McMap. All rights reserved.