Displaying WebCam video with Qt

百般思念 提交于 2019-12-03 09:22:39

问题


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.


回答1:


I know its little bit late for this question. but I was looking for the same thing and could not find pure qt solution. I found http://qt-apps.org/content/show.php/Qt+Opencv+webcam+viewer?content=89995 this depends opencv which I dont know and I dont want to learn.

and here is my solution http://qt-apps.org/content/show.php/V4lCapture?content=126541

one thing its thread needs to be polished a little more but it works anyway.




回答2:


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:

  • http://doc.qt.digia.com/4.6/qglshaderprogram.html
  • http://doc.qt.digia.com/4.6/qglshader.html
  • http://www.fourcc.org/source/YUV420P-OpenGL-GLSLang.c (the conversion is in the FProgram string)



回答3:


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



来源:https://stackoverflow.com/questions/1378720/displaying-webcam-video-with-qt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!