Solved

Video capturing with OpenCV

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

863 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

27 Experts available now in Live!

Get 1:1 Help Now