OpenCV's camera in Windows 8 - opencv

I use OpenCV in my project of Augment Reality. The original platform is Windows 7 and everything works perfect - full-screen with 1080p. However, when I launched my program on Windows 8 it showed live video with resolution 640x480. The same program on the same hardware, but with different OS Windows shows different results. I wrote simple test program which showed the same problem:
include "highgui.h"
int main()
{
cvNamedWindow("VideoTest", CV_WINDOW_AUTOSIZE);
CvCapture *capture = cvCreateCameraCapture(0);
CvSize size = cvSize(1920, 1080);
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH , size.width);
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT , size.height);
IplImage* frame;
while(1)
{
frame = cvQueryFrame(capture);
if(!frame) break;
cvShowImage("VideoTest", frame);
char c = cvWaitKey(33);
if(c == 27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("VideoTest");
return 0;
}
I think that there is problem with - cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH , size.width); But I have no idea how to resolve it.
I would be glad any help.
P.S.
I have some new info:
I wrote test program for using of DirectShow.
It captures web camera "USB Web-camera Microsoft LifeCam Studio" into full screen live video with 1080p quality. However, when I launched this program on Windows 8 it showed only live video with 640x480 resolution.
Simple test showed that method SetFormat() of IAMStreamConfig produces HRESULT value S_OK on Windows 7 and E_FAIL on Windows 8.
It is shown in the next listing:
hr = streamConfTest->SetFormat(&mtGroup);
if(SUCCEEDED(hr))
{
printf("Success SetFormat( &mtGroup )");
}else
{
printf("Error SetFormat( &mtGroup )");
}
The first branch is chosen on Windows 7, and the second is chosen on Windows 8.
I have no idea how to resolve it. I would be glad any help.

After some times I found the suitable decision of this problem. I have included Media Foundation in my project and have written simple C++ class for this. Short article about it is showed on Capturing of video from web-camera on Windows 7 and 8 by Media Foundation

Related

DirectXTK 3D audio uses only left channel

I've decided to try the DirectXTK12 audio and it's working fine except for the 3D sound. I'm following the guide from wiki but the sound is always in the left speaker no matter how I position the listener/emitter. What's wrong? My code looks like this:
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (FAILED(hr)) {...}
std::unique_ptr<DirectX::AudioEngine> audEngine;
DirectX::AUDIO_ENGINE_FLAGS eflags = DirectX::AudioEngine_Default;
#ifdef _DEBUG
eflags |= DirectX::AudioEngine_Debug;
#endif
std::unique_ptr<DirectX::SoundEffect> soundEffect;
soundEffect = std::make_unique<DirectX::SoundEffect>(audEngine.get(), L"Sound.wav");
auto effect = soundEffect->CreateInstance(DirectX::SoundEffectInstance_Use3D);
effect->Play(false);
DirectX::AudioListener listener;
listener.SetPosition(DirectX::XMFLOAT3(0.0f, 0.0f, 0.0f));
DirectX::AudioEmitter emitter;
emitter.SetPosition(DirectX::XMFLOAT3(0.0f, 0.0f, 0.0f));
effect->Apply3D(listener, emitter, false);
It should be in the center but it's only using the left channel although there are no errors in the output, the only thing the output says is this:
INFO: XAudio 2.9 debugging enabled
INFO: mastering voice has 2 channels, 96000 sample rate, 00000003 channel mask
Playing the sound without 3D uses both speakers as expected.
I've fixed the issue by converting used Sound.wav to mono (1 channel) sound.

Capturing through a single multi-head (stereo) camera using OpenCV

I have a single multi-head (stereo) usb camera that can be detected and can stream stereo videos using the "Video Capture Sources" filter in GraphEdit .
I'm trying to access both channels using OpenCV2.4.8 (on PC that has VS2010, Win7 X64) for further stereo image processing. However, I can only detect/stream single head(channel) of the camera and not both stereo heads of it. My code is set according to the related documentation notes of VideoCapture::grab/VideoCapture::retrieve and looks like the following:
#include "opencv2/opencv.hpp"
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat Lframe,Rframe;
namedWindow("Lframe",CV_WINDOW_AUTOSIZE);namedWindow("Rframe",CV_WINDOW_AUTOSIZE);
while(char(waitKey(1)) != 'q') {
if(cap.grab())
cap.retrieve(Lframe,0); cap.retrieve(Rframe,1);// get a new frame
imshow("Lframe",Lframe);imshow("Rframe",Rframe);
if(waitKey(30) >= 0) break;
}
return 0;
}
The problem is that the rendered channels (Lframe,Rframe) are identical no matter which Channel index is passed. Hence, only certain head is accessed & I can't get stereo streaming.
Is there a way to use "Video Capture Sources" filter directly with OpenCV?
Waiting for your assistance & Thank you in advance,

