PDA

View Full Version : using a DirectShow enabled webcam to take still images in QT



Jason Hamilton
8th October 2008, 16:30
Hey all,

Okay, so I have a problem. I am trying to write an application that will allow the user to take a picture (using, currently, a logitech webcam) of an individual. Now, I've taken this project over from another person who is no longer with the company and there are wsome things that seem strange to me. First off, the current version allows the user to load an image from the hard drive, a functionality that we want to keep. However, the image is being loaded as a pixmap into a QLabel object (strange?). So question 1, is that ideal?
In the new version that we are writing, we want to be able to capture that image from a webcam connected to the computer as well as read one off the HD. The webcam is a Logitech if that matters and according to Logitech, it supports a DirectShow interface for controlling it. Here's the issue: if I want to display the live stream in the window and allow the user to click a 'capture image' button when the subject is correctly in the frame how do I go about showing that in the QT UI? In reading through the forums and things, I've learned that this might be an application for Phonon; correct? But I don't see an Phonon Widgets in the QT Designer. Is that a seperate thing I'll need to buy?
Thanks for the help with my previous questions. You've all been a great help in the past.

Jason

JimDaniel
8th October 2008, 19:22
Phonon will not yet do what you require. It is only useful for simple media playback at the moment.

QLabel is the widget for showing images on-screen. It takes a QPixmap. However, QImage is what you will use when you're grabbing the DirectShow image bits the webcam streams out.

You will need first to figure out how to get the streaming image data from the webcam, this part is not related to Qt. Then once you have access to the raw frame bits, you copy those frame bits to a QImage, and from there you can do whatever you want, convert it to a QPixmap and set that to a QLabel for on-screen display, or save the image onto the hard drive....etc.

Jason Hamilton
8th October 2008, 20:54
Okay, so if I were to incorporate, say, the AMCap code to get the stream, do you know of any places were I could see an example of how to grab a single frame? I should point out that I'm a junior software engineer and have no experience working with hardware and the DX stuff I know is very old. Thanks again.

Jason

JimDaniel
8th October 2008, 22:07
Unfortunately this is out of my area of expertise. I recommend you go to a forum specializing in DirectShow and ask them how you can get access to the frame bits from AmCap, in the form of an uchar *. They will tell you something about locking the object, grabbing the bits, then unlocking the object. Once you can do that, all that's left on the Qt side is to copy those bits to a QImage - you can instantiate a QImage from uchar *. Sorry I can't be of more help.

Jason Hamilton
8th October 2008, 23:25
No, hey, a pointer in the right direction is plenty of help. THanks