main.cpp:59:1: error: ‘capture’ was not declared in this scope capture = cvCaptureFromCAM( 0 ); [closed]
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;
}
}
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?
is there anyway to get this code run ? I need it because i'm working on the same subject
error:
capture
was not declared in this scope@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 resultsIf 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 ...
Thanks @StevenPuttemans@LorenaGdL