2016年6月17日 星期五

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/