Solved

Video capturing with OpenCV

Posted on 2006-06-15
4
23,018 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

691 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