Qt 编译 Darknet
创建 .pro 文件
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
MainWindow.cpp \
# Darknet_Detector/Darknet_Detector.cpp \
# Darknet_Detector/DarknetDetector.cpp
HEADERS += \
MainWindow.h \
# Darknet_Detector/Darknet_Detector.h \
# Darknet_Detector/yolo_v2_class.hpp \
# Darknet_Detector/DarknetDetector.h
FORMS += \
MainWindow.ui
# OpenCV
INCLUDEPATH += \
/home/chli/OpenCV/opencv-3.4.0/build/installed/include \
/home/chli/OpenCV/opencv-3.4.0/build/installed/include/opencv \
/home/chli/OpenCV/opencv-3.4.0/build/installed/include/opencv2
LIBS += \
-L/home/chli/OpenCV/opencv-3.4.0/build/installed/lib \
-lopencv_highgui \
-lopencv_core \
-lopencv_imgproc \
-lopencv_imgcodecs \
-lopencv_video \
-lopencv_videoio
# Darknet
SOURCES += \
/home/chli/github/darknet/src/softmax_layer.c \
/home/chli/github/darknet/src/l2norm_layer.c \
/home/chli/github/darknet/src/yolo_layer.c \
/home/chli/github/darknet/src/region_layer.c \
/home/chli/github/darknet/src/shortcut_layer.c \
/home/chli/github/darknet/src/parser.c \
/home/chli/github/darknet/src/detection_layer.c \
/home/chli/github/darknet/src/avgpool_layer.c \
/home/chli/github/darknet/src/convolutional_layer.c \
/home/chli/github/darknet/src/maxpool_layer.c \
/home/chli/github/darknet/src/lstm_layer.c \
/home/chli/github/darknet/src/crop_layer.c \
/home/chli/github/darknet/src/cost_layer.c \
/home/chli/github/darknet/src/blas.c \
/home/chli/github/darknet/src/activation_layer.c \
/home/chli/github/darknet/src/route_layer.c \
/home/chli/github/darknet/src/image.c \
/home/chli/github/darknet/src/activations.c \
/home/chli/github/darknet/src/list.c \
/home/chli/github/darknet/src/gemm.c \
/home/chli/github/darknet/src/batchnorm_layer.c \
/home/chli/github/darknet/src/rnn_layer.c \
/home/chli/github/darknet/src/data.c \
/home/chli/github/darknet/src/network.c \
/home/chli/github/darknet/src/cuda.c \
/home/chli/github/darknet/src/crnn_layer.c \
/home/chli/github/darknet/src/im2col.c \
/home/chli/github/darknet/src/dropout_layer.c \
/home/chli/github/darknet/src/deconvolutional_layer.c \
/home/chli/github/darknet/src/local_layer.c \
/home/chli/github/darknet/src/utils.c \
/home/chli/github/darknet/src/image_opencv.cpp \
/home/chli/github/darknet/src/upsample_layer.c \
/home/chli/github/darknet/src/option_list.c \
/home/chli/github/darknet/src/gru_layer.c \
/home/chli/github/darknet/src/tree.c \
/home/chli/github/darknet/src/normalization_layer.c \
/home/chli/github/darknet/src/box.c \
/home/chli/github/darknet/src/connected_layer.c \
/home/chli/github/darknet/src/matrix.c \
#/home/chli/github/darknet/src/compare.c \
/home/chli/github/darknet/src/col2im.c \
/home/chli/github/darknet/src/iseg_layer.c \
/home/chli/github/darknet/src/logistic_layer.c \
/home/chli/github/darknet/src/demo.c \
/home/chli/github/darknet/src/layer.c \
/home/chli/github/darknet/src/reorg_layer.c \
/home/chli/github/darknet/examples/regressor.c \
/home/chli/github/darknet/examples/nightmare.c \
/home/chli/github/darknet/examples/attention.c \
#/home/chli/github/darknet/examples/swag.c \
/home/chli/github/darknet/examples/art.c \
/home/chli/github/darknet/examples/super.c \
/home/chli/github/darknet/examples/rnn.c \
/home/chli/github/darknet/examples/lsd.c \
#/home/chli/github/darknet/examples/dice.c \
/home/chli/github/darknet/examples/go.c \
/home/chli/github/darknet/examples/yolo.c \
/home/chli/github/darknet/examples/captcha.c \
/home/chli/github/darknet/examples/detector.c \
/home/chli/github/darknet/examples/tag.c \
/home/chli/github/darknet/examples/darknet.c \
#/home/chli/github/darknet/examples/rnn_vid.c \
/home/chli/github/darknet/examples/classifier.c \
/home/chli/github/darknet/examples/segmenter.c \
#/home/chli/github/darknet/examples/voxel.c \
/home/chli/github/darknet/examples/coco.c \
/home/chli/github/darknet/examples/cifar.c \
/home/chli/github/darknet/examples/instance-segmenter.c \
#/home/chli/github/darknet/examples/writing.c
HEADERS += \
/home/chli/github/darknet/src/cost_layer.h \
/home/chli/github/darknet/src/crnn_layer.h \
/home/chli/github/darknet/src/layer.h \
/home/chli/github/darknet/src/utils.h \
/home/chli/github/darknet/src/maxpool_layer.h \
/home/chli/github/darknet/src/data.h \
/home/chli/github/darknet/src/batchnorm_layer.h \
/home/chli/github/darknet/src/network.h \
/home/chli/github/darknet/src/list.h \
/home/chli/github/darknet/src/avgpool_layer.h \
/home/chli/github/darknet/src/region_layer.h \
/home/chli/github/darknet/src/stb_image.h \
/home/chli/github/darknet/src/shortcut_layer.h \
/home/chli/github/darknet/src/lstm_layer.h \
/home/chli/github/darknet/src/crop_layer.h \
/home/chli/github/darknet/src/gemm.h \
/home/chli/github/darknet/src/im2col.h \
/home/chli/github/darknet/src/rnn_layer.h \
/home/chli/github/darknet/src/blas.h \
/home/chli/github/darknet/src/normalization_layer.h \
/home/chli/github/darknet/src/reorg_layer.h \
/home/chli/github/darknet/src/tree.h \
/home/chli/github/darknet/src/local_layer.h \
/home/chli/github/darknet/src/col2im.h \
/home/chli/github/darknet/src/demo.h \
/home/chli/github/darknet/src/route_layer.h \
/home/chli/github/darknet/src/upsample_layer.h \
/home/chli/github/darknet/src/convolutional_layer.h \
/home/chli/github/darknet/src/iseg_layer.h \
/home/chli/github/darknet/src/stb_image_write.h \
/home/chli/github/darknet/src/parser.h \
/home/chli/github/darknet/src/logistic_layer.h \
/home/chli/github/darknet/src/gru_layer.h \
/home/chli/github/darknet/src/image.h \
/home/chli/github/darknet/src/option_list.h \
/home/chli/github/darknet/src/activation_layer.h \
/home/chli/github/darknet/src/activations.h \
/home/chli/github/darknet/src/softmax_layer.h \
/home/chli/github/darknet/src/yolo_layer.h \
/home/chli/github/darknet/src/connected_layer.h \
/home/chli/github/darknet/src/dropout_layer.h \
/home/chli/github/darknet/src/classifier.h \
/home/chli/github/darknet/src/detection_layer.h \
/home/chli/github/darknet/src/matrix.h \
/home/chli/github/darknet/src/deconvolutional_layer.h \
/home/chli/github/darknet/src/l2norm_layer.h \
/home/chli/github/darknet/src/cuda.h \
/home/chli/github/darknet/src/box.h \
/home/chli/github/darknet/include/darknet.h
INCLUDEPATH += \
/home/chli/github/darknet/include \
/home/chli/github/darknet/src
CUDA_SOURCES += \
/home/chli/github/darknet/src/blas_kernels.cu \
/home/chli/github/darknet/src/deconvolutional_kernels.cu \
/home/chli/github/darknet/src/activation_kernels.cu \
/home/chli/github/darknet/src/convolutional_kernels.cu \
/home/chli/github/darknet/src/avgpool_layer_kernels.cu \
/home/chli/github/darknet/src/col2im_kernels.cu \
/home/chli/github/darknet/src/crop_layer_kernels.cu \
/home/chli/github/darknet/src/maxpool_layer_kernels.cu \
/home/chli/github/darknet/src/im2col_kernels.cu \
/home/chli/github/darknet/src/dropout_layer_kernels.cu
CUDA_SDK = "/usr/local/cuda-10.0" # Path to cuda SDK install
CUDA_DIR = "/usr/local/cuda-10.0" # Path to cuda toolkit install
# DO NOT EDIT BEYOND THIS UNLESS YOU KNOW WHAT YOU ARE DOING....
SYSTEM_NAME = ubuntu # Depending on your system either 'Win32', 'x64', or 'Win64'
SYSTEM_TYPE = 64 # '32' or '64', depending on your system
CUDA_ARCH = sm_50 # Type of CUDA architecture, for example 'compute_10', 'compute_11', 'sm_10'
NVCC_OPTIONS = --use_fast_math
# include paths
INCLUDEPATH += $$CUDA_DIR/include \
# library directories
QMAKE_LIBDIR += $$CUDA_DIR/lib64/
CUDA_OBJECTS_DIR = ./
# Add the necessary libraries
#CUDA_LIBS = -lcuda -lcudart
CUDA_LIBS += -lcudart -lcufft -lcuda -lcublas -lcurand -lcudnn
# The following makes sure all path names (which often include spaces) are put between quotation marks
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
#LIBS += $$join(CUDA_LIBS,'.so ', '', '.so')
LIBS += \
$$CUDA_LIBS
# Configuration of the Cuda compiler
CONFIG(debug, debug|release) {
# Debug mode
cuda_d.input = CUDA_SOURCES
cuda_d.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
cuda_d.commands = $$CUDA_DIR/bin/nvcc -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$NVCC_LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda_d.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda_d
}
else {
# Release mode
cuda.input = CUDA_SOURCES
cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
cuda.commands = $$CUDA_DIR/bin/nvcc $$NVCC_OPTIONS $$CUDA_INC $$NVCC_LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda
}
DISTFILES += \
/home/chli/github/darknet/examples/detector-scipy-opencv.py \
/home/chli/github/darknet/examples/detector.py
TRANSLATIONS += \
Darknet_Detector_Qt_zh_CN.ts
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
修改源码
darknet.h 最开始
#ifndef GPU
#define GPU
#endif
#ifndef CUDNN
#define CUDNN
#endif
#ifndef OPENCV
#define OPENCV
#endif
image_opencv.cpp 最开始
#define OPENCV
im2col.h 最开始
#ifndef GPU
#define GPU
#endif
col2im.h 最开始
#ifndef GPU
#define GPU
#endif
cuda.h 中 #ifdef GPU 前一行添加
#define GPU
cuda.c 最开始
#include "cuda.h"
attention.c 中
void validate_attention_single()
show_image(*, *) 改为
show_image(*, *, 1)
屏蔽
darknet.c
中的函数
int main(int argc, char **argv)
检测调用
详见源码调用方式
darknet.c