Hexo 寫作篇

建立草稿

1
hexo new draft 'new-article'

編輯草稿

用自己慣用的編輯器打開編輯

1
retext source/_drafts/new-article.md

發布草稿

名稱不包含.md

1
hexo publish draft 'new-article'

其他

如何在文章中正確的加入圖片與檔案
正確的引用圖片方式是使用下列的標籤插件而不是 markdown:

1
2
{% asset_img example.jpg This is an example image %}
{% asset_link example.cpp This is an example cpp %}

官網說明 標籤插件

我的常用軟體

介紹我在 Windows, MacOS 和 Ubuntu 各平台使用的軟體.
基本上我是蠻喜愛跨平台軟體的, 學一次就可以在各平台上使用是件輕鬆的事情.
生活就該這樣簡簡單單就好.

影片剪輯

  • OpenShot

My Github Repositories

自 2014 年開始, 就陸續把我的作品上傳到 Github 上,
這邊就紀錄一下截至今天為止上傳的作品數,

1
2018/02/02 29 個 Sources

https://libraries.io/github/shengyu7697
針對 GitHub 的統計, 原來我的貢獻被超過 2 個開放原始碼專案採用, 覺得自己要繼續持續努力!

最後希望 2018 今年可以突破 40 個 Sources!加油!

Build OSVR on Windows

Required tools/libraries

1. Build boost

Use “Developer Command Prompt for VS2015”(C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\Shortcuts)

1
2
3
cd C:/osvr/boost_1_60_0
bootstrap.bat
b2 --toolset=msvc-14.0 architecture=x86 address-model=64 stage

2. Build OSVR-Core

目錄配置結構

1
2
3
4
5
6
C:\
├─ osvr
│  ├─ boost_1_60_0
│  ├─ jsoncpp-vc14-64bits-18
│  └─ libfunctionality-vc14-64bits-42
└─ opencv

輸入以下指令開始編譯 OSVR-Core

1
2
3
cd C:/osvr/
git clone --recursive https://github.com/OSVR/OSVR-Core.git
mkdir OSVR-Core/build

使用cmake-gui

1
2
3
4
source code dir = C:/osvr/OSVR-Core
build the binaries dir = C:/osvr/OSVR-Core/build
Configure
選 Visual Studio 14 2015 Win64

加入下列路徑

1
2
3
libfunctionality_DIR = C:/osvr/libfunctionality-binary/install/lib/cmake/libfunctionality
OpenCV_DIR = C:/osvr/opencv/build
jsoncpp_DIR = C:/osvr/jsoncpp-vc14-64bits-18/install/lib/cmake/jsoncpp

手動加入entry (click “Add Entry”, add PATH)

1
2
3
BOOST_LIBRARYDIR = C:/osvr/boost_1_60_0/libs
BOOST_ROOT = C:/osvr/boost_1_60_0
BOOST_INCLUDE_DIR = C:/osvr/boost_1_60_0

Configure and Generate, click osvrcore.sln and build

1
C:\osvr\OSVR-Core\build\osvrcore.sln

Fix compiler error (header_cpp_265, header_cpp_172) 加入opencv目錄路徑

1
2
3
PROJECT > Properties (或在專案右鍵選Properties)
Configuration Properties \ C/C++ \ General \ Additional Include Directories
add C:\osvr\opencv\build\include

Compile Plugin of video-based tracker

Need DirectShow (Microsoft Windows SDK Update)
確保 DIRECTSHOW_QEDIT_INCLUDE_DIR 和 DIRECTSHOW_STRMIIDS_LIBRARY 都要有值

1
2
DIRECTSHOW_QEDIT_INCLUDE_DIR:PATH="C:/Program Files/Microsoft Platform SDK for Windows Server 2003 R2/Include"
DIRECTSHOW_STRMIIDS_LIBRARY:PATH="C:/Program Files (x86)/Windows Kits/8.1/Lib/winv6.3/um/x64/strmiids.lib"

CMake Script

輸入以下腳本可以自動完成上面第2步
gen_vs2015_64.sh

