(原)在anaconda3+ubuntu16.04中編譯Pose flow中的deepmatching動態庫

轉載請註明出處:html

http://www.javashuo.com/article/p-xaysocrg-er.htmlpython

參考網址:linux

https://github.com/YuliangXiu/PoseFlowc++

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

1 簡介

pose flow能夠直接使用,可是須要編譯deep matching的文件夾。官方給出的編譯步驟以下:github

cd deepmatching
make clean all
make python
cd ..

2 makefile

可是直接使用官方的makefile沒法編譯成功,須要修改一下。shell

因爲這邊是用的是anaconda3,下面直接貼出修改後的makefile:ubuntu

注意:若是直接拷貝可能因爲網頁緣由,把下面2八、3一、34等這些行前面的tab換成了空格,致使make的時候出錯。此時將這些行的空格改爲tab便可。bash

 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更新結束

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

相關文章
相關標籤/搜索