網頁

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,免費網路空間,目前感覺很棒
雖然該網站曾經被駭客入侵,但是我想它會改善,何況我也只是放單純的網頁


Visual Studio Installer 64bit 安裝

用 Notepad.exe 開啟 SetupProject.vdproj
修改 TargetPlatform
3.0 : x86 32-bit platform
3.1 : x64 64-bit platform, AMD64 and EM64T instruction sets
3.2 : Itanium 64-bit platform

修改 Application Folder 之 Properties 的 DefaultLocation
[ProgramFilesFolder][Manufacturer]\[ProductName]
[ProgramFiles64Folder][Manufacturer]\[ProductName]