This is the first time I deal with dll. I am using Opencv3 and Visual C++ to write a face recognition program. I have to load the CascadeClassigier, FaceRecognizer and VideoCapture into the memory before recognizing. They are all classes defined in opencv. And I want to package these classes into a new class and export that with a DLL. The intention I am doing so is to avoid include that many opencv files in my application program.
Here is my code (file name is RecFuncs.h):
#pragma once
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/face/facerec.hpp"
#include "opencv2/face/predict_collector.hpp"
#include <stdio.h>
#include <conio.h>
using namespace std;
using namespace cv;
#ifdef FACEDLL_EXPORTS
#define FACEDLL_API __declspec(dllexport)
#else
#define FACEDLL_API __declspec(dllimport)
#endif
namespace FaceFuncs {
class FACEDLL_API Load
{
public:
Ptr<face::FaceRecognizer> a;
CascadeClassifier b;
VideoCapture c;
};
}
And when I import my dll class, It seems that the class is not complete or undefined. How can I achieve my intention? Any idea or?
Related
I am attempting to make a class to contain some math operations from a CRC math tables handbook I have, in creating one of the functions I got a strange error I had not seem before. The code for both the cpp and the header are below:
//Header File
#include <iostream>
#include <cmath>
#include <string>
#define int "CRCMathLib_H"
using namespace std;
class CRCMathLib
{
public:
int DoReturn_Totient(int Toter); //Error comes from here when trying to declare as an int
};
//CPP Class File
#include "CRCMathLib.h"
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int CRCMathLib::DoReturn_Totient(int Toter)
{
return 0;
}
//CPP Main File
#include <iostream>
#include <cmath>
#include <string>
#include "CRCMathLib.h"
using namespace std;
int main()
{
return 0;
}
The Main file does not do anything as of yet as this is a completely new file for these operations, I believe this may be a preprocessing error and its not picking up on the int statement as I ran it on another PC with VS and it was able to read the statement. anything would help. Also it was requesting a decleration of the header file, so thats why I placed the int there, is this possibly the issue? removing it returns the error of not having a decleration.
In your .h remove #define int "CRCMathLib_H" which is most probably a typo
replace it by
#include <iostream>
#include <cmath>
#include <string>
#pragma once
The #pragma once ensure you can safely include your .h from the cpp implementation file and the main.cpp
You mis understood include guard protection usually done by
ifndef CRCMathLib_H
#define CRCMathLib_H
// all of you .h file delcaration
#endif
This can be easily replace by the #pragma once statement at the begining of the file
More on this here: https://www.learncpp.com/cpp-tutorial/header-guards/
When I use CLion on a Mac to compile C++ code for highlight removal in a single image, there is an error:
Please help me fix it.
#ifndef QX_CVPR09_CTBF_BASIC_H
#define QX_CVPR09_CTBF_BASIC_H
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <numeric>
#include <vector>
#include <process.h>
#include <direct.h>
#include <io.h>
#include <time.h>
#include <string>
#include <memory.h>
#include <algorithm>
#include <functional> // For greater<int>()
#include <iostream>
#if _MSC_VER > 1020 // if VC++ version is > 4.2
using namespace std; // std c++ libs implemented in std
#endif
#define QX_DEF_PADDING 10
#define QX_DEF_THRESHOLD_ZERO 1e-6
class qx_timer {public: void start(); float stop(); void time_display(char *disp=""); void fps_display(char *disp=""); private: clock_t m_begin; clock_t m_end;};
It's a part of my code. The full code is too long.
process.h
process.h is a C header file which contains function declarations and
macros used in working with threads and processes. Most C compilers
that target DOS, Windows 3.1x, Win32, OS/2, Novell NetWare or DOS
extenders supply this header and the library functions in their C
library. Neither the header file nor most of the functions are defined
by either the ANSI/ISO C standard or by POSIX.
Depends on which platform you compile and what standard you use. If you are on linux or compile with c99/ansi standard then this header will probably just not be available (which might be your error)
I am trying to compile C++ code shown below but I got an error saying,
In file included from src/LM.h:3:0,
from src/LM.cpp:1:
src/common.h:30:13: error: ‘hash’ is already declared in this scope
using tr1::hash;
This is the command I used to compile the files below.
g++ -std=c++11 -Wall src/Foo.cpp
Foo.cpp
#include "Foo.h"
...
Foo.h
#ifndef FOO_H
#define FOO_H
#include "common.h"
//more code here
#endif
common.h
#ifndef _COMMON_H_
#define _COMMON_H_
#include <iostream>
#include <fstream>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <utility>
#include <vector>
#include <string>
#include <array>
#include <algorithm>
#include <set>
#include <tr1/unordered_map>
#include <tr1/functional>
namespace std {
using tr1::unordered_map;
using tr1::hash;
} // namespace std
using namespace std;
//more code here
#endif
I want the source code to use std::tr1::unordered_map and std::tr1::hash rather than std::unordered_map and std::hash(Actually I am making some modifications to distributed files which does uses std::tr1::unordered_map and std::tr1::hash).
What is possibly wrong with my codes?
UPD:
https://github.com/clab/fast_align/blob/master/src/port.h seems to do the same thing as mine. However, this compiles without any problem... Have any idea?
There is already std::hash in C++11. You cannot redefine it. You can use another name for tr1::hash.
Probably the best idea (if you really want to use std::tr1::hash/std::tr1::unordered_map instead of C++11 structures) is to write your own namespace in which using all structures, that you want without std::hash/std::unordered_map.
namespace common
{
using std::tr1::hash;
using std::tr1::unordered_map;
using std::vector;
// and so on
}
I tried to make console application that is using my DLL that is taking care of Kinect.
When I am building my project I get:
2>e:\projects\c++\vs\kinect dll\consoleapplication1\consoleapplication1.cpp(4):
warning C4627: '#include "KinectDLL.h"': skipped when looking for precompiled header use
2> Add directive to 'stdafx.h' or rebuild precompiled header
2> e:\michał\projects\c++\vs\kinect dll\kinect dll\depthreader.h(4):
fatal error C1083: Cannot open include file: 'NuiApi.h': No such file or directory
Note: ConsolApplication1 and Kinect DLL are 2 projects in the same solution, first one have one dependency – Kinect DLL project as DLL. I have “use precompile headers” turned off in both projects!
Kinect DLL projects:
KinectDLL.h:
#ifdef KINECTDLL_EXPORTS
#define KINECTDLL_API __declspec(dllexport)
#else
#define KINECTDLL_API __declspec(dllimport)
#endif
DepthReader.h:
#pragma once
#include <ole2.h>
#include <Windows.h>
#include "NuiApi.h"
#include "KinectDLL.h"
namespace KinectDLL{
class DepthReader{
static KINECTDLL_API const int depthWidth = 640;
static KINECTDLL_API const int depthHeight = 480;
static KINECTDLL_API const int bytesPerPixel = 4;
public:
KINECTDLL_API DepthReader(void);
KINECTDLL_API ~DepthReader(void);
KINECTDLL_API int Run(HINSTANCE hInstance, int nCmdShow);
private:
HANDLE depthStreamHandle;
HANDLE nextDepthFrameEvent;
HANDLE depthStream;
BYTE* depthRGBX;
bool nearMode;
INuiSensor* sensor;
//HWND m_hWnd;
HRESULT CreateFirstConnected();
void Update();
void ProcessDepth();
};
}
DepthReader.cpp
#include "stdafx.h"
#include "DepthReader.h"
namespace KinectDLL{
DepthReader::DepthReader(void) :
nextDepthFrameEvent(INVALID_HANDLE_VALUE),
depthStreamHandle(INVALID_HANDLE_VALUE),
nearMode(false),
sensor(NULL)
{
// create heap storage for depth pixel data in RGBX format
depthRGBX = new BYTE[depthWidth*depthHeight*bytesPerPixel];
}
… and so on, mostly copy and pase from MS Kinect examples...
Consoleapplication1 project:
Consolapplication1.cpp:
#include "KinectDLL.h"
#include "stdafx.h"
#include "Rotations.h"
#include "Camera.h"
#include "FileLoader.h"
#include "DepthReader.h"
using namespace std;
Camera camera;
Rotations rotations;
FileLoader fileLoader;
KinectDLL::DepthReader depthReader;
… then there is OpenGL, points from file. I am using Kinect to contole the scene, not to display data from it. No depthReader for now.
Clearly I am doing something stupid but I can't see what. I am reading Microsoft examples about DLL in VC++ but I can't see what is wrong.
I have just finished created a dll with some functions that depend on the skeleton stream from the kinect. What I did was something like this:
#ifdef KINECTFUNCTIONSDLL_EXPORTS
#define KINECTFUNCTIONSDLL_API __declspec(dllexport)
#else
#define KINECTFUNCTIONSDLL_API __declspec(dllimport)
#endif
#include <Windows.h>
#include <NuiApi.h>
using namespace std;
#include <string>
namespace KinectFunctions{
class GestureRecognizer
{
public:
Vector4 KINECTFUNCTIONSDLL_API resta(Vector4 vector1,Vector4 vector2);
}
}
and now for the .cpp:
#include "KinectFunctionsDLL.h"
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <fstream>
using namespace std;
namespace KinectFunctions{
Vector4 GestureRecognizer::resta(Vector4 vector1,Vector4 vector2){
Vector4 salida;
salida.x=vector1.x-vector2.x;
salida.y=vector1.y-vector2.y;
salida.z=vector1.z-vector2.z;
return salida;
}
}
Keep in mind that the project you use to create the dll must be created checking the DLL option (it's a checkbox that appears when you choose to create a new project. Like it is shown here:
https://www.youtube.com/watch?v=yEqRyQhhto8
And of course you need to add the dependencies for the kinect dll, the kinect10.lib and the headers, like in any project where you want to use the device.
I'm currently using the triangle library in my program. The library contains only .c and .h files (no .lib). I get the following error on Visual Studio C++ 2010:
1>data.obj : error LNK2019: unresolved external symbol _triangulate referenced in function "struct triangulateio __cdecl readfile(void)" (?readfile##YA?AUtriangulateio##XZ)
The header file of my data.cpp is the following:
#ifndef DATA_H
#define DATA_H
#include <WinSock2.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <time.h>
#include <GL/gl.h> //include the gl header file
#include <GL/glut.h> //include the glut header file
#include <GL/glu.h> //include the glut header file
#include <armadillo>
//Namespace
using namespace std;
using namespace arma;
extern "C"
{
#ifdef SINGLE
#define REAL float
#else /* not SINGLE */
#define REAL double
#endif /* not SINGLE */
#include "triangle.h"
}
triangulateio readfile();
#endif
Data.cpp
triangulate("pczAevn", &in, &mid, &vorout);
I've already made my program work with a Makefile of mine on Ubuntu, but I need to run my program on windows.
Feel free to ask for more information.
EDIT #1:
If you use the triangle library with VS, you have to put the following instruction on top of the triangle.c file #define TRILIBRARY
Now it compile. Thank you very much for the help.
The linker can't find a definition for "triangulateio readfile()", if it's defined in the .c file my guess is that it isn't built. If you include it in the project it could work.