1
2
3
4
5
6
7
8
9
10
11
12
cd OSVR-Core/build
cmake .. \
-G "Visual Studio 14 2015 Win64" \
-DCMAKE_INSTALL_PREFIX:PATH=C:/osvr/install \
-Dlibfunctionality_DIR:PATH=C:/osvr/jsoncpp-vc14-64bits-18/install/lib/cmake/libfunctionality \
-DOpenCV_DIR:PATH=C:/osvr/opencv/build \
-Djsoncpp_DIR:PATH=C:/osvr/jsoncpp-vc14-64bits-18/install/lib/cmake/jsoncpp \
-DBOOST_LIBRARYDIR:PATH=C:/osvr/boost_1_60_0/libs \
-DBOOST_ROOT:PATH=C:/osvr/boost_1_60_0 \
-DBOOST_INCLUDE_DIR:PATH=C:/osvr/boost_1_60_0 \
-DBUILD_HEADER_DEPENDENCY_TESTS:BOOL=OFF \
-DBUILD_TESTING:BOOL=OFF

Trace OSVR videobasedtracker plugin

紀錄一下 VideoBasedTracker plugin 的啟動流程,流程如下,

com_osvr_VideoBasedHMDTracker.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class VideoBasedHMDTracker : boost::noncopyable {
VideoBasedHMDTracker() {

}

// TODO_TRACE: 誰 call update()?
OSVR_ReturnCode VideoBasedHMDTracker::update() {
m_vbtracker.processImage()
}

osvr::vbtracker::VideoBasedTracker m_vbtracker;
};

class HardwareDetection {
operator() {
auto newTracker = osvr::pluginkit::registerObjectForDeletion(
ctx, new VideoBasedHMDTracker(...));
}
};

// Plugin 進入點
OSVR_PLUGIN(com_osvr_VideoBasedHMDTracker) {
/// 告訴 core 建立一個 device object.
osvr::pluginkit::registerDriverInstantiationCallback(
ctx, "VideoBasedHMDTracker", new ConfiguredDeviceConstructor);
}

VideoBasedTracker.cpp

1
2
3
bool VideoBasedTracker::processImage(...) {

}

Trace OSVR 演算法

Trace OSVR 演算法 (VideoBasedTracker)

原始程式碼如下:
videobasedtracker/VideoBasedTracker.cpp

以下為簡化過程式碼的流程:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
bool VideoBasedTracker::processImage(cv::Mat frame, cv::Mat grayImage,
OSVR_TimeValue const &tv,
PoseHandler handler) {

m_frame = frame;
m_imageGray = grayImage;
auto foundLeds = m_blobExtractor.extractBlobs(grayImage); // blob 偵測

auto undistortedLeds = undistortLeds(foundLeds, m_camParams);

for (size_t sensor = 0; sensor < m_identifiers.size(); sensor++) {

osvrPose3SetIdentity(&m_pose);
auto ledsMeasurements = undistortedLeds;
{
auto &myLeds = m_led_groups[sensor];
auto led = begin(myLeds);
auto e = end(myLeds);
while (led != end(myLeds)) {
led->resetUsed();
auto threshold = m_params.blobMoveThreshold *
led->getMeasurement().diameter;
auto nearest = led->nearest(ledsMeasurements, threshold); // 找最近的
if (nearest == end(ledsMeasurements)) {
// We have no blob corresponding to this LED, so we need
// to delete this LED.
led = myLeds.erase(led);
} else {
// Update the values in this LED and then go on to the
// next one. Remove this blob from the list of potential matches.
// 因為已經這個 blob 是哪個 LED, 所以從 ledsMeasurements 裡移除這個 LED
led->addMeasurement(*nearest, m_params.blobsKeepIdentity);
ledsMeasurements.erase(nearest);
++led;
}
} // while

for (auto &remainingLed : ledsMeasurements) {
myLeds.emplace_back(m_identifiers[sensor].get(), remainingLed);
}
}

bool gotPose = false;
if (m_estimators[sensor]) {
OSVR_PoseState pose;
if (m_estimators[sensor]->EstimatePoseFromLeds( // 估算 Pose
m_led_groups[sensor], tv, pose)) {
m_pose = pose;
handler(static_cast<unsigned>(sensor), pose); // 送 Pose 出去
gotPose = true;
}
}
} // for

return done;
}

ledsMeasurements 是偵測到的 LED blobs

重點流程如下:

  • m_blobExtractor.extractBlobs(grayImage); // blob 偵測
  • m_estimators[sensor]->EstimatePoseFromLeds() // 估算 Pose
  • handler(static_cast(sensor), pose); // 送 Pose 出去