cvCreateCameraCapture Not Working

I am using OpenCV2.2 in Ubuntu 11.04. Using code::blocks 10.05 IDE. Testing the webcam with a simple code in openCV to capture video from the webcam. But, cvCreateCameraCapture(index) is always returning null(showing 0 error, 0 warning).
I have checked for index {-5 to +5}. The inbuilt webcam of my Acer Aspire 4736z is working fine with Cheese. lsusb showing:
Bus 002 Device 002: ID 04f2:b044 Chicony Electronics Co., Ltd Acer CrystalEye Webcam
means driver is installed.
grep -i v4l /var/log/udev returns
ID_V4L_VERSION=2
ID_V4L_PRODUCT=Video WebCam
ID_V4L_CAPABILITIES=:capture:
DEVLINKS=/dev/v4l/by-id/usb-Chicony_Electronics_Co.__Ltd._Video_WebCam_SN0001-video-index0 /dev/v4l/by-path/pci-0000:00:1d.7-usb-0:4:1.0-video-index0
Also followed this: cvCreateCameraCapture returns null
but got nothing.
Code is:
int main(int argc, char**argv)
{
IplImage *img;
char ch;
int c;
CvCapture *capture= cvCreateCameraCapture(0);
cvNamedWindow("Example1",CV_WINDOW_AUTOSIZE);
if(!capture)
printf("Camera Not Initialized");return 0;
while (capture)
{
img=cvQueryFrame(capture);
cvShowImage("Example1",img);
ch=cvWaitKey(33);
if(ch==32)
break;
}
cvReleaseImage(&img);
cvDestroyWindow("Example1");
}
Output Window:
Camera Not Initialized
Process returned 0(0X0) execution time:0.155s
press enter to continue.
Please Help me what is the problem, why the camera not working?
try recompiling OpenCV making sure you meet all the dependencies (see here).
Plus, use the newer
CvCapture* cam = cvCaptureFromCAM(CV_CAP_ANY);

Can't access webcam with OpenCV

