main.cpp:59:1: error: ‘capture’ was not declared in this scope capture = cvCaptureFromCAM( 0 ); [closed]

asked 2015-10-28 08:31:03 -0600

sarmad gravatar image

I was following a tutorial on web for an OpenCV library to detect eyes

when i compile it this error appears I tried to fix it but didn't find a

solution.

main.cpp:59:1: error: ‘capture’ was not declared in this scope capture = cvCaptureFromCAM( 0 );

The code is long I put only the part that I think causing this error Full code

Thanks

#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <iostream>
#include <queue>
#include <stdio.h>
#include <math.h>

#include "constants.h"
#include "findEyeCenter.h"
#include "findEyeCorner.h"



 /** Function Headers */
 void detectAndDisplay( cv::Mat frame );

  int main( ) 
{

 cv::Mat frame;

 if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading face cascade, please change face_cascade_name in source code.\n"); return -1; };

 createCornerKernels();
  ellipse(skinCrCbHist, cv::Point(113, 155.6), cv::Size(23.4, 15.2),
  43.0, 0.0, 360.0, cv::Scalar(255, 255, 255), -1);

capture = cvCaptureFromCAM( 0 );

if( capture)

{
   while( true ) 

 {

 frame = cvQueryFrame( capture );
 // mirror it
 imshow("Video",frame);
 cv::flip(frame, frame, 1);
 frame.copyTo(debugImage);

// Apply the classifier to the frame
 if( !frame.empty() ) {
  detectAndDisplay( frame );
 }
 else {
  printf(" --(!) No captured frame -- Break!");
  break;
  }

  imshow(main_window_name,debugImage);

   int c = cv::waitKey(10);
   if( (char)c == 'c' ) { break; }
   if( (char)c == 'f' ) {
   imwrite("frame.png",frame);
  }

  }
  }

  releaseCornerKernels();

  return 0;
 }
}
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sarmad
close date 2015-10-29 09:36:45.860889

Comments

2

The tutorial you are following is extremely outdated ... it combines newer C++ headers with C - style functionality, which should be avoided at all cost. So please leave it be and look for a better example! Why not try tutorials from the official page?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-10-28 09:10:28 -0600 )edit

is there anyway to get this code run ? I need it because i'm working on the same subject

sarmad gravatar imagesarmad ( 2015-10-28 10:22:18 -0600 )edit

error: capture was not declared in this scope

pklab gravatar imagepklab ( 2015-10-28 11:43:12 -0600 )edit

@sarmad the error is caused because the variable capture hasn't been properly defined (it belongs to no class). But in any case, follow @StevenPuttemans advice. Even if you solve this issue, sooner or later you will run into another one, and if you don't, you have high probabilities to end up running a buggy code with wrong results

LorenaGdL gravatar imageLorenaGdL ( 2015-10-28 11:55:08 -0600 )edit
1

If you depend on the same subject or previous developed code, your first step should be to transfer that code to OpenCV 2.4.12! Before that, there is no use in continuing this way ...

StevenPuttemans gravatar imageStevenPuttemans ( 2015-10-29 03:36:35 -0600 )edit
1
sarmad gravatar imagesarmad ( 2015-10-29 08:34:40 -0600 )edit