yolo2-vs2015-CUDA8.0-OPENCV3.2_DEMO

来源:互联网 发布:七局网络教育 编辑:程序博客网 时间:2024/06/05 11:34

Background

最近想把yolo2的darknet框架在windows下运行,首选当然是宇宙最强IDE了。。。。。
下面是建立yolo2 visual studio工程时遇到的问题,做的记录,欢迎讨论。

Code

完整的VS2015+CUDA8.0+OPENCV3.2代码在这里github。

Prepare

1.opencv

preproceser中定义OPENCV
安装OPENCV3.2,其他版本也可以,安装到一个目录,并设置环境变量
我的OPENCV_DIR是E:\opencv\build\x64\vc14 PATH为%OPENCV_DIR%\bin
vs中设置相应的目录
c/c++ include中 $(OPENCV_DIR)\..\..\include
lib include中 $(OPENCV_DIR)\lib;input中opencv_world320d.lib

2.gpu CUDA

(1)preproceser中定义GPU
重要:右键工程选择build dependencies中添加CUDA选项,为了让vs能够使用nvcc编译器。
(2)更改cu文件编译属性

avatar

(3)设置CUDA_PATH,并设置环境变量,(通常windows安装CUDA时已经自动设置好)
include中$(CUDA_PATH)\include
lib include中$(CUDA_PATH)\lib\x64
inpute 中加入cudart.lib curand.lib cublas.lib

ERROE

1.fatal error C1083: Cannot open include file: ‘unistd.h’: No such file or directory

在Linux下开发的C程序都需要头文件unistd.h,但VC中没有个头文件,所以用VC编译总是报错。 把下面的内容保存为unistd.h,可以解决这个问题。将文件放到工程的include文件夹下,如(..\include)。
#ifndef _UNISTD_H #define _UNISTD_H #include <io.h> #include <process.h> #endif /* _UNISTD_H */

2.fatal error C1083: Cannot open include file: ‘pthread.h’: No such file or directory

缺失的pthread.h文件是yolo框架darknet使用的线程库,需要下载第三方库,新建文件夹3rdparty,将对应的include文件夹目录(..\3rdparty\include),lib文件夹目录(..\3rdparty\lib\x64),dll库目录添加到PATH环境变量或者将dll文件添加到工程所在目录,即sln所在目录。

3.error C2011: ‘timespec’: ‘struct’ type redefinition

将_TIMESPEC_DEFINED加到vs的Preprocessor项

4.error C2065: ‘CLOCK_REALTIME’: undeclared identifier

将对应函数double what_time_is_it_now() 内部实现注释

5.error C2036: ‘void *’: unknown size

(char *)加到对应的变量前 如 memcpy(swp, (char *)arr+(j*size), size);

6.fatal error C1083: Cannot open include file: ‘sys/time.h’: No such file or directory

头文件引用include < sys/time.h>中的sys\time.h是linux系统下文件,在win下不存在,所以可将引用改为#include < time.h>

7.error C2079: ‘time’ uses undefined struct ‘timeval’;error C2224: left of ‘.tv_sec’ must have struct/union type;error C2224: left of ‘.tv_sec’ must have struct/union type;

将对应位置处的有关time的函数及定义注释,其为计算fps,我们改用其他方法计算fps

8.error LNK2019: unresolved external symbol popen referenced in function engine_go

popen函数前加“_”变为“_popen”

9.error LNK2019: unresolved external symbol pclose referenced in function score_game

同上处理”_pclose”

10.error LNK2019: unresolved external symbol sleep referenced in function self_go

同上

Result

以上是我配置过程中我遇到的问题,运行时会一闪而过,这是因为程序需要输入参数,可在vs的debugging中的command arguments 里添加参数,如
detector demo cfg/coco.data cfg/yolo.cfg yolo.weights
注意:其中的data文件需要指定到你的data文件所在处,weight同理。

建立工程中遇到的错误,希望对你有帮助,如果发现错误欢迎留言,共同讨论进步。

原创粉丝点击