相關程式碼:
videobasedtracker/LED.h
videobasedtracker/LED.cpp

Build OpenCV 3 on Ubuntu

系統環境

  • Ubuntu 16.04
  • OpenCV 3.3.1
  • Cmake

目錄放置結構

1
2
|- opencv-3.3.1
|- opencv_contrib-3.3.1

opencv-3.3.1 原始碼下載
opencv_contrib-3.3.1 原始碼下載

編譯時所需要的套件

1
sudo apt-get install build-essential cmake git

可以參考這些(待確認)
https://docs.opencv.org/3.3.0/d7/d9f/tutorial_linux_install.html
https://docs.opencv.org/3.4.1/d2/de6/tutorial_py_setup_in_ubuntu.html (套件有錯誤)
https://www.learnopencv.com/install-opencv-3-4-4-on-ubuntu-16-04/

編譯 OpenCV

編譯 opencv-3.3.1,

1
2
3
4
5
6
7
8
9
10
11
12
cd opencv-3.3.1
mkdir -p build && cd build
cmake \
-DCMAKE_BUILD_TYPE:STRING=RELEASE \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local \
-DWITH_TBB:BOOL=ON \
-DWITH_V4L:BOOL=ON \
-DBUILD_EXAMPLES:BOOL=ON \
-DWITH_QT:BOOL=ON \
-DWITH_OPENGL:BOOL=ON \
..
make -j8

安裝,

1
sudo make install

重新載入動態連結,

1
sudo ldconfig -v

編譯 OpenCV (with opencv_contrib)

編譯 opencv-3.3.1 with opencv_contrib,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cd opencv-3.3.1
mkdir -p build && cd build
cmake \
-DCMAKE_BUILD_TYPE:STRING=RELEASE \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local \
-DWITH_TBB:BOOL=ON \
-DWITH_V4L:BOOL=ON \
-DBUILD_EXAMPLES:BOOL=ON \
-DWITH_QT:BOOL=ON \
-DWITH_OPENGL:BOOL=ON \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.3.1/modules \
-DBUILD_opencv_legacy=OFF \
..
make -j8

安裝,

1
sudo make install

重新載入動態連結,

1
sudo ldconfig -v

Qt add Git version or SHA1

紀錄一下如何在 Qt .pro 專案檔裡帶入 git 的版本資訊或是 git 的 SHA1,讓編譯出來的 Qt 程式夾帶 git 版本資訊。

Add code to Qt .pro file.

1
2
GIT_VERSION = "$(shell git -C \""$$_PRO_FILE_PWD_"\" describe)"
DEFINES += GIT_VERSION=\\\"$$GIT_VERSION\\\"

(Windows 下要先確保 git 指令的路徑已經有加到系統環境變數裡)

Use the define inside your code. (cpp files)

1
QString version(GIT_VERSION);

參考文章
https://stackoverflow.com/questions/27041573/print-git-hash-in-qt-as-macro-created-at-compile-time
https://gist.github.com/grassator/11405930
https://www.everythingfrontend.com/posts/app-version-from-git-tag-in-qt-qml.html

其它相關文章推薦
[Qt] 讀檔,讀取 txt 文字檔
[Qt] 寫檔,寫入 txt 文字檔
安裝 Qt 在 Windows 7 (使用MSVC)
Qt產生的exe發布方式
Qt 新增多國語言.ts翻譯檔案
Qt5的中文亂碼問題如何解決

Qt and OpenCV 3 on Windows (使用 MinGW)

介紹一下怎麼在 Windows 下使用 Qt 和 OpenCV 3.

系統環境

  • Windows 7
  • Qt5.10.0 (編譯器選擇 mingw530_32)
  • OpenCV 3.3.1 (準備用 mingw 來 build)
  • Cmake

安裝 Qt

先從官網下載 Qt, 目前最新為5.10, 安裝好之後
並把 Qt dll 路徑加進系統環境變數裡 (這步很重要, 因為要用它來編譯OpenCV)

1
2
C:\Qt\Qt5.10.0\5.10.0\mingw53_32\bin
C:\Qt\Qt5.10.0\Tools\mingw530_32\bin

編譯 OpenCV (使用 MinGW 編譯)

從官網下載 OpenCV 並解開, 執行下列指令

1
2
3
4
cd opencv-3.3.1
mkdir build
cd build
cmake-gui.exe ..

