(原)在anaconda3+ubuntu16.04中编译Pose flow中的deepmatching动态库

转载请注明出处:

https://www.cnblogs.com/darkknightzh/p/11285239.html

参考网址:

https://github.com/YuliangXiu/PoseFlow

http://xiuyuliang.cn/2014/12/05/deepmatching/

1 简介

pose flow可以直接使用,但是需要编译deep matching的文件夹。官方给出的编译步骤如下:

cd deepmatching
make clean all
make python
cd ..

2 makefile

但是直接使用官方的makefile无法编译成功,需要修改一下。

由于这边是用的是anaconda3,下面直接贴出修改后的makefile:

注意:如果直接拷贝可能由于网页原因,把下面28、31、34等这些行前面的tab换成了空格,导致make的时候出错。此时将这些行的空格改成tab即可。

 1 CC=g++
 2 
 3 OS_NAME=$(shell uname -s)
 4 ifeq ($(OS_NAME),Linux) 
 5   LAPACKLDFLAGS=/home/xxx/anaconda3/lib/libsatlas.so   # single-threaded blas
 6   
 7   #LAPACKLDFLAGS=/usr/lib64/atlas/libtatlas.so  # multi-threaded blas
 8   #BLAS_THREADING=-D MULTITHREADED_BLAS # remove this if wrong
 9 endif
10 ifeq ($(OS_NAME),Darwin)  # Mac OS X
11   LAPACKLDFLAGS=-framework Accelerate # for OS X
12 endif
13 LAPACKCFLAGS=-Dinteger=int $(BLAS_THREADING)
14 STATICLAPACKLDFLAGS=-fPIC -Wall -g -fopenmp -static -static-libstdc++  /home/xxx/anaconda3/lib/libjpeg.a /home/xxx/anaconda3/lib/libpng.a /usr/lib64/libz.a /usr/lib64/libblas.a /usr/lib/gcc/x86_64-redhat-linux/4.9.2/libgfortran.a /usr/lib/gcc/x86_64-redhat-linux/4.9.2/libquadmath.a # statically linked version
15 
16 CFLAGS= -fPIC -Wall -g -std=c++11 $(LAPACKCFLAGS) -fopenmp -DUSE_OPENMP -O3
17 LDFLAGS=-fPIC -Wall -g -ljpeg -lpng -fopenmp  -lblas
18 CPYTHONFLAGS=-I/home/xxx/anaconda3/include/python3.6m
19 
20 SOURCES := $(shell find . -name '*.cpp' ! -name 'deepmatching_matlab.cpp')
21 OBJ := $(SOURCES:%.cpp=%.o)
22 HEADERS := $(shell find . -name '*.h')
23 
24 
25 all: deepmatching 
26 
27 .cpp.o:  %.cpp %.h
28     $(CC) -o $@ $(CFLAGS) -c $+
29 
30 deepmatching: $(HEADERS) $(OBJ)
31     $(CC) -o $@ $^ $(LDFLAGS) $(LAPACKLDFLAGS)   -L/home/xxx/anaconda3/lib -I/home/xxx/anaconda3/include
32 
33 deepmatching-static: $(HEADERS) $(OBJ)
34     $(CC) -o $@ $^ $(STATICLAPACKLDFLAGS)
35 
36 python: $(HEADERS) $(OBJ)
37 #    swig -python $(CPYTHONFLAGS) deepmatching.i # not necessary, only do if you have swig compiler
38     g++ $(CFLAGS) -c deepmatching_wrap.c $(CPYTHONFLAGS)
39     g++ -shared $(LDFLAGS) $(LAPACKLDFLAGS) deepmatching_wrap.o $(OBJ) -o _deepmatching.so $(LIBFLAGS)  -L/home/xxx/anaconda3/lib
40 
41 clean:
42     rm -f $(OBJ) deepmatching *~ *.pyc .gdb_history deepmatching_wrap.o _deepmatching.so deepmatching.mex???

3 说明

