網頁

2016年11月22日 星期二

Cascade Classifier Training

開啟命令提示字元

set PATH=D:\OpenCV\build_64\install\x64\vc12\bin;%PATH%
set PATH=D:\OpenCV\dep\tbb2017_20160916oss\bin\intel64\vc12;%PATH%
set PATH=D:\Qt\Qt5.7.0_64\5.7\msvc2013_64\bin;%PATH%

cd neg
dir/b>neg.txt
編輯 neg.txt 加入檔案路徑

標註 正樣本
使用 opencv_annotation.exe
"D:\OpenCV\build_64\install\x64\vc12\bin\opencv_annotation.exe" --annotations=20160615.txt --images=20160615\*.jpg
c: add rectangle to current image
n: save added rectangles and show next image
d: delete the last annotation made
<ESC>: exit program(無法使用,請參考下列修正方式)

編輯 opencv_annotation.cpp
case 27
  //destroyWindow(window_name);
  stop = true;
  break;
不然無法用 ESC 結束程式

產生 pos.vec
"D:\OpenCV\build_64\install\x64\vc12\bin\opencv_createsamples.exe" -info pos.txt -vec pos.vec -w 50 -h 25

產生 xml
mkdir xml
"D:\OpenCV\build_64\install\x64\vc12\bin\opencv_traincascade.exe" -data xml -vec pos.vec -bg neg.txt -numPos 150 -numNeg 20 -numStages 20 -maxFalseAlarmRate 0.45 -featureType LBP -w 50 -h 25

-numPos 每級分類器訓練時所用正樣本數目
-numNeg 每級分類器訓練時所用負樣本數目,可大於 -bg 指定的圖片數目
-featureType: HAAR
-featureType: LBP
-mode BASIC 直立
-mode ALL
-minHitRate 0.999 正樣本被判成正樣本的比例
-maxFalseAlarmRate 0.5 負樣本被判成正樣本的比例

錯誤 Required leaf false alarm rate achieved. Branch training terminated.
預設 -maxFalseAlarmRate 0.5

2016年11月7日 星期一

OpenCV statusbar & mouse position

症狀:setMouseCallback 回傳函式的滑鼠位置錯誤,狀態烈沒有顯示滑鼠位置,顏色資訊
對策:開啟 modules/highgui/src/window_QT.h 將下一行增加 virtual 宣告
    void icvmouseProcessing(QPointF pt, int cv_event, int flags);
    virtual void icvmouseProcessing(QPointF pt, int cv_event, int flags);


OpenCV release 版本無法執行

症狀:debug 版本正常,release 版本的程式無法執行,出現如下錯誤
This application failed to start because it could not find or load the Qt platform plugin "windows"
in "".
原因:因為 PATH 環境變數設定錯誤,使用到錯誤的 Qt library
對策:修正 Project Property Pages/Coniguration Properties/Debugging/Environment 的 PATH
PATH=%PATH%;D:\Qt\Qt5.7.0_64\5.7\msvc2013_64\bin;
PATH=D:\Qt\Qt5.7.0_64\5.7\msvc2013_64\bin;%PATH%


除錯路上拾遺

查詢載入 plugin 的過程
設定環境變數 QT_DEBUG_PLUGINS=1
下列兩個環境變數皆可設定 plugin 的路徑
QT_QPA_PLATFORM_PLUGIN_PATH=D:\Qt\Qt5.7.0_64\5.7\msvc2013_64\plugins
QT_PLUGIN_PATH=D:\Qt\Qt5.7.0_64\5.7\msvc2013_64\plugins

編譯 Qt source
1. 新版的 Qt 編譯不能使用 vs2013,要使用 Visual C++ Build Tools(Visual Studio 2015)
2. 編譯需要跳過一些模組
configure.bat -release -nomake examples -skip qtscript

2016年10月26日 星期三

findContours, drawContours

findContours
Non-zero pixels are treated as 1's. Zero pixels remain 0's, so the image is treated as binary.
0: 黑, 255(白)
以黑為背景,尋找灰白的前景邊界

hierarchy
the elements hierarchy[i][0] , hiearchy[i][1] , hiearchy[i][2] , and hiearchy[i][3] are set to 0-based indices in contours of the next and previous contours at the same hierarchical level, the first child contour and the parent contour, respectively.
0: 下一個
1: 上一個
2: 第一個兒子
3: 父親
If for the contour i there are no next, previous, parent, or nested contours, the corresponding elements of hierarchy[i] will be negative.
沒有就是 -1

RETR_EXTERNAL
It sets hierarchy[i][2]=hierarchy[i][3]=-1 for all the contours.

RETR_CCOMP
所有邊界分為兩層, 白的外圈, 和內圈
hierarchy[i][3]=-1 for all the contours.

drawContours


2016年10月25日 星期二

Build OpenCV v3

下載安裝 git for windows

下載安裝 TortoiseGit, 設定 git for windows 的位置

建立目錄 D:/OpenCV
Clone the repository to D:\OpenCV from https://github.com/Itseez/opencv.git

下載安裝 CMake

除了分別下載安裝 python35_32, python35_64, 也要下載 Source

安裝 Setuptools
下載 ez_setup.py 置於 D:\Python35 下
執行 D:\Python35>python ez_setup.py

Install Sphinx via the command:
D:\Python35\Scripts\easy_inatall.exe sphinx

安裝 NumPy
cd D:\Python35\Scripts
pip install numpy

