opencv - cvCaptureFromCAM(CV_CAP_DSHOW) capture blank frame - c++

I am using OpenCV 2.1 and Visual Studio 2008 in Windows. I am trying to grab the frames from CCD camera and want to display on Windows. Camera is with PAL format. Camera is detecting but showing the blank grey screen.
I found many post related to blank screen but no one is work in my case. So post I post this question.
Below is my code:
#include "stdafx.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <iostream>
int main(int argc, char* argv[])
{
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCaptureFromCAM(CV_CAP_DSHOW);
if ( !capture ) {
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar();
return -1;
}
while ( 1 ) {
IplImage* frame = cvQueryFrame( capture );
if ( !frame ) {
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
}
else
{
fprintf( stderr, "Size of camera frame %d X %d\n",frame->width,frame->height );
}
cvShowImage( "mywindow", frame );
if ( (cvWaitKey(10) & 255) == 27 ) break;
}
// Release the capture device housekeeping
cvReleaseCapture( &capture );
cvDestroyWindow("mywindow");
return 0;
}
Above code return frame size 320 X 240 but blank screen.
Code is working fine for usb webcam with code CvCapture* capture = cvCaptureFromCAM(1);
I am using Avermedia Gold Camera Card on my board. So Do I need SDK to use this camera or is there any option to use CCD camera??
Driver is installed correctly and check with EzCaptureVC application.

OpenCV needs to support your camera else there's no guarantee its going to work: check the compatibility list.
Also 2.1 it's very outdated. I suggest you try again with the 2.3.1 since there has been some improvements in this area.

Related

How to calculate Frame Per Second in opencv?

Here is my code it display video but at high fps. I want original fps here but don't know how to do it. Watching some tutorials , they are using VideoCapture , I tried to use it but this is giving me linker error undefined reference to 'cv::VideoCapture::VideoCapture(std::string const&)'.. though I am linking all libraries but error is same. I am using Dev-C++ 5.11 (GCC 4.9.2) , so any idea how to use (CV_CAP_PROP_FPS)here -
#include <windows.h>
#include <opencv/cv.hpp>
#include <opencv/highgui.h>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
double fps=0;
cvNamedWindow( "Movie", CV_WINDOW_NORMAL );
CvCapture* capture = cvCreateFileCapture( "G:\\movie\\Journey.2.The.Mysterious.Island.2012.avi" );
IplImage* frame;
//cv::VideoCapture cap("G:\\movie\\Journey.2.The.Mysterious.Island.2012.avi" ); [giving me error]
//fps=cap.get(CV_CAP_PROP_FPS); [How to use this]
while(1)
{
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "Movie", frame );
char c = cvWaitKey(27);
if( c == 27 ) break; //esc
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Movie" );
}
Thnx :)
double fps=cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);

OpenCV in Ubuntu does not show window

I installed a fresh Ubuntu. Downloaded Eclipse via the Shop, installed the CDT plugin via the Plugin Manager in Eclipse (Kepler). I used the Shop to download the OpenCV dev package. After adding the paths in eclipse I wrote a short program.
#include <iostream>
#include "opencv2/opencv.hpp"
int main(int argc, const char * argv[])
{
cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCaptureFromCAM(-1);
IplImage *newImg;
while(true)
{
newImg = cvQueryFrame( capture );
if( newImg==0 )
break;
cvShowImage( "result", newImg );
}
return 0;
}
The program compiles and the debugger shows some values in newImg. But there is no window coming up and shows the result. The camera LED lights, a step through the loop seem to work perfect. Only the output window is missing. The same program runs perfect in XCode on OS X.
Just add small wait between execution of subsequent loops. Use cv::waitKey for this purpose.
#include <iostream>
#include "opencv2/opencv.hpp"
int main(int argc, const char * argv[])
{
cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCaptureFromCAM(-1);
IplImage *newImg;
while(true)
{
newImg = cvQueryFrame( capture );
if( newImg==0 )
break;
cvShowImage( "result", newImg );
cv::waitKey(100); //Wait of 100 ms
}
return 0;
}

How to open webcam in opencv2.4.6.1 on ubuntu12.04?

