PDA

View Full Version : Qthreads and webcam app



Schizo
20th June 2007, 14:43
Hi guys! I'm new to Qt and developing a face recognition app with QT4 and Intel Opencv! I'll explain you how my app should work and I've got some questions because i have some strange problems...
My app need to start a webcam and display the frames captured by the webcam in a Qlabel, pushing a button the user should be able to get a webcam frame saved to the disk (.pgm format), display it in an other QLabel and after pushing another button do a face recognition task with that image.

That's what I've done...
For the webcam a started a Qthread, the webcam has to run continuosly and every time a frame is captured, the thread send a signal (with the frame included, coverted in a Qimage) to a slot defined in the main thread (GUI) where it will be showed in the label (label->setPixmap(Qimage)). I didn't focus up to know my attention on the "saving frame on the disk part" because I realized that when the thread is running the facerecognition tasks in the main thread don't work as they should. But facerec task in the main thread and webcam thread don't have any shared resource or variable. if i comment the line where I start the webcam thread, facerec taks are done perfect, if i run the app with the webcam thread i get some troubles.

My questions:
1. How would you in your opinion plan the app (how many threads, shared memory...)
2. Shall i run my face rec tasks in an other Thread outside the main thread?
3. Do you think i need some mutex? (IMHO no because i think that webcam thread and the main thread don't have any shared var...)

Thanks in advance, and sorry for my english! Any help will be appreciated and if you need i'll also post the code. Thank you and bye!

guilugi
21st June 2007, 10:17
Yes, a compilable code would be the best, if you want rapid solutions ;-)

I have a similar architecture in my MediaBrowser, I have a separated thread that processes thumbnails of images contained in a specified directory, and notifies main GUI thread each time a thumbnail is ready, so it can be displayed !

It works really fine with me, and your approach seems good.

Seeing your code will surely help.

Guilugi.