2016年6月17日 星期五

caffe fast-rcnn GPU編譯流程

caffe fast-rcnn GPU編譯流程(含python layer)

2015/12/21 | 
嗨, 大家好今天要來分享的是 fast-rcnn GPU編譯流程
1. 前期準備工作, 安裝相依程式
#下列為C++ 快速安裝方式, 若想要安裝最新版本請至各官網下載自行編譯
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
#下列為python 快速安裝方式
sudo apt-get -y install python-pip
cd ./caffe-fast-rcnn/python
for req in $(cat requirements.txt); do sudo pip install $req; done
#install easydict
wget https://pypi.python.org/packages/source/e/easydict/easydict-1.6.zip
unzip easydict-1.6.zip
cd easydict-1.6
python setup.py install
#下列為安裝CUDA 流程
#先到官網下載安裝檔
https://developer.nvidia.com/cuda-downloads
#Ctrl + Alt + F1
sudo lightdm stop
sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb
sudo apt-get update
sudo apt-get install cuda
#安裝驅動期間必須要重新開機才能繼續
#安裝cuDNN
tar -zxf cudnn-7.0-linux-x64-v3.0-prod.tgz
cd cuda
sudo cp lib64/* /usr/local/cuda/lib64/
sudo cp include/cudnn.h /usr/local/cuda/include/
#build caffe
cp Makefile.config.example Makefile.config
vi Makefile.config
#1.Uncomment the line: USE_CUDNN := 1 and WITH_PYTHON_LAYER := 1
#2.Make sure the CUDA_DIR correctly points to our CUDA installation.
make pycaffe -j8
make all -j8
make test -j8
cd ./caffe-fast-rcnn/lib
rm ./nms/*.so
make
#恭喜完成

parse command line arguments in bash


./myscript.sh -e conf -s /etc -l /usr/lib /etc/hosts

#!/bin/bash
# Use -gt 1 to consume two arguments per pass in the loop (e.g. each
# argument has a corresponding value to go with it).
# Use -gt 0 to consume one or more arguments per pass in the loop (e.g.
# some arguments don't have a corresponding value to go with it such
# as in the --default example).
# note: if this is set to -gt 0 the /etc/hosts part is not recognized ( may be a bug )
while [[ $# -gt 1 ]]
do
key="$1"

case $key in
    -e|--extension)
    EXTENSION="$2"
    shift # past argument
    ;;
    -s|--searchpath)
    SEARCHPATH="$2"
    shift # past argument
    ;;
    -l|--lib)
    LIBPATH="$2"
    shift # past argument
    ;;
    --default)
    DEFAULT=YES
    ;;
    *)
            # unknown option
    ;;
esac
shift # past argument or value
done
echo FILE EXTENSION  = "${EXTENSION}"
echo SEARCH PATH     = "${SEARCHPATH}"
echo LIBRARY PATH    = "${LIBPATH}"
echo "Number files in SEARCH PATH with EXTENSION:" $(ls -1 "${SEARCHPATH}"/*."${EXTENSION}" | wc -l)
if [[ -n $1 ]]; then
    echo "Last line of file specified as non-opt/last argument:"
    tail -1 $1
fi


Rotate image around x, y, z axis in OpenCV

記錄一下在網路上找到的資料
http://stackoverflow.com/questions/19093728/rotate-image-around-x-y-z-axis-in-opencv/19110462#19110462

可以對圖片做x , y , z 三軸旋轉

Finally found a way, thanks to this post:https://plus.google.com/103190342755104432973/posts/NoXQtYQThgQ
I let OpenCV calculate the matrix for me, but I'm doing the perspective transform myself (found it easier to implement than putting everything into a cv::Mat)
float rotx, roty, rotz; // set these first
int f = 2; // this is also configurable, f=2 should be about 50mm focal length

int h = img.rows;
int w = img.cols;

float cx = cosf(rotx), sx = sinf(rotx);
float cy = cosf(roty), sy = sinf(roty);
float cz = cosf(rotz), sz = sinf(rotz);

float roto[3][2] = { // last column not needed, our vector has z=0
    { cz * cy, cz * sy * sx - sz * cx },
    { sz * cy, sz * sy * sx + cz * cx },
    { -sy, cy * sx }
};

float pt[4][2] = {{ -w / 2, -h / 2 }, { w / 2, -h / 2 }, { w / 2, h / 2 }, { -w / 2, h / 2 }};
float ptt[4][2];
for (int i = 0; i < 4; i++) {
    float pz = pt[i][0] * roto[2][0] + pt[i][1] * roto[2][1];
    ptt[i][0] = w / 2 + (pt[i][0] * roto[0][0] + pt[i][1] * roto[0][1]) * f * h / (f * h + pz);
    ptt[i][1] = h / 2 + (pt[i][0] * roto[1][0] + pt[i][1] * roto[1][1]) * f * h / (f * h + pz);
}

cv::Mat in_pt = (cv::Mat_<float>(4, 2) << 0, 0, w, 0, w, h, 0, h);
cv::Mat out_pt = (cv::Mat_<float>(4, 2) << ptt[0][0], ptt[0][1],
    ptt[1][0], ptt[1][1], ptt[2][0], ptt[2][1], ptt[3][0], ptt[3][1]);

cv::Mat transform = cv::getPerspectiveTransform(in_pt, out_pt);

cv::Mat img_in = img.clone();
cv::warpPerspective(img_in, img, transform, img_in.size());

2016年6月15日 星期三

Ubuntu 14.04 install boost

如何安裝 boost 到 ubuntu 14.04

1. Download boost
    http://www.boost.org/

2. cd /path/boost/
    sudo apt-get update
  sudo apt-get install build-essential g++ python-dev autotools-dev libicu-dev build-   essential libbz2-dev libboost-all-dev
  ./bootstrap.sh --prefix=/usr/local
  sudo ./b2 install

3. sudo apt-get install libboost-all-dev

2016年6月7日 星期二

Eclipse C++ 打包

在程式的主資料夾建立folder : build
裡面放一個執行檔 build.sh

***
WORKDIR=$(cd "$(dirname "$0")"; pwd)
cd $WORKDIR/../

#將系統內建的也打包進去
find . -type f -perm /a+x -exec ldd {} \; | grep so | sed -e '/^[^\t]/ d' | sed -e 's/\t//' | sed -e 's/.*=..//' | sed -e 's/ (0.*)//' | sort | sed '/^\s*$/d' |  uniq | sed -e '/x86_64-linux-gnu/d' | sed -e '/lib64/d' | sed 's/^/sudo cp /' | sed 's?$? '`pwd`/lib'?' >> copy.sh

#find . -type f -perm /a+x -exec ldd {} \; | grep so | sed -e '/^[^\t]/ d' | sed -e 's/\t//' | sed -e 's/.*=..//' | sed -e 's/ (0.*)//' | sort | sed '/^\s*$/d' |  uniq | sed 's/^/sudo cp /' | sed 's?$? '`pwd`/lib'?' >> copy.sh

mkdir lib
chmod +x copy.sh
./copy.sh
rm copy.sh

***
註解的不將系統內建的連結檔放入lib