错误LNK2001:未解析的外部符号“public:static class cv :: CascadeClassifier

时间:2015-03-17 08:36:07

标签: c++ opencv

我正在使用OpenCV在c ++中开发应用程序我已经用OpenCV来管理人脸识别,但我无法编译

我的caras.cpp(比如main.cpp)

#include "stdafx.h"
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <windows.h>

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

#include "mouse.h"
#include "faceRecognizer.h"


using namespace std;
using namespace cv;

int main(int argc, const char** argv)
{
    string hPath = "haarcascade_frontalface_alt.xml";
    mouse m;

    faceRecognizerr FaRe = faceRecognizerr::faceRecognizerr(hPath);
    //Encendemos la web cam 
    VideoCapture captureDevice;
     captureDevice.open(0);
    //Declaramos las variables que haran de imagen
    static Mat captureFrame;
    static Mat grayscaleFrame;

    //create a window to present the results
    namedWindow("outputCapture", 1);

    //create a loop to capture and find faces
    for(;;)
    {

       //capture a new image frame
       captureDevice>>captureFrame;

       //convert captured image to gray scale and equalize
       cvtColor(captureFrame, grayscaleFrame, CV_BGR2GRAY);
       equalizeHist(grayscaleFrame, grayscaleFrame);

       //create a vector array to store the face found
       std::vector<Rect> faces;

       //find faces and store them in the vector array
       FaRe.SetGrayScaleFrame(grayscaleFrame);
       FaRe.FaceDetect(faces);
       //draw a rectangle for all found faces in the vector array on the    original image
       for(int i = 0; i < faces.size(); i++)
       {

           Point pt1(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
           Point pt2(faces[i].x, faces[i].y);
           rectangle(captureFrame, pt1, pt2, cvScalar(0, 255, 0, 0), 1, 8, 0);
       }
       //print the output
       imshow("outputCapture", captureFrame);

   }
   return 0;

}

FaceRecognizer.h

#include <iostream>
#include <stdio.h>
#include <string>

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

using namespace std;
using namespace cv;

///////////////////////////////////////////////////////
///         DECLARACION DE LA CLASE                 ///
///////////////////////////////////////////////////////
class faceRecognizerr{

private :
    static CascadeClassifier face_cascade;
    static string haarcascadeURL;
   static Mat grayScaleFrame;
public :
    faceRecognizerr(string haarcascadeURL);
    void FaceDetect(std::vector<Rect> faces);
    void SetGrayScaleFrame(Mat grayScaleFrame);
};

我的faceRecognizer.cpp

#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <string>

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

using namespace std;
using namespace cv;

#include "faceRecognizer.h"

///////////////////////////////////////////////////////
///                 CONSTRUCTOR                     ///
///////////////////////////////////////////////////////
faceRecognizerr::faceRecognizerr(string haarcascadeURL)
{
    this->haarcascadeURL = haarcascadeURL;
    this->face_cascade.load(this->haarcascadeURL);
}


///////////////////////////////////////////////////////
///         GETTERS Y SETTERS                       ///
///////////////////////////////////////////////////////
void faceRecognizerr::SetGrayScaleFrame(Mat newGrayScaleFrame)
{
    this->grayScaleFrame = newGrayScaleFrame;
}

///////////////////////////////////////////////////////
///              FUNCTIONS Y VOIDS                  ///
///////////////////////////////////////////////////////
void faceRecognizerr::FaceDetect(std::vector<Rect> faces)
{
    this->face_cascade.detectMultiScale(this->grayScaleFrame, faces, 1.1, 3, CV_HAAR_FIND_BIGGEST_OBJECT|CV_HAAR_SCALE_IMAGE);
}

当我运行程序时,我的visual studio会向我返回这些消息:

1>------ Build started: Project: caras, Configuration: Debug Win32 ------
1>Build started 17/03/2015 9:13:11.
1>InitializeBuildStatus:
1>  Touching "Debug\caras.unsuccessfulbuild".
1>ClCompile:
1>  All outputs are up-to-date.
1>  All outputs are up-to-date.
1>  faceRecognizer.cpp
1>  All outputs are up-to-date.
1>caras.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
1>Debug\faceRecognizer.obj : warning LNK4042: object specified more than once; extras ignored
1>Debug\mouse.obj : warning LNK4042: object specified more than once; extras ignored
1>faceRecognizer.obj : error LNK2001: unresolved external symbol "public: static class cv::CascadeClassifier faceRecognizerr::face_cascade" (?face_cascade@faceRecognizerr@@2VCascadeClassifier@cv@@A)
1>faceRecognizer.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > faceRecognizerr::haarcascadeURL" (?haarcascadeURL@faceRecognizerr@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A)
1>faceRecognizer.obj : error LNK2001: unresolved external symbol "public: static class cv::Mat faceRecognizerr::grayScaleFrame" (?grayScaleFrame@faceRecognizerr@@2VMat@cv@@A)
1>C:\Users\Ariel\documents\visual studio 2010\Projects\caras\Debug\caras.exe : fatal error LNK1120: 3 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.02
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我是c ++的新手,我不知道如何在属性上声明和实现类以及如何包含在主程序中。请帮我!

我通过互联网搜索了很多时间,但我找不到任何对我有用的东西。

非常感谢大家!

编辑:

有人要求我的编译命令。我想是这样的:

/OUT:"C:\Users\Ariel\documents\visual studio 2010\Projects\caras\Debug\caras.exe" /INCREMENTAL:NO /NOLOGO "opencv_calib3d2410d.lib" "opencv_contrib2410d.lib" "opencv_core2410d.lib" "opencv_features2d2410d.lib" "opencv_flann2410d.lib" "opencv_gpu2410d.lib" "opencv_highgui2410d.lib" "opencv_imgproc2410d.lib" "opencv_legacy2410d.lib" "opencv_ml2410d.lib" "opencv_objdetect2410d.lib" "opencv_ts2410d.lib" "opencv_video2410d.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Debug\caras.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Users\Ariel\documents\visual studio 2010\Projects\caras\Debug\caras.pdb" /SUBSYSTEM:CONSOLE /PGD:"C:\Users\Ariel\documents\visual studio 2010\Projects\caras\Debug\caras.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE

0 个答案:

没有答案