我制作了自己的使用Opencv和其他库的库。这是
CMakelists.txt of my library:
cmake_minimum_required(VERSION 3.0)
project("face_module")
add_definitions("-std=c++11" "-Wno-write-strings")
file(GLOB_RECURSE SOURCES "*.cpp"")
file(GLOB_RECURSE HEADERS "*.h"")
add_library("face_module" SHARED ${SOURCES} ${HEADERS})
target_include_directories(
"face_module" PUBLIC "include" )
find_package(OpenCV 3.2.0 REQUIRED)
find_package(jsoncpp REQUIRED)
set( JSONCPP_LIBRARIES jsoncpp curl )
SET(OpenCV_LIBS opencv_core opencv_highgui opencv_videoio opencv_imgproc opencv_imgcodecs )
target_link_libraries("face_module"
"${CMAKE_CURRENT_LIST_DIR}/lib/tensorflow/libtensorflow.so"
"${CMAKE_CURRENT_LIST_DIR}/lib/tensorflow/libtensorflow_framework.so"
${OpenCV_LIBS}
${JSONCPP_LIBRARIES}
pthread)
我在程序中同时使用该库和Opencv:
cmake_minimum_required(VERSION 3.0)
project("database_generator")
add_definitions("-std=c++11" )
file(GLOB SOURCES "database_generator.cpp")
file(GLOB HEADERS "")
add_executable("database_generator" ${SOURCES} ${HEADERS})
target_link_libraries("database_generator"
"face_module")
当我在我的database_generator项目中使用OpenCV VideoCapture时,网络摄像头使我图像变黑。我不明白为什么会这样。 正如您在database_generator的CmakeLists.txt中看到的那样,我没有添加Opencv库,因为它也在我的face_module库中添加了。
在我的图书馆世代中我做了什么不好的事情?
这是我的database_generator的主文件
int main(int argc, char **argv) {
cv::VideoCapture *video_capture = new cv::VideoCapture(0);
if (!video_capture->isOpened()) {
std::cerr << "Can't open camera " << 0 << std::endl;
}
while(1) {
cv::Mat u8x3_image;
*video_capture >> u8x3_image;
std::cout << "lalal"<< u8x3_image.empty() << std::endl;
cv::imshow("facedetector", u8x3_image);
cv::waitKey(100);
}
}
使用前面的代码,相机会向我发送正常图像,但是,当我使用我的类库时,网络摄像头发送的图像是黑色...
编辑: 我还尝试在我的库中做所有事情,只是生成一个可执行文件(没有库)
project("database_generator2")
add_definitions("-std=c++11" )
file(GLOB_RECURSE SOURCES "*.cpp" "../module/database_generator.cpp")
file(GLOB_RECURSE HEADERS "*.h" )
add_executable("database_generator2" ${SOURCES} ${HEADERS})
target_include_directories( "database_generator2" PUBLIC "include" )
find_package(OpenCV 3.2.0 REQUIRED)
find_package(jsoncpp REQUIRED)
set( JSONCPP_LIBRARIES jsoncpp curl )
SET(OpenCV_LIBS opencv_core opencv_highgui opencv_videoio opencv_imgproc opencv_imgcodecs )
target_link_libraries("database_generator2"
"${CMAKE_CURRENT_LIST_DIR}/lib/tensorflow/libtensorflow.so"
"${CMAKE_CURRENT_LIST_DIR}/lib/tensorflow/libtensorflow_framework.so"
${OpenCV_LIBS}
${JSONCPP_LIBRARIES}
pthread)
我也有同样的麻烦,所以问题不是由于库的产生。 我认为它来自Tensoflow库libtensorflow_framework.so libtensorflow.so,但我不明白为什么。
libtensorflow_framework.so:
linux-vdso.so.1 => (0x00007fff575d2000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7afda2b000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7afd722000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7afd505000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f7afd183000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7afcf6d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7afcba3000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7afe7f9000)
libtensorflow.so:
linux-vdso.so.1 => (0x00007ffc32ba1000)
libtensorflow_framework.so => /home/xavier/Desktop/developpement/Network/pam_face_module/library/lib/tensorflow/./libtensorflow_framework.so (0x00007f0bc5a55000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0bc5851000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f0bc5634000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0bc532b000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f0bc4fa9000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0bc4d93000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0bc49c9000)
/lib64/ld-linux-x86-64.so.2 (0x00007f0bc9233000)
这真的很奇怪,因为opencv的读取功能正常工作,但是VideoCapture给我发送了黑色图像:(
Edit2: 太疯狂了,事实上,一旦我使用tensorlow对象,VideoCapture就会向我发送黑色图像...这可能来自tensorflow库编译吗?
答案 0 :(得分:1)
如果您使用的库未正确链接,您甚至都不会获得可执行文件。
这应该有帮助