用 VS2013 開啟 PCbuild/pcbuild.sln, 主要建立 python 專案
可以建立出32位元 PCbuild/win32/python35_d.lib並且拷貝至 Python35_32/libs 下
64位元 PCbuild/amd64/python35_d.lib並且拷貝至 Python35_64/libs 下

Download and install Miktex: http://miktex.org/.
At the fourth step make sure you select for the "Install missing packages" the Yes option.
Miktex 只使用 64位元

Download the Intel TBB library: https://www.threadingbuildingblocks.org/, 選擇 Windows 版本
Extract it.
Create a dep directory in your OpenCV folder.
And copy the extracted files here.

Do the same with the eigen files: eigen.tuxfamily.org

下載 CUDA Toolkit 8.0 選擇 Windows 版本

安裝32和64位元的 Qt5.7 for VS2013, 於不同目錄

開啟 CMake
Where is the source code: D:/OpenCV/opencv
Where to build the binaries: D:.OpenCV/build_64
按 Configure 選擇 Visual Studio 12 2013 Win64
按 Generate, 此時會產生錯誤, 需要設定下列目錄
EIGEN_INCLUDE_PATH=D:\OpenCV\dep\eigen
開啟 PYTHON3 設定正確的版本位置
PYTHON3_EXECUTABLE=D:/Python35_32/python.exe
PYTHON3_INCLUDE_DIR=D:/Python35_32/include
PYTHON3_LIBRARY=D:/Python35_32/libs/python35.lib
PYTHON3_LIBRARY_DEBUG=D:/Python35_32/libs/python35_d.lib
PYTHON3_NUMPY_INCLUDE_DIRS=D:/Python35_32/Lib/site-packages/numpy/core/include
PYTHON3_PACKAGES_PATH=D:/Python35_32/Lib/site-packages
開啟 WITH_QT, WITH_TBB, WITH_CUDA
按 Generate, 此時會產生錯誤, 需要設定下列目錄
QT_QMAKE_EXECUTABLE=D:/Qt/Qt5.7.0_64/5.7/msvc2013/bin/qmake.exe
Qt5Concurrent_DIR=D:/Qt/Qt5.7.0_64/5.7/msvc2013/lib/cmake/Qt5Concurrent
Qt5Core_DIR=D:/Qt/Qt5.7.0_64/5.7/msvc2013/lib/cmake/Qt5Core
Qt5Gui_DIR=D:/Qt/Qt5.7.0_64/5.7/msvc2013/lib/cmake/Qt5Gui
Qt5OpenGL_DIR=D:/Qt/Qt5.7.0_64/5.7/msvc2013/lib/cmake/Qt5OpenGL
Qt5Test_DIR=D:/Qt/Qt5.7.0_64/5.7/msvc2013/lib/cmake/Qt5Test
Qt5Widgets_DIR=D:/Qt/Qt5.7.0_64/5.7/msvc2013/lib/cmake/Qt5Widgets
TBB_INCLUDE_DIRS=D:/OpenCV/dep/tbb2017_20160916oss/include

開啟 CMake
Where is the source code: D:/OpenCV/opencv
Where to build the binaries: D:.OpenCV/build_32
按 Configure 選擇 Visual Studio 12 2013
按 Generate, 此時會產生錯誤, 需要設定下列目錄
EIGEN_INCLUDE_PATH=D:\OpenCV\dep\eigen
開啟 PYTHON3 設定正確的版本位置
開啟 WITH_QT, WITH_TBB
關閉 WITH_CUDA, 因為 CUDA 沒有 32 位元版本
按 Generate, 此時會產生錯誤, 需要設定下列目錄
QT_QMAKE_EXECUTABLE=D:/Qt/Qt5.7.0_32/5.7/msvc2013/bin/qmake.exe
Qt5Concurrent_DIR=D:/Qt/Qt5.7.0_32/5.7/msvc2013/lib/cmake/Qt5Concurrent
Qt5Core_DIR=D:/Qt/Qt5.7.0_32/5.7/msvc2013/lib/cmake/Qt5Core
Qt5Gui_DIR=D:/Qt/Qt5.7.0_32/5.7/msvc2013/lib/cmake/Qt5Gui
Qt5OpenGL_DIR=D:/Qt/Qt5.7.0_32/5.7/msvc2013/lib/cmake/Qt5OpenGL
Qt5Test_DIR=D:/Qt/Qt5.7.0_32/5.7/msvc2013/lib/cmake/Qt5Test
Qt5Widgets_DIR=D:/Qt/Qt5.7.0_32/5.7/msvc2013/lib/cmake/Qt5Widgets
TBB_INCLUDE_DIRS=D:/OpenCV/dep/tbb2017_20160916oss/include

用 VisualStudio2013 開啟 D:\OpenCV\Builds\OpenCV.sln
選擇 ALL_BUILD, Build Debug 和 Release
選擇 INSTALL, Build Debug 和 Release



2016年10月19日 星期三

OpenCV 之 waitKey 使用

waitKey 除了不能區分大小寫,最慘的是和中文輸入法打架
使用 ImmDisableIME(-1); 關閉輸入法

2016年10月13日 星期四

Google Driver Web Page

原先可以正常使用的 語言學習 網站,近期一直不穩,甚至完全不能使用
之後查明原因為 Google 要停止這個功能

網路上有人建議使用 GitHub,但試過後發現,GitHub 可能也不支援了

目前將網頁搬至 000webhost,免費網路空間,目前感覺很棒
雖然該網站曾經被駭客入侵,但是我想它會改善,何況我也只是放單純的網頁