- 從 C++ 端呼叫 Python 的一個 Function。
- 將從 C++ 用 OpenCV 讀進來的 Mat 資料結構轉換成 Numpy Array。
- 把 Numpy Array 當成參數傳進 Python Function。
棒球癡;電影狂;讀書人。
傳說中的陽光宅男。
Google Code Prettify
2017年9月2日 星期六
[C++] Pass an OpenCV Mat Image to a Python Function
最近因工作需要而研究了一陣子 C++ 與 Python 的互動,主要達成以下幾件事:
2016年3月22日 星期二
Babun 透明化及 oh-my-zsh 的 powerline 主題配置
自從前兩天發現 Babun 這個好物之後,我就開始研究這個 Windows 下的 Unix-like 終端機的環境配置。至此算是小有成果,打造了個看起來蠻漂亮的開發環境。
有了這東西,我再也不需要用醜醜的 Pietty 遠端到伺服器進行作業啦!! 順帶一提,伺服器部分我當然也安裝了 oh-my-zsh + powerline 主題,否則就發揮不出 Babun 的魅力啦~
有了這東西,我再也不需要用醜醜的 Pietty 遠端到伺服器進行作業啦!! 順帶一提,伺服器部分我當然也安裝了 oh-my-zsh + powerline 主題,否則就發揮不出 Babun 的魅力啦~
2015年8月28日 星期五
Caffe + Ubuntu 15.04 + CUDA 7.0 編譯安裝
花費近一週的時間,總算是把Caffe成功編譯安裝在Ubuntu15.04的伺服器主機上面了... 因故在此紀錄下整個安裝過程的筆記!
然而時間過太久,較前面的步驟遇到的問題已記不得了,在照著流程走的過程中遇到沒提到的問題再自行Google解決吧。
整個流程大致上是按照以下二篇參考教學的指示:
Caffe + Ubuntu 15.04 + CUDA 7.0 新手安裝配置指南
caffe+cuda7.0+opencv3.0.0+mkl ubuntu14.04配置
接著紀錄下我的安裝過程。
然而時間過太久,較前面的步驟遇到的問題已記不得了,在照著流程走的過程中遇到沒提到的問題再自行Google解決吧。
整個流程大致上是按照以下二篇參考教學的指示:
Caffe + Ubuntu 15.04 + CUDA 7.0 新手安裝配置指南
caffe+cuda7.0+opencv3.0.0+mkl ubuntu14.04配置
接著紀錄下我的安裝過程。
2015年8月10日 星期一
Image Features 轉換為 HTK File Format
鑑於最近研究用HMM進行手勢影像辨識,接觸了HTK Toolkit。該工具原是主要用於Speech Recognition,但只要將影像特徵轉換為適合的 File Format 則亦可進行 HMM 的訓練及使用。
要轉換的 feature vectors 基本上以如下格式儲存:
每行代表一個 feature vector ,檔頭的 135 表示每個 feature vector 的維度為 135 。
轉換的 code 是基於 LIACS 的 code 做一點修改,使之能處理小數的特徵值,並可將數張影像的 feature vectors 一次轉換為 HTK Format 。
以下只呈現修改過的部份:
frames 表示欲轉換的 feature vectors 數量(即影片 frame 數);
HTK_WriteHeader 的參數 3 為 feature vector 維度 * sizeof(float),參數 4 為HTK_USER 表示自訂特徵類型;
變數 x type 改為 float ,方可接受小數特徵值。
欲驗證輸出的 HTK File Format 是否正確,可使用 HTK Tools 裡的 HList:
參考文獻
要轉換的 feature vectors 基本上以如下格式儲存:
135 1 0.0328217 0.0100089 0.000778311 0 4.92805e-005 5.75842e-007 1 0.0777054 0.129443 0.0319161 0.0646412 0.0244341 0.0152372 0.00485908 0.0127946 0.0031298 0.00783502 0.0125285 0.00126586 0.0105069 0.00283716 0.00630043 0.0025311 0.00454009 0.00269783 0.00262739 0.00419814 0.00102193 0.00319554 0.00344698 0.00145266 0.00241564 0.00231722 0.00144811 0.000919769 0.00106583 0.00170757 0.00113995 0.00193437 0.00134729 0.000975564 0.00163894 0.00160577 0.0010904 0.000848026 0.00160142 0.00176397 0.00176891 0.00204451 0.000736588 0.000142591 0.000819708 0.000699803 0.000852419 0.000318257 0.0004559 0.00084382 0.00070141 0.000193684 0.000341556 0.00121724 0.00114435 0.000771485 0.00137698 0.00106348 0.001131 0.00066602 0.00113994 0.000994646 0.000689515 0.000134377 0.000611667 0.000816581 7.27596e-012 0.000455511 0.000862932 0.000542742 0.000790653 0.00015376 0.000667005 0.00185994 0.00118799 0.00195221 0.00048036 0.00203206 0.0017036 0.00115241 0.00159665 0.000456289 0.00245261 0.00115743 0.00212574 0.000759982 0.00161923 0.000970768 0.000446351 0.0025218 0.000559381 0.00170117 0.00145245 0.00123497 0.00162679 0.0014485 0.00113292 0.00180706 0.00172861 0.00261046 0.000791285 0.00385214 0.00245815 0.0020356 0.00148777 0.00122579 0.00334875 0.00294233 0.00460947 0.0024289 0.00304412 0.00934439 0.00441411 0.00604666 0.00464733 0.010632 0.0119068 0.0184638 0.0183619 0.0177572 0.0191143 0.027884 0.0404363 0.0691513 0.0750528 0.167004 0.469292 ...
每行代表一個 feature vector ,檔頭的 135 表示每個 feature vector 的維度為 135 。
轉換的 code 是基於 LIACS 的 code 做一點修改,使之能處理小數的特徵值,並可將數張影像的 feature vectors 一次轉換為 HTK Format 。
以下只呈現修改過的部份:
float reverse_float( const float inFloat )
{
float retVal;
char *floatToConvert = ( char* ) & inFloat;
char *returnFloat = ( char* ) & retVal;
// swap the bytes into a temporary buffer
returnFloat[0] = floatToConvert[3];
returnFloat[1] = floatToConvert[2];
returnFloat[2] = floatToConvert[1];
returnFloat[3] = floatToConvert[0];
return retVal;
}
int main(int argc, char* argv[])
{
...
int number, frames = 61;
int i, j; float x;
...
/* Write the binary HTK header file */
HTK_WriteHeader(out,(unsigned int) number, (unsigned int) 1, (short) number * sizeof(float), (short) HTK_USER);
for (j = 0; j < frames; ++j) {
/* Write the data samples with 2 bytes per sample */
for (i=0; i<number; i++)
{
fscanf(in, "%f", &x);
printf("%d: %f\n",i,x);
//x = byte_swap_short(x);
x = reverse_float(x);
fwrite(&(x),sizeof(float),1,out);
}
}
fclose(out);
fclose(in);
/* Test the HTK I/O */
//HTK_test(argv[2]);
}
return 0;
}
frames 表示欲轉換的 feature vectors 數量(即影片 frame 數);
HTK_WriteHeader 的參數 3 為 feature vector 維度 * sizeof(float),參數 4 為HTK_USER 表示自訂特徵類型;
變數 x type 改為 float ,方可接受小數特徵值。
欲驗證輸出的 HTK File Format 是否正確,可使用 HTK Tools 裡的 HList:
- hlist -h filename > log.txt
2015年7月3日 星期五
編譯Matlab Deep Learning Tool: MatConvNet
Requirement
"It seems that the '-cxx' argument was introduces in mex in Matlab R2014, so that's why it ended up with error..." by lenck: error in compiling GPU version with windows 7 + matlab 2013b #35
Installation & Testing
Installing and compiling the library
Quick start
基本上CPU版照做就可以了,GPU可能還有點問題。
p.s. 安裝過程檔案路徑最好不要有中文,不然出錯你找一輩子都找不到原因...
- Matlab 2014a (or above)
- Any C/C++ Compiler (recommand Visual Studio 201x)
Usage: MEX [option1 ... optionN] sourcefile1 [... sourcefileN] [objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN] Use the -help option for more information, or consult the MATLAB API Guide. D:\TOOLS\MATLAB\R2013A\BIN\MEX.PL: Error: Unrecognized switch: -cxx. Error using mex (line 206) Unable to complete successfully. Error in vl_compilenn>mex_link (line 323) mex(mopts{:}) ; Error in vl_compilenn (line 287) mex_link(opts, ...
"It seems that the '-cxx' argument was introduces in mex in Matlab R2014, so that's why it ended up with error..." by lenck: error in compiling GPU version with windows 7 + matlab 2013b #35
Installation & Testing
Installing and compiling the library
Quick start
基本上CPU版照做就可以了,GPU可能還有點問題。
p.s. 安裝過程檔案路徑最好不要有中文,不然出錯你找一輩子都找不到原因...
2014年3月2日 星期日
Xperia SL 6.2.B.1.96解鎖 & root & recovery & 刷ROM
提醒:以下筆記所提供之資訊皆源自Android 台灣中文網-Android(安卓,安致)討論區 - APK.TW,建議先於此論壇註冊用戶方能觀看內容。:)
2013年11月22日 星期五
編譯OpenCV-2.4.7於Visual Studio 2012使其支援GPU-CUDA
2014.10.03 更新:
找到一篇參考文章
Cuda Tech News: CUDA 5.5 + OpenCV 2.4.9 + Visual Studio 2012
──────────────────────────────────────────────────────
先前在2.4.6版試了很久都失敗,果斷心一橫下載2.4.7來編譯就過了。
然而2.4.7的highgui library不知是否有bug,導致無法將影片讀取進來。暫時的解決辦法是使用2.4.6的highgui library做代替。
找到一篇參考文章
Cuda Tech News: CUDA 5.5 + OpenCV 2.4.9 + Visual Studio 2012
──────────────────────────────────────────────────────
先前在2.4.6版試了很久都失敗,果斷心一橫下載2.4.7來編譯就過了。
然而2.4.7的highgui library不知是否有bug,導致無法將影片讀取進來。暫時的解決辦法是使用2.4.6的highgui library做代替。
訂閱:
文章 (Atom)