Ok. As I promised to your request in the comments, and sorry to keep you waiting, really been busy. Barely had time to post this answer too. But here it is:
This is me simulating that opencv is capturing black image. On the output window, which I had asked you in the comments about what it says, shows that there is an error.
After investigating, I realised that it is due to the camera's available format:
Of cuz, this is a lousier camera. If you have a better camera like the logitech one, you can see that the format available is so much more.
There are lots of methods, you can try some thing like
capture.set(CV_CAP_PROP_FRAME_WIDTH , 640);
capture.set(CV_CAP_PROP_FRAME_HEIGHT , 480);
capture.set (CV_CAP_PROP_FOURCC, CV_FOURCC('B', 'G', 'R', '3'));//diff from mine, using as example
then the webcam will be able to snap. This webcam is bit faulty, hence the image snapped is not that beautiful.
Hope this is your problem. but it may not be the case too. I like debugging problems, but I can't put down all the possible causes that this happen for you as I am really busy, as you asked for an example, this is one of them. Cheers. If you could tell me what you output window error says, I probably can help more.
EDIT(to answer more in your comments):
Ok, I want you to try a few things:
1)First, instead of using cvQueryFrame
, or similar capturing methods, I want you to try use that webcam to capture a video instead. Wait up to maybe say 10 secs to see if it's successful. Reason being, some cameras(lower quality ones) take quite a while to warm up and the first few frames they capture may be an empty one.
2) If the step one doesn't work, try typing
cout << cv::getBuildInformation() << endl;
and paste the results for media I/O and Video I/O? I want to see the results. I would suspect your library dependencies too, but since you said it works with a logitech camera, I doubt that's the case. Of course, there's always a chance it's due to that the camera is not compatible to OpenCV. Does the camera have any brands by the way?
3) Alternatively, just search for usb drivers online and install it, I had a friend who did this for a similar problem, but not sure the process of that.