在make-gui上按照下方流程進行

1
2
3
選擇 MinGW Makefiles  
選擇 Use default native compilers
再按 Finish

按 Configure 會報錯說沒設定 CMAKE_CXX_COMPILERCMAKE_C_COMPILER
不管它再按一下 Configure 他會自動找到

1
2
勾選 WITH_OPENGL
勾選 WITH_QT

再按一下 Configure, 再按 Generate
接下來就可以開始編譯與安裝

1
2
mingw32-make -j8
mingw32-make install

把 OpenCV dll 目錄加進系統環境變數裡 (這步很重要, 否則執行期間會找不到dll)

1
C:\opencv\build\x86\mingw

之後在 Qt 專案檔 .pro 加入下列變數

1
2
3
4
5
6
7
8
INCLUDEPATH += C:\opencv\build\include
LIBS += -LC:\opencv\build\x86\vc14\lib \
-lopencv_core331 \
-lopencv_highgui331 \
-lopencv_imgcodecs331 \
-lopencv_imgproc331 \
-lopencv_features2d331 \
-lopencv_calib3d331

搞定結束!

疑難雜症

Q. 遇到 windres.exe: unknown option -- W 編譯錯誤怎辦?
A. cmake 取消勾選 ENABLE_PRECOMPILED_HEADERS

Q. 遇到 modules/videoio/src/cap_dshow.cpp error: 'sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA' was not declared in this scope 編譯錯誤怎辦?
A. 編輯 opencv-3.3.1/modules/videoio/src/cap_dshow.cpp
#include "DShow.h" 前面加入 #define NO_DSHOW_STRSAFE 定義

參考文章
https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows
https://ricky.moe/2017/06/17/qt5-6-2-opencv3-1-integration/

其它相關文章推薦
[Qt] 讀檔,讀取 txt 文字檔
[Qt] 寫檔,寫入 txt 文字檔
安裝 Qt 在 Windows 7 (使用MSVC)
Qt產生的exe發布方式
Qt 新增多國語言.ts翻譯檔案
Qt5的中文亂碼問題如何解決

Ubuntu 安裝 Hexo

本篇紀錄在 Ubuntu 下安裝 Hexo 的過程與步驟,

安裝環境

  • Ubuntu 16.04 LTS
  • node v4.2.6 (node -v 指令查看)
  • npm v3.5.2 (npm -v 指令查看)

安裝步驟

已有 nodejs 環境直接跳到 步驟3
步驟1. 安裝nodejs

1
2
sudo apt-get update
sudo apt-get install nodejs nodejs-legacy npm

步驟2. 安裝hexo

1
sudo npm install hexo-cli -g

檢查版本

1
2
3
4
5
6
7
8
9
10
11
12
$ hexo version
hexo-cli: 1.0.4
os: Linux 4.10.0-37-generic linux x64
http_parser: 2.5.0
node: 4.2.6
v8: 4.5.103.35
uv: 1.8.0
zlib: 1.2.8
ares: 1.10.1-DEV
icu: 55.1
modules: 46
openssl: 1.0.2g-fips

步驟3. 初始化一個部落格工作環境:

1
2
3
hexo init blog
cd blog
npm install

步驟4. 啟動 server 來看看網誌

1
hexo server

步驟5. 建立新文章

1
hexo new [layout] 'new-article'

生出來的文章檔案會在 source/_drafts/source/_posts/source/ 下,單看你選擇什麼 layout 的模板。
搞定完成!

參考文章
https://oawan.me/2016/easy-hexo-easy-blog/
https://www.jianshu.com/p/dd111ea16f4d
https://www.jianshu.com/p/24cb74aeb0a3
https://wwssllabcd.github.io/blog/2014/12/22/how-to-install-hexo/
官網 寫作教學
如何使Hexo以文章分類為URI?
Xuan’s Blog Hexo 安裝
線上md寫作
Hexo-撰寫文章 (內含 title、data、tags、keywords、description、categories 範例)
http://ibruce.info/2013/11/22/hexo-your-blog/ (內含 favicon 製作)

相關文章
Hexo 使用 Google Analytics 進行網站流量分析
Hexo 本機測試時如何關閉 Google Analytics
Hexo codeblock 插入程式碼區塊與各種程式語言預覽
升級更新 Hexo upgrade
Hexo 熱門主題列表
Mac OS 安裝 Hexo