Solved

Video capturing with OpenCV

Posted on 2006-06-15
4
22,949 Views
Last Modified: 2011-10-03
I found a simple code on the net about video capturing with opencv functions. However, when i compiled it, it didnt work, cvQueryFrame didnt grab a frame. Actually my camera doesnt a usb camera just connect the pc through DV Capture + Tv Tuner card.
Doesnt OpenCV support Microsoft DV camera VCR driver or do you have any idea about how to correct or change following code?


#include "stdafx.h"
//---------------------------------------------------------
//Open Source Computer Vision Library
//File Name : sample.cpp
//   OS     : WindowsXP
//Library   : OpenCV for MS-Windows ƒÀ4a
// Camera   : USBcamera PMC-30
// Auther   : NAKANO Michiki
//Time-stamp:<November 02, 2004; 22:18>
//---------------------------------------------------------

#include "cv.h"
#include "highgui.h"


IplImage* src = NULL;      


int _tmain(int argc, _TCHAR* argv[])
{


  int key;      
  CvCapture* capture = NULL;

 
  if(NULL==(capture = cvCaptureFromCAM(-1)))
  {
    printf("\nError on cvCaptureFromCAM");
    return -1;
  }

  //-----
  cvNamedWindow("Capture", CV_WINDOW_AUTOSIZE);
  cvNamedWindow("Capture2", CV_WINDOW_AUTOSIZE);
 
  cvMoveWindow("Capture", 50, 50);
  cvMoveWindow("Capture2", 320, 50);
 
  for(;;){
 
    if(NULL==(src=cvQueryFrame(capture))){
      printf("\nError on cvQueryFrame");
      break;
    }

   
    cvShowImage("Capture", src);

   
    key = cvWaitKey(10);
   
    if(key==0x1b)
      break;
  }
 
  cvReleaseCapture(&capture);
  cvDestroyWindow("Capture");

  return 0;

}
0
Comment
Question by:ebnhuseyin
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
mrblue earned 250 total points
ID: 16922971
I do not know OpenCV but I have found the following description (http://www.cs.bham.ac.uk/resources/courses/robotics/doc/opencvdocs/ref/OpenCVRef_Highgui.htm):

==================================
cvCaptureFromCAM
Allocates CvCapture structure and  binds it to the video camera

CvCapture* cvCaptureFromCAM( int index );index
Index of the camera to be used. If there is only one camera or it does not matter what camera to use,  -1 may be passed.
The function cvCaptureFromCAM allocates and initialized the CvCapture structure for reading a video stream from the camera. Currently two camera interfaces can be used: Video for Windows (VFW) and Matrox Imaging Library (MIL). To connect to VFW camera the parameter "index" should be in range 0-10, to connect to MIL camera the parameter "index" should be in range 100-115. If -1 is passed then the function searches for VFW camera first and then for MIL camera.

After the allocated CvCapture structure is not used any more it should be released by cvReleaseCapture function.
=======================================

It looks like OpenCV recognizes only VFW (this is what I think you should be interested in) or MIL video sources. So you need VFW driver for your camera (TV Tuner or anything else) to be seen by OpenCV.

0
 
LVL 8

Expert Comment

by:mrblue
ID: 16923184
I found info that WDM video sources are mapped to VFW through VFW-to-WDM mapper. This shows as "Microsoft WDM Image Capture" VFW driver as enumerated by capGetDriverDescription() function. If you have more than one such source (WDM) you can switch them with capDlgVideoSource() macro in VFW application.

Theoretically it should work. You can use simple VFW application to select different source for "Microsoft WDM Image Capture" driver - i.e. switch between camera and TV tuner.

0
 

Author Comment

by:ebnhuseyin
ID: 16925605
At the begining i had two camera system, but i uninstalled to usb one to avoid confusion. Now i have only one camera in my system connected trough DV Capture + Tv Tuner card.  How can i write a VFM application with opencv for it. Is there any simplest way

On the other hand i can watch the preview video using DirectX AMCap program. Is that meaning it has VFW driver?
0
 

Author Comment

by:ebnhuseyin
ID: 16925649
Moreover,
At that line " capture = cvCaptureFromCAM(-1) ", function doesnt return  NULL value. when the program comes the line "if(NULL==(src=cvQueryFrame(capture)))" error occurs.  Actually its not a error, cvQueryFrame returns NULL value.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Header of docx file 17 115
Add values of each row in an array 3 64
C++ :Change value from  DisableCMD registry 4 66
Why  my code (program) build with old compiler? 11 76
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question