Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Video capturing with OpenCV

Posted on 2006-06-15
4
Medium Priority
?
23,098 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 750 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
  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 …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

636 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