COMPILE_TIME_ASSERTs 都无法将 dlib 引用为共享库
COMPILE_TIME_ASSERTs all fail referencing dlib as shared library
我正在尝试为 dlib 编写一个 JNI 包装器,以便我可以在 Java 中获取面部描述符。
我已经编写了 jni 代码来执行此操作,但我似乎无法 make
它(在 MacOS X 上)。
我的 JNI 不会产生任何编译错误,但是当 make
-ing 时,大量 COMPILE_TIME_ASSERTS 会失败。
我哪里做错了,我怎样才能成功做到这一点?
CmakeLists.txt:
cmake_minimum_required(VERSION 2.8.12)
project(dlib-jni)
set(CMAKE_CXX_STANDARD 11)
# add_subdirectory(../dlib dlib_build)
include_directories(src)
find_package(dlib REQUIRED) #possibly supporting components!
# include_directories(${OpenCV_INCLUDE_DIRS})
message(STATUS "Using dlib-${dlib_VERSION}")
find_package(OpenCV 3 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
find_package(JNI REQUIRED)
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
message (STATUS "JAVA_INCLUDE_PATH =${JAVA_INCLUDE_PATH}")
message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
message (STATUS "JAVA_JVM_LIBRARY=${JAVA_JVM_LIBRARY}")
include_directories(${JNI_INCLUDE_DIRS})
add_library(dlib_jni SHARED src/dlib-jni.cpp)
target_link_libraries(dlib_jni dlib::dlib opencv_core opencv_highgui)
cmake 命令:
cmake -DOpenCV_DIR=/usr/local/opt/opencv/share/OpenCV/OpenCVConfig.cmake ../
cmake 输出:
-- The C compiler identification is AppleClang 9.1.0.9020039
-- The CXX compiler identification is AppleClang 9.1.0.9020039
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using dlib-19.15.99
-- Found OpenCV: /usr/local (found suitable version "3.3.1", minimum required is "3")
-- Found JNI: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libjawt.dylib
-- JNI_INCLUDE_DIRS=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/include;/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/include/darwin;/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/include
-- JAVA_INCLUDE_PATH =/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/include
-- JNI_LIBRARIES=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libjawt.dylib;/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/server/libjvm.dylib
-- JAVA_JVM_LIBRARY=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/server/libjvm.dylib
-- Configuring done
CMake Warning (dev):
Policy CMP0042 is not set: MACOSX_RPATH is enabled by default. Run "cmake
--help-policy CMP0042" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.
MACOSX_RPATH is not specified for the following targets:
dlib_jni
This warning is for project developers. Use -Wno-dev to suppress it.
-- Generating done
-- Build files have been written to: /Users/me/gitrepos/dlib-jni/build
制作命令:
make && make install
第一个错误(有很多):
/usr/local/include/dlib/array2d/../geometry/../image_processing/../image_transforms/image_pyramid.h:940:13: error: static_assert failed "Failed assertion"
COMPILE_TIME_ASSERT( pixel_traits<in_pixel_type>::has_alpha == false );
COMPILE_TIME_ASSERT
是为了确保您使用 dlib 的代码实际上是正确的。
碰巧我的不是。
在我的例子中,我从 OpenCV Mat 创建了一个 dlib cv_image,如下所示:
dlib::cv_image<rgb_pixel_apha> img(image);
然后像这样尝试检测人脸:
std::vector<dlib::matrix<rgb_pixel>> faces;
for (auto face : detector(img))
...
眼尖的开发人员会注意到它们的模板化方式不同。一个是 rgb_pixel_alpha
,另一个是 rgb_pixel
.
COMPILE_TIME_ASSERT 检查在此拾取的 alpha 通道。我只是没有正确理解错误。
我正在尝试为 dlib 编写一个 JNI 包装器,以便我可以在 Java 中获取面部描述符。
我已经编写了 jni 代码来执行此操作,但我似乎无法 make
它(在 MacOS X 上)。
我的 JNI 不会产生任何编译错误,但是当 make
-ing 时,大量 COMPILE_TIME_ASSERTS 会失败。
我哪里做错了,我怎样才能成功做到这一点?
CmakeLists.txt:
cmake_minimum_required(VERSION 2.8.12)
project(dlib-jni)
set(CMAKE_CXX_STANDARD 11)
# add_subdirectory(../dlib dlib_build)
include_directories(src)
find_package(dlib REQUIRED) #possibly supporting components!
# include_directories(${OpenCV_INCLUDE_DIRS})
message(STATUS "Using dlib-${dlib_VERSION}")
find_package(OpenCV 3 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
find_package(JNI REQUIRED)
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
message (STATUS "JAVA_INCLUDE_PATH =${JAVA_INCLUDE_PATH}")
message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
message (STATUS "JAVA_JVM_LIBRARY=${JAVA_JVM_LIBRARY}")
include_directories(${JNI_INCLUDE_DIRS})
add_library(dlib_jni SHARED src/dlib-jni.cpp)
target_link_libraries(dlib_jni dlib::dlib opencv_core opencv_highgui)
cmake 命令:
cmake -DOpenCV_DIR=/usr/local/opt/opencv/share/OpenCV/OpenCVConfig.cmake ../
cmake 输出:
-- The C compiler identification is AppleClang 9.1.0.9020039
-- The CXX compiler identification is AppleClang 9.1.0.9020039
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using dlib-19.15.99
-- Found OpenCV: /usr/local (found suitable version "3.3.1", minimum required is "3")
-- Found JNI: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libjawt.dylib
-- JNI_INCLUDE_DIRS=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/include;/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/include/darwin;/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/include
-- JAVA_INCLUDE_PATH =/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/include
-- JNI_LIBRARIES=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libjawt.dylib;/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/server/libjvm.dylib
-- JAVA_JVM_LIBRARY=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/server/libjvm.dylib
-- Configuring done
CMake Warning (dev):
Policy CMP0042 is not set: MACOSX_RPATH is enabled by default. Run "cmake
--help-policy CMP0042" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.
MACOSX_RPATH is not specified for the following targets:
dlib_jni
This warning is for project developers. Use -Wno-dev to suppress it.
-- Generating done
-- Build files have been written to: /Users/me/gitrepos/dlib-jni/build
制作命令:
make && make install
第一个错误(有很多):
/usr/local/include/dlib/array2d/../geometry/../image_processing/../image_transforms/image_pyramid.h:940:13: error: static_assert failed "Failed assertion"
COMPILE_TIME_ASSERT( pixel_traits<in_pixel_type>::has_alpha == false );
COMPILE_TIME_ASSERT
是为了确保您使用 dlib 的代码实际上是正确的。
碰巧我的不是。
在我的例子中,我从 OpenCV Mat 创建了一个 dlib cv_image,如下所示:
dlib::cv_image<rgb_pixel_apha> img(image);
然后像这样尝试检测人脸:
std::vector<dlib::matrix<rgb_pixel>> faces;
for (auto face : detector(img))
...
眼尖的开发人员会注意到它们的模板化方式不同。一个是 rgb_pixel_alpha
,另一个是 rgb_pixel
.
COMPILE_TIME_ASSERT 检查在此拾取的 alpha 通道。我只是没有正确理解错误。