【发布时间】:2020-12-04 23:37:49
【问题描述】:
我正在使用最新版本的 dlib 并尝试构建一个 DLL,该 DLL 使用其dlib::frontal_face_detector 和dlib::shape_predictor predictor 检测面部。然而,
在尝试通过简单地使用detector 时:
auto faces = this->detector(img, 0);
我得到这个编译错误:
Severity Code Description Project File Line Suppression State
Error C2146 syntax error: missing ';' before identifier 'pixel_type' Test D:\Codes\Dependencies\include\dlib\image_processing\scan_fhog_pyramid.h 601
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int Test D:\Codes\Dependencies\include\dlib\image_processing\scan_fhog_pyramid.h 601
Error C2027 use of undefined type 'dlib::image_traits<image_type>' Test D:\Codes\Dependencies\include\dlib\image_processing\scan_fhog_pyramid.h 601
这就是代码的样子:
#include <iostream>
#include <tuple>
#include <chrono>
#include <string>
#include <filesystem>
namespace fs = std::filesystem;
#include <functional>
//#include <torch/torch.h>
//#include <torch/script.h>
#include <dlib/opencv.h>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
//#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
class TEST_API Test
{
public:
Test(std::string shape_predictor_path = "");
void main_op(cv::Mat img_ori, bool show_debug_info = true);
~Test();
private:
dlib::frontal_face_detector detector;
dlib::shape_predictor predictor;
//torch::jit::script::Module net;
};
//in Test.cpp
#include <Test/Test.h>
Test::Test(std::string shape_predictor_path)
{
auto cdir = fs::current_path();
detector = dlib::get_frontal_face_detector();
auto landmark_path = shape_predictor_path == "" ? (cdir / "shape_predictor_68_face_landmarks.dat").string() : shape_predictor_path;
auto model_path = (cdir / "net_4.jit").string();
std::cout << "landmark path: " << landmark_path << "model path: " << model_path << std::endl;
dlib::deserialize(landmark_path) >> this->predictor;
//this->net = torch::jit::load(model_path);
}
void Test::main_op(cv::Mat img, bool show_debug_info)
{
try
{
//cv::Mat img_cpy(img);
//grayscale
cv::cvtColor(img, img, cv::COLOR_BGR2GRAY);
auto faces = this->detector(img, 0);
//....
}
catch(std::exception exp)
{
std::cout << exp.what() << std::endl;
}
}
我在 Visual Studio 2019 中与 libtorch1.6 一起使用 OpenCV3.4.11。语言设置为 C++17。 我的 C++ 预处理器中也有这些:
NDEBUG
_CONSOLE
_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
_CRT_SECURE_NO_WARNINGS
我使用的是 dlib 19.21,我包含了它的包含路径,并将 dlibs source.cpp 添加到我的 dll 项目中,并像这样构建我的项目。
这些也是我的构建选项:
/D_TEST_BUILD_DLL /bigobj
为什么我会看到这个错误?我在这里错过了什么?
更新:
如果不使用任何其他库,例如torch,这种情况会再次发生。所以这与任何其他库无关。这是纯粹的 dlib/opencv!
【问题讨论】:
-
请提取并提供minimal reproducible example,如果没有它,您的问题将是题外话。
-
无论是否提供 mre,这个问题都不是题外话。在这种情况下,不需要 imo。万一需要,投票也无济于事。
-
minimal reproducible example 是一种确保问题具有一定质量的工具。您的问题缺乏质量,因为未知代码会导致多个错误。问号太多了,这就是恕我直言不赞成投票的原因。如果您是这里的新用户,我会放过您的,但您在这里的时间足够长,知道这些事情。
-
@UlrichEckhardt,我不会在这里和你争论,因为你刚才提到的同样的原因,我认为没有必要,因为这里显示的大部分代码是实际上主要操作对结果负责。没有一个依赖项会影响相关操作。这是MRE!如果你再看一遍。我刚刚添加了那些
extra信息,以防万一有这样的库冲突。如您所见,问题只是与缺乏适当的转换有关。无论如何,谢谢您的时间。