Solved

Video capturing with OpenCV

Posted on 2006-06-15
4
22,864 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now