Processing math: 33%

2016年7月28日 星期四

Ubuntu 開啟ssh 連線

在ubuntu的環境下, 如果想要開啟遠端ssh連線
要安裝 openssh-client and openssh-server
並執行 ssh


sudo apt-get install openssh-client openssh-server 
sudo /etc/init.d/ssh start

安裝好ssh後可以在 /etc/ssh/sshd_config 裡面更改連線的port的位置
port 的預設值是22


如果沒有安裝ssh就連線,  會看到以下錯誤訊息

ssh: connect to host localhost port 22: Connection refused 



2016年7月25日 星期一

Eclipse / macro

Project Macros

This topic describes the various macros that are available for use within projects. They can be used when specifying build command or build options and in general are quite useful when trying to make projects portable and more maintainable.

MacroDescription
${InputFileName}Represents the input file name.
${InputFileExt}Represents the extension of the input file.
${InputFileBaseName}Represents the base name of the input file. That is the file name with an extension stripped.
${InputFileRelPath}Represents the input file path relative to the builder current directory.
${InputDirRelPath}Represents the input file directory path relative to the builder current directory.
${OutputFileName}Represents the output file name.
${OutputFileExt}Represents the output file extension.
${OutputFileBaseName}Represents the output file base name. That is the output file name with an extension stripped.
${OutputFileRelPath}Represents the output file path relative to the current builder directory.
${OutputDirRelPath}Represents the output file directory path relative to the current builder directory.
${ConfigName}Represents the name of a given configuration.
${ConfigDescription}Represents the description of a given configuration.
${BuildArtifactFileName}Represents the name of the build artifact.
${BuildArtifactFileExt}Represents the extension of the build artifact.
${BuildArtifactFileBaseName}Represents the base name of the build artifact.
${BuildArtifactFilePrefix}Represents the prefix of the build artifact.
${ProjName}Represents the name of a given project.
${ProjDirPath}Represents the absolute path of a given project.
${WorkspaceDirPath}Represents the workspace absolute path.
${DirectoryDelimiter}Represents the directory delimiter used on the system. That is the “\? for Win32 systems and the “/? for Unix-like systems. This could be useful, e.g. in the case a user needs the absolute path of an input file. The absolute path would be represented in the following way: CWD{DirectoryDelimiter}${InputFileRelPath}
${PathDelimiter}Represents the default path delimiter used on the system to separate paths in the path environment variables. That is the “;? for Win32 systems and the “:? for Unix-like systems
This might be used in the environment variable definitions
${EclipseVersion}Represents the current Eclipse version.
${CDTVersion}Represents the current CDT version.
${HostOsName}Represents the operating system name on which eclipse is running.
${C2000_CG_ROOT}Installation folder of the C28x code generation tools.
${C5500_CG_ROOT}Installation folder of the C55x code generation tools.
${C6000_CG_ROOT}Installation folder of the C6x code generation tools.
${MSP430_CG_ROOT}Installation folder of the MSP430 code generation tools.
${TMS470_CG_ROOT}Installation folder of the ARM code generation tools.
${CCS_INSTALL_ROOT}Root installation directory of CCS. i.e. the directory installed in + /ccsv4 or /ccsv5
${CG_TOOL_ROOT}Installation folder of the currently selected code generation tools. Will be the same value as the matching <ISA>_CG_ROOT macro.
${CG_TOOL_SUFFIX}Contains the ISA of the currently selected code generation tools. i.e. 2000 for C2000.

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 (catrequirements.txt);dosudopipinstallreq; 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

2016年5月9日 星期一

NO_PUBKEY 575159689BEFB442

Ubuntu 14.04 更新的時候出現了

"Error GPG: http://download.fpcomplete.com stable Release: NO_PUBKEY 575159689BEFB442"

解決方式:
wget -q -O- https://s3.amazonaws.com/download.fpcomplete.com/ubuntu/fpco.key | sudo apt-key add -



2016年5月4日 星期三

Sed 小應用:刪除行尾(首)的最後一個字元


刪除每一行的最後一個字元
sed 's/.$//'

".$" 代表著行尾的前一個任意字元

利用sed來替換文字
sed's/想要被替換的字/替換的字/'

行首

sed 's/^/string/' 行首用'string'代替



2016年5月3日 星期二

google protobuff 3.0.0, ImportError: cannot import name symbol_database

安裝好caffe之後 進行演算法偵測
出現了 "ImportError: cannot import name symbol_database"

解決的方法是移除default的 python-protobuf

$: sudo apt-get remove python-protobuf


**
protobuf-3.0.0 有一個bug

按照以下網址修改
作者:xfxyjwf
https://github.com/xfxyjwf/protobuf/blob/494716a682ef854168e92231a3cdcc89d587d9b9/src/google/protobuf/arena.h

重新編譯google-protobuf即可

無法取得以下的密鑰ID 的公鑰: 1397BC53640DB551

這是google chrome的問題


wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -


That will fix it

Source:
https://www.reddit.com/r/linux4noobs...no_public_key/


2016年3月24日 星期四

Multiple “could not be resolved” problems using Eclipse

最近用eclipse的時候遇到一個很奇怪的問題
我在使用C++11的新功能 chrono的時候 會發現我已經更改了
Properties > C/C++ Build > Setting > GCC C++ Complier
> Dialet  > Language standard = ISO C++1y (-std=c++1y)

但在build project的時候, 會出現很多很多error, 雖然最後仍然可以成功的build出程式
可是無法使用eclipse 來執行程式, 只能用terminate 來啟動

後來上網查到解決辦法

***
Go to Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros, etc. -> Providers -> CDT GCC built-in compiler settings, deactivate Use global provider shared between projects and add the command line argument -std=c++11.

The eclipse live code analysis does not share the same settings with the build compiler. You can also change the setting globally (not just for the project) in Window -> Preferences -> C/C++ -> Build -> Settings -> CDT GCC Built-in Compiler Settings.

**
更改完這些設定之後Rebuild project 
錯誤訊息就會消失了!

2016年3月15日 星期二

python-check there is a existing file in a folder

import os
bIsExist = os.path.exists(file_path)

if there is a file with same path, then bIsExist is True.