3.1. 虽然STATICLAPACKLDFLAGS也进行了修改,但是由于未编译静态库,因而未进行测试这个是否成功。

3.2. 其他修改主要是设置路径,最主要的是LDFLAGS,增加了-lblas,否则我这边会出错。

/home/xxx/anaconda3/lib/libsatlas.so: undefined reference to `_gfortran_stop_numeric'
/home/xxx/anaconda3/lib/libsatlas.so: undefined reference to `_gfortran_pow_i4_i4'
/home/xxx/anaconda3/lib/libsatlas.so: undefined reference to `_gfortran_transfer_character'
/home/xxx/anaconda3/lib/libsatlas.so: undefined reference to `_gfortran_compare_string'
/home/xxx/anaconda3/lib/libsatlas.so: undefined reference to `_gfortran_st_write_done'
/home/xxx/anaconda3/lib/libsatlas.so: undefined reference to `_gfortran_pow_r8_i4'
/home/xxx/anaconda3/lib/libsatlas.so: undefined reference to `_gfortran_concat_string'
/home/xxx/anaconda3/lib/libsatlas.so: undefined reference to `_gfortran_pow_r4_i4'
/home/xxx/anaconda3/lib/libsatlas.so: undefined reference to `_gfortran_etime'
/home/xxx/anaconda3/lib/libsatlas.so: undefined reference to `_gfortran_copy_string'
/home/xxx/anaconda3/lib/libsatlas.so: undefined reference to `_gfortran_transfer_integer'
/home/xxx/anaconda3/lib/libsatlas.so: undefined reference to `_gfortran_st_write'

3.3. 另一方面,31行增加了-L/home/xxx/anaconda3/lib,否则提示下面的错(原因是使用的是anaconda3,这些库都是anaconda3里面的,不在系统目录中)。

/usr/bin/ld: cannot find -ljpeg
/usr/bin/ld: cannot find –lpng

若提示找不到头文件,可以在该行-I处添加。

3.4. deepmatching_wrap.c2983

#include <numpy/arrayobject.h>

修改为

#include </home/xxx/anaconda3/lib/python3.6/site-packages/numpy/core/include/numpy/arrayobject.h>

这个不记得是哪个参考网址里面给出的了(我这边根据anaconda3的路径重新配置了),见谅。。。

3.5 http://xiuyuliang.cn/2014/12/05/deepmatching/中指出,ubuntu中没有libsatlas.so,按照该网页的第一步,直接将libatlas.a liblapack.a libf77blas.a libcblas.a捏成一个即可。在anaconda3中,这些.a文件均在/home/xxx/anaconda3/lib中,因而在该文件夹中打开终端,而后输入网页中的命令即可(若需复制命令,请移步该网页,此处只是保存个备份,如有侵权,我会删除)。

3.6 ~/.bashrc中添加下面两句(不知道为何3.3-I添加了include路径,结果还是有错)

export C_INCLUDE_PATH=/home/xxx/anaconda3/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/home/xxx/anaconda3/include:$CPLUS_INCLUDE_PATH

否则找不到jpeglib.h

io.cpp:19:21: fatal error: jpeglib.h: No such file or directory

 =================================================================================

190807更新:

3.7 编译成功之后,运行pose flow的matching.py时,若使用deep matching,会提示找不到libjpeg.so.9,原因是其不在系统的目录里面。可以将matching.py的最后一句修改成:

解决方法参考网页https://stackoverflow.com/questions/29888716/i-use-os-system-to-run-executable-file-but-it-need-a-so-file-it-cant-find-li

cmd = "LD_LIBRARY_PATH=/home/xxx/anaconda3/lib ./deepmatching/deepmatching %s %s -nt 10 -downscale 3 -out %s/%s_%s.txt > cache"%(img1,img2,vidname,img1_id,img2_id)

之后便可以成功使用deep matching。

190807更新结束

 =================================================================================

posted on 2019-08-01 20:50  darkknightzh  阅读(589)  评论(0编辑  收藏  举报

导航