I'm using OpenCV 2.2 with visual studio 2010 on a win 7 64 bit pc.
I'm able to display pictures and play AVI files through OpenCV as given in the book "Learning OpenCV" but I'm not able to capture webcam images. Even the samples given along with the OpenCV files cant access the webcam.
I get asked for " video source -> capture source" and there are two options: HP webcam Splitter and HP webcam. If I select HP webcam the window closes immediately without displaying any error. (i think any error message is too fast to be seen before it closes). If I select HP Webcam splitter then the new window, where the webcam images(video) are supposed to come, is filled with uniform gray. The webcam LED is on but no video is seen. My webcam works fine with flash (www.testmycam.com) and with DirectShow http://www.codeproject.com/KB/audio-video/WebcamUsingDirectShowNET.aspx
I did try getting some error message by using this:
#include "cv.h"
#include "highgui.h"
#include <iostream>
using namespace cv;
using namespace std;
int main(int, char**)
{
VideoCapture cap("0"); // open the default camera
if(!cap.isOpened()) // check if we succeeded
{
cout << "Error opening camera!";
getchar();
return -1;
}
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
And the error message I got was:
warning: Error opening file (C:\Users\vp\work\ocv\opencv\modules\highgui\src\cap
_ffmpeg.cpp:454)
Error opening camera!
I don't know what this "cap_ffmpeg.cpp" is and I don't know if this is any issue with the nosy "HP Media Smart" stuff.
Any help will be greatly appreciated.
I had the same issue on Windows 7 64-bit. I had to recompile opencv_highgui changing the "Preprocesser Definitions" in the C/C++ panel of the properties page to include:
HAVE_VIDEOINPUT
HAVE_DSHOW
Hope this helps
The cap_ffmpeg.cpp is the source file which uses ffmpeg to perform capturing of the device. If the default example given from OpenCV doesn't work with your webcam, you are out of luck. I suggest you buy another one that is supported.
Recently I have installed OpenCV 2.2 and NetBeans 6.9.1. I had a problem with camera capture, the image in the window was black but the program runs perfectly, without errors. I had to run NetBeans as admin user to fix this problem.
I hope this can help you all.
I just switched to OpenCV 2.2 and am having essentially the same problem but a 32 bit compture running Vista. The webcam would start but I'd get an error message setting the width property for the camera. If I specifically request the DirectShow camera, the cvCreateCameraCapture would fail.
What I think is going on is that the distribution version of HighGUI was build excluding the DirectShow camera. The favored Windows camera on OpenCV used to be Video For Windows, VFW but that has been deprecated since Windows Vista came out and has created all sorts of problems. Why they don't just include it, I don't know. Check the source file cap.cpp
My next step is to rebuild HighGUI myself and make sure the flag HAVE_DSHOW is set. I seem to remember having the same problem with the last version of OpenCV I've been using until I rebuilt it making sure the DirectShow version was enabled.
I experienced the same problem. My Vaio Webcam LED is on but no image on the screen.
Then I tried to export the first frame to a JPEG file and its working. Then I tried to insert a delay of 33ms before capture any frame, this time it works like a charm. Hope this'll help.
Here's an article I wrote some time back. It uses the videoInput library to get input from webcams. It uses DirectX, so it works with almost every webcam out there. Capturing images with DirectX
Once you create the cv::VideoCapture you should give an integer not a string (since string implies the input is a file).
To open the default camera, open the stream with
cv::VideoCapture capture(0);
and it will work fine.
CMAKE GUI, MSVC++10E, Vista 32bit, OpenCV2.2
It looks like HAVE_VIDEOINPUT/WITH_VIDEOINPUT option doesn't work.
However adding: /D HAVE_DSHOW /D HAVE_VIDEOINPUT to CMAKE_CXX_FLAGS, and CMAKE_C_FLAGS did the trick for me (there will be warns due to macro redefinitions).

Why does OpenCV give me a black screen?

I'm currently trying to use OpenCV (using the Processing library).
However, when I try to run any examples (either the Processing ones or the C ones included with OpenCV), I see nothing but black instead of input from the camera. The camera's LED indicator does turn on.. has anyone had the same problem? is my camera somehow incompatible with openCV? It's an Acer Crystal Eye...
Thanks,
OpenCV 2.1 still has a few problems with 64bits OS. You can read this topic on the subject.
If you're looking for working/compilable source code that shows how to use the webcam, check this out.
Let us know if it helped you.
I recently had the same problem. The OpenCV library on its own just gave me a blank screen, I had to include the videoInput library:
http://muonics.net/school/spring05/videoInput/
An example I followed was:
#include "stdafx.h"
#include "videoInput.h"
#include "cv.h"
#include "highgui.h"
int main()
{
videoInput VI;
int numDevices = VI.listDevices();
int device1= 0;
VI.setupDevice(device1);
int width = VI.getWidth(device1);
int height = VI.getHeight(device1);
IplImage* image= cvCreateImage(cvSize(width, height), 8, 3);
unsigned char* yourBuffer = new unsigned char[VI.getSize(device1)];
cvNamedWindow("test");
while(1)
{
VI.getPixels(device1, yourBuffer, false, false);
image->imageData = (char*)yourBuffer;
cvConvertImage(image, image, CV_CVTIMG_FLIP);
cvShowImage("test", image);
if(cvWaitKey(15)==27) break;
}
VI.stopDevice(device1);
cvDestroyWindow("test");
cvReleaseImage(&image);
return 0;
}
From this source: http://www.aishack.in/2010/03/capturing-images-with-directx/
I had somewhat same problem on Ubuntu. I downloaded a code from here:
http://www.rainsoft.de/projects/pwc.html
It does an extra step before starting to get frames(i think setting FPS). Worth a try, the code is easy to read and works with non-philips cams.
OpenCV only supports a limited number of types of cameras. Most likely your camera is not supported. You can look at either the source code or their web site to see which are supported.

Resources