Click here to Skip to main content
12,400,183 members (54,232 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ Windows
Hello guys.. I got this code after watching a certain video tutorial on you tube. But whenever I try running it I always get the errors below...
Warning 1   warning C4627: '#include <cv.h>': skipped when looking for precompiled header use   c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  222 1   FirstProject
Warning 2   warning C4627: '#include <highgui.h>': skipped when looking for precompiled header use  c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  223 1   FirstProject
Warning 3   warning C4627: '#include <opencv2/opencv.hpp>': skipped when looking for precompiled header use c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  224 1   FirstProject
Error   4   error C2143: syntax error : missing ';' before '*'  c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  230 1   FirstProject
Error   5   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  230 1   FirstProject
Error   6   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  230 1   FirstProject
Error   7   error C2065: 'CvCapture' : undeclared identifier    c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  242 1   FirstProject
Error   8   error C2065: 'capture' : undeclared identifier  c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  242 1   FirstProject
Error   9   error C2039: 'cout' : is not a member of 'std'  c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  251 1   FirstProject
Error   10  error C2065: 'cout' : undeclared identifier c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  251 1   FirstProject
Error   11  error C2039: 'cout' : is not a member of 'std'  c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  258 1   FirstProject
Error   12  error C2065: 'cout' : undeclared identifier c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  258 1   FirstProject
Error   13  error C2059: syntax error : ')' c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  261 1   FirstProject
Error   14  error C2065: 'capture' : undeclared identifier  c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  263 1   FirstProject
Error   15  error C3861: 'cvCaptureFromAVI': identifier not found   c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  263 1   FirstProject
Error   16  error C2065: 'capture' : undeclared identifier  c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  265 1   FirstProject
Error   17  error C3861: 'cvNamedWindow': identifier not found  c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  267 1   FirstProject
Error   18  error C2065: 'capture' : undeclared identifier  c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  269 1   FirstProject
Error   19  error C3861: 'cvQueryFrame': identifier not found   c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  269 1   FirstProject
Error   20  error C2065: 'capture' : undeclared identifier  c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  278 1   FirstProject
Error   21  error C3861: 'cvQueryFrame': identifier not found   c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  278 1   FirstProject
Error   22  error C3861: 'cvResize': identifier not found   c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  284 1   FirstProject
Error   23  error C3861: 'cvWaitKey': identifier not found  c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  287 1   FirstProject
Error   24  error C3861: 'cvWaitKey': identifier not found  c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  290 1   FirstProject
Error   25  error C3861: 'cvDestroyAllWindows': identifier not found    c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  297 1   FirstProject
Error   26  error C2065: 'capture' : undeclared identifier  c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  299 1   FirstProject
Error   27  error C3861: 'cvReleaseCapture': identifier not found   c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  299 1   FirstProject
Error   28  error C3861: 'cvReleaseHaarClassifierCascade': identifier not found c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  300 1   FirstProject
Error   29  error C3861: 'cvHaarDetectObjects': identifier not found    'c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  310 1   FirstProject
Error   30  error C2039: 'cout' : is not a member of 'std'  c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  317 1   FirstProject
Error   31  error C2065: 'cout' : undeclared identifier c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  317 1   FirstProject
Error   32  error C3861: 'cvShowImage': identifier not found    c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp  328 1   FirstProject


I have tried debugging but no progress. When I also checked in the haarcascade directory I didnt find any xml file about car detection. So any help I will be grateful. the code is below

#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include 
#include "stdafx.h"
#include <cxcore.h>
#include <string>

// Create a new Haar classifier
static CvHaarClassifierCascade* cascade = 0;
 
// Create memory for calculations
static CvMemStorage* storage = 0;
 
// Function prototype for detecting an object from an image
void detect(IplImage* img);
 
// Main function, defines the entry point for the program
int main(int argc, char** argv)
{
	// Structure for getting video from camera or avi
	CvCapture *capture;
 
	// Images to capture the frame from video or camera or from file
	IplImage  *frame;
	
	int input_resize_percent = 100;
	
	if(argc < 3)
	{
		std::cout << "Usage " << argv[0] << " cascade.xml video.avi" << std::endl;
		return 0;
	}
	
	if(argc == 4)
	{
		input_resize_percent = atoi(argv[3]);
		std::cout << "Resizing to: " << input_resize_percent << "%" << std::endl;
	}
	
	cascade = (CvHaarClassifierCascade*) cvLoad(argv[1], 0, 0, 0);
	storage = cvCreateMemStorage(0);
	capture = cvCaptureFromAVI(argv[2]);
	
	assert(cascade && storage && capture);
	
	cvNamedWindow("video", 1);
	
	IplImage* frame1 = cvQueryFrame(capture);
	frame = cvCreateImage(cvSize((int)((frame1->width*input_resize_percent)/100) , (int)((frame1->height*input_resize_percent)/100)), frame1->depth, frame1->nChannels);
	
	const int KEY_SPACE  = 32;
	const int KEY_ESC    = 27;
	
	int key = 0;
	do
	{
		frame1 = cvQueryFrame(capture);
		
		if(!frame1)
			
			break;
		
		cvResize(frame1, frame);
		detect(frame);
		
		key = cvWaitKey(10);
		
		if(key == KEY_SPACE)
			key = cvWaitKey(0);
		
		if(key == KEY_ESC)
			break;
	}
	
	while(1);
	cvDestroyAllWindows();
	cvReleaseImage(&frame);
	cvReleaseCapture(&capture);
	cvReleaseHaarClassifierCascade(&cascade);
	cvReleaseMemStorage(&storage);
	
	return 0;
 
}
 
void detect(IplImage *img)
{
	CvSize img_size = cvGetSize(img);
	CvSeq *object = cvHaarDetectObjects(img, cascade, storage,
		1.1, //1.1,//1.5, //-------------------SCALE FACTOR
		1, //2        //------------------MIN NEIGHBOURS
		0, //CV_HAAR_DO_CANNY_PRUNING
		cvSize(0,0),//cvSize( 30,30), // ------MINSIZE
		img_size //cvSize(70,70)//cvSize(640,480)  //---------MAXSIZE
		);
	std::cout << "Total: " << object->total << " cars" << std::endl;
	
	for(int i = 0 ; i < ( object ? object->total : 0 ) ; i++)
	{
		CvRect *r = (CvRect*)cvGetSeqElem(object, i);
		cvRectangle(img,
			cvPoint(r->x, r->y),
			cvPoint(r->x + r->width, r->y + r->height),
			CV_RGB(255, 0, 0), 2, 8, 0);
	}
	
	cvShowImage("video", img);
}

[HBEdit]Added missing code block[/HBEdit]
Posted 29-Apr-13 18:02pm
Updated 29-Apr-13 18:10pm
H.Brydon34.3K
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

A few things that I can identify without looking too hard:
- The precompiled header choice is not set correctly in the project (which gives the missing PCH spec messages)
- The stdafx.h include should be the first one in the list of includes.
- This won't compile. A #include with nothing to the right is illegal.
- It might be a good idea to initialize capture and frame to NULL or nullptr in the declaration.
- What do you anticipate the "while(1);" will do?

I know a little C++ but am not an openCV user; I'm sure other indiscretions exist.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100