车辆检测使用VS 2010和Open CV2.4.3问题 [英] Vehicle detection Using VS 2010 and Open CV2.4.3 problem

查看:116
本文介绍了车辆检测使用VS 2010和Open CV2.4.3问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..我看了你管上的某个视频教程后得到了这段代码。但每当我尝试运行它时,我总是会得到以下错误...

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







我试过调试但没有进展。当我也检查haarcascade目录时,我没有找到任何关于汽车检测的xml文件。所以任何帮助我都会感激不尽。代码在下面






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]



[HBEdit]Added missing code block[/HBEdit]

推荐答案

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.
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.


这篇关于车辆检测使用VS 2010和Open CV2.4.3问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