I am using opencv2.4.6.1 on Ubuntu 12.04 LTS. I am new to opencv and have been trying to understand the sample programs in the opencv docs. I am trying to work on a project which takes a picture from a USB webcam (Kinamax Night Vision Camera) and do some image processing on it. I came across a sample code that is shown below:
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
// A Simple Camera Capture Framework
int main()
{
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
if ( !capture ) {
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar();
return -1;
}
// Create a window in which the captured images will be presented
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
// Show the image captured from the camera in the window and repeat
while ( 1 ) {
// Get one frame
IplImage* frame = cvQueryFrame( capture );
if ( !frame ) {
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
}
cvShowImage( "mywindow", frame );
// Do not release the frame!
//If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
//remove higher bits using AND operator
if ( (cvWaitKey(10) & 255) == 27 ) break;
}
// Release the capture device housekeeping
cvReleaseCapture( &capture );
cvDestroyWindow( "mywindow" );
return 0;
}
On compiling using:
g++ trycam.c -o trycam `--cflags --libs opencv`
It gives no errors.
When I try to run it using : ./trycam Nothing shows up! Literally Nothing.
On searching google and some other posts in the stackoverflow community, I tried updating the libraries and install other dependencies like ffmpeg,GTK, Gstreamer,etc. I understand that the webcam I have connected via USB is not supported as per the list of webcams supported by linux opencv in the link here. Even my default webcam that is in my HP Pavilion dv6000 is not opening.
Is there a way I could get around this? Kindly help me out.

Wanting to live-mirror video in OpenCV on OSX, not sure where to start

If it isn't already obvious, this is my first day playing around with OpenCV.
What I am hoping to do is mirror frame2, and then upsample it.
I am not sure how to use a matrix operation on these frames which are of type IplImage. How could I mirror my frame2, and then upsample it to the Webcam2 window? Below is my code:
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
// A Simple Camera Capture Framework
int main() {
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
if ( !capture ) {
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar();
return -1;
}
// Create a window in which the captured images will be presented
cvNamedWindow( "Webcam", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "Webcam2", CV_WINDOW_AUTOSIZE );
// Show the image captured from the camera in the window and repeat
while ( 1 ) {
// Get one frame
IplImage* frame = cvQueryFrame( capture );
IplImage* frame2 = cvCreateImage(cvSize (frame->width*2, frame->height*2),
frame->depth, frame->nChannels);
cvPyrUp (frame, frame2);
if ( !frame ) {
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
}
cvShowImage( "Webcam", frame );
cvShowImage( "Webcam2", frame2 );
// Do not release the frame!
//If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
//remove higher bits using AND operator
if ( (cvWaitKey(10) & 255) == 27 ) break;
}
// Release the capture device housekeeping
cvReleaseCapture( &capture );
cvDestroyWindow( "Webcam" );
cvDestroyWindow( "Webcam2" );
return 0;
}
There is a neat function in OpenCV, called flip(). The C counterpart is named cvFlip(). And I am sure it will help you.
And I will also give you the advice I always give: Move from the C interface to C++! Much cleaner, much safer, much easier!
You can check this answer to see the differences between the two.

OpenCv Visual C++ 2010 Express problem

Hi I am trying to run the code below but having problems with the cvCreateFileCapture function.
#include "stdafx.h"
#include <iostream>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
using namespace std;
int main( int argc, char** argv ) {
cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
// CvCapture* capture = cvCaptureFromAVI( argv[1] ); // either one will work
CvCapture* capture = cvCreateFileCapture( "test.avi");
IplImage* frame;
while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "Example2", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Example2" );
}
Initially I was getting an error about a missing msvcr90d.dll file. I had to download vs 2008 and change the platform toolset configuration settings. After I did this I got the error below. Any help would be much appreciated.
I bet cvCreateFileCapture() is failing because it didn't found the file. You just don't know because you are not checking the return of the function.
It returns NULL if it can't load the video file.
CvCapture* capture = cvCreateFileCapture("test.avi");
if (capture == NULL)
{
std::cout << "!!! cvCreateFileCapture failed !!!" << std::endl;
exit(0);
}
I have no idea what openCv is, but if memory serves me, msvcr90d.dll is the debug dll for VC++2008.
Have you checked your project's configuration and properties to see what mode and what dlls it is using/importing ?