Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Errors while building

Hello everyone, so imported opencv in my visual studio, did all right but i get errors...

https://pastebin.com/JwNQjRqx

trying to solve it for day i ran out of ideas... when i build only with

#include <opencv2\core.hpp>
#include <opencv2\highgui.hpp>

I get successful build ...

Errors while building

Hello everyone, so imported opencv in my visual studio, did all right but i get errors...

https://pastebin.com/JwNQjRqx

a  Source.cpp
C:\Users\A\source\repos\opencv410\opencv410\Source.cpp(33,31): warning C4244:  '=': conversion from 'double' to 'int', possible loss of data
C:\Users\A\source\repos\opencv410\opencv410\Source.cpp(34,32): warning C4244:  '=': conversion from 'double' to 'int', possible loss of data
     Creating library C:\Users\A\source\repos\opencv410\x64\Release\opencv410.lib and object C:\Users\A\source\repos\opencv410\x64\Release\opencv410.exp
Source.obj : error LNK2001: unresolved external symbol "void __cdecl cv::equalizeHist(class cv::_InputArray const &,class cv::_OutputArray const &)" (?equalizeHist@cv@@YAXAEBV_InputArray@1@AEBV_OutputArray@1@@Z)
Source.obj : error LNK2001: unresolved external symbol "public: virtual double __cdecl cv::VideoCapture::get(int)const " (?get@VideoCapture@cv@@UEBANH@Z)
Source.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl cv::VideoCapture::release(void)" (?release@VideoCapture@cv@@UEAAXXZ)
Source.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl cv::VideoCapture::isOpened(void)const " (?isOpened@VideoCapture@cv@@UEBA_NXZ)
Source.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl cv::VideoCapture::open(int,int)" (?open@VideoCapture@cv@@UEAA_NHH@Z)
Source.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl cv::VideoCapture::~VideoCapture(void)" (??1VideoCapture@cv@@UEAA@XZ)
Source.obj : error LNK2001: unresolved external symbol "public: __cdecl cv::VideoCapture::VideoCapture(void)" (??0VideoCapture@cv@@QEAA@XZ)
Source.obj : error LNK2001: unresolved external symbol "void __cdecl cv::cvtColor(class cv::_InputArray const &,class cv::_OutputArray const &,int,int)" (?cvtColor@cv@@YAXAEBV_InputArray@1@AEBV_OutputArray@1@HH@Z)
Source.obj : error LNK2001: unresolved external symbol "public: void __cdecl cv::CascadeClassifier::detectMultiScale(class cv::_InputArray const &,class std::vector<class cv::Rect_<int>,class std::allocator<class cv::Rect_<int> > > &,double,int,int,class cv::Size_<int>,class cv::Size_<int>)" (?detectMultiScale@CascadeClassifier@cv@@QEAAXAEBV_InputArray@2@AEAV?$vector@V?$Rect_@H@cv@@V?$allocator@V?$Rect_@H@cv@@@std@@@std@@NHHV?$Size_@H@2@2@Z)
Source.obj : error LNK2001: unresolved external symbol "public: bool __cdecl cv::CascadeClassifier::load(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?load@CascadeClassifier@cv@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
Source.obj : error LNK2001: unresolved external symbol "public: __cdecl cv::CascadeClassifier::~CascadeClassifier(void)" (??1CascadeClassifier@cv@@QEAA@XZ)
Source.obj : error LNK2001: unresolved external symbol "public: __cdecl cv::CascadeClassifier::CascadeClassifier(void)" (??0CascadeClassifier@cv@@QEAA@XZ)
Source.obj : error LNK2001: unresolved external symbol "void __cdecl cv::ellipse(class cv::_InputOutputArray const &,class cv::Point_<int>,class cv::Size_<int>,double,double,double,class cv::Scalar_<double> const &,int,int,int)" (?ellipse@cv@@YAXAEBV_InputOutputArray@1@V?$Point_@H@1@V?$Size_@H@1@NNNAEBV?$Scalar_@N@1@HHH@Z)
Source.obj : error LNK2001: unresolved external symbol "void __cdecl cv::resize(class cv::_InputArray const &,class cv::_OutputArray const &,class cv::Size_<int>,double,double,int)" (?resize@cv@@YAXAEBV_InputArray@1@AEBV_OutputArray@1@V?$Size_@H@1@NNH@Z)
C:\Users\A\source\repos\opencv410\x64\Release\opencv410.dll : fatal error LNK1120: 14 unresolved externals

trying to solve it for day i ran out of ideas... when i build only with

#include <opencv2\core.hpp>
#include <opencv2\highgui.hpp>

I get successful build ...... but with this code i get errors...

#include "opencv2/objdetect.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

// Declare structure to be used to pass data from C++ to Mono.
struct Circle
{
    Circle(int x, int y, int radius) : X(x), Y(y), Radius(radius) {}
    int X, Y, Radius;
};

CascadeClassifier _faceCascade;
String _windowName = "Unity OpenCV Interop Sample";
VideoCapture _capture;
int _scale = 1;

extern "C" int __declspec(dllexport) __stdcall  Init(int& outCameraWidth, int& outCameraHeight)
{
    // Load LBP face cascade.
    if (!_faceCascade.load("lbpcascade_frontalface.xml"))
        return -1;

    // Open the stream.
    _capture.open(0);
    if (!_capture.isOpened())
        return -2;

    outCameraWidth = _capture.get(CAP_PROP_FRAME_WIDTH);
    outCameraHeight = _capture.get(CAP_PROP_FRAME_HEIGHT);

    return 0;
}

extern "C" void __declspec(dllexport) __stdcall  Close()
{
    _capture.release();
}

extern "C" void __declspec(dllexport) __stdcall SetScale(int scale)
{
    _scale = scale;
}

extern "C" void __declspec(dllexport) __stdcall Detect(Circle* outFaces, int maxOutFacesCount, int& outDetectedFacesCount)
{
    Mat frame;
    _capture >> frame;
    if (frame.empty())
        return;

    std::vector<Rect> faces;
    // Convert the frame to grayscale for cascade detection.
    Mat grayscaleFrame;
    cvtColor(frame, grayscaleFrame, COLOR_BGR2GRAY);
    Mat resizedGray;
    // Scale down for better performance.
    resize(grayscaleFrame, resizedGray, Size(frame.cols / _scale, frame.rows / _scale));
    equalizeHist(resizedGray, resizedGray);

    // Detect faces.
    _faceCascade.detectMultiScale(resizedGray, faces);

    // Draw faces.
    for (size_t i = 0; i < faces.size(); i++)
    {
        Point center(_scale * (faces[i].x + faces[i].width / 2), _scale * (faces[i].y + faces[i].height / 2));
        ellipse(frame, center, Size(_scale * faces[i].width / 2, _scale * faces[i].height / 2), 0, 0, 360, Scalar(0, 0, 255), 4, 8, 0);

        // Send to application.
        outFaces[i] = Circle(faces[i].x, faces[i].y, faces[i].width / 2);
        outDetectedFacesCount++;

        if (outDetectedFacesCount == maxOutFacesCount)
            break;
    }

    // Display debug output.
    imshow(_windowName, frame);
}