Hits: 256
來學學cv吧
環境建置
- windows 10
- python 3.6
- 安裝python套件
pip install numpy
pip install matplotlib
pip install opencv-contrib-python
pip install dlib # 噴錯
在安裝 dlib
的時候噴錯,錯誤訊息是 CMake must be installed to build the following extensions: dlib
,看起來就是系統找不到CMake這個程式,google了一下,找到的解法是安裝 Visual Studio 2017 Community。
- 安裝 Visual Studio 2017 community,選擇
適用於CMake的Visual C++工具
,會把其他相對應的一起安裝好(大約要5G…OMG)
-
設定 Cmake 到環境變數的
Path
中,路徑為C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin
-
再次執行
pip install dlib
,大功告成。
課堂筆記
Section 2: Basic of computer vision and OpenCV
10. What are images?
影像的定義:2維(2-D)的可見光光譜
11. How are image formed?
12. Storing image on computer.
OpenCV use RGB color space by default.
Each pixel coordinate (x, y) contains 3 values(for R, G, B) ranging from 0-255.
影像是如何被電腦儲存的?就是以array的形式儲存的可見光光譜,以3D-array的形式儲存在電腦中(彩色影像)
除了彩色影像之外,也有灰階與黑白影像,這就更簡單了,灰階就是只有2D的0-255的array,(0為白255為黑);而黑白影像就只有0與255。
15. Understanding color spaces
RGB
HSV
適合用於color segementation。
CMYK
簡介一下一張照片是怎麼被python讀懂的,基本上就是透過numpy
與cv2
,把影像根據color space(RGB, HSV, CMYK…等),讀成(height, width, color_spaces)
的形式,以下範例示範
import cv2
import numpy as np
image = cv2.imread(r'path/input.jpg')
image.shape # it's a (830 height, 1245 width, 3 space) array.
# Figure out the color space.
print(image[829]) # 列出第830列的所有顏色
print('--------')
print(image[829][0]) # 列出第830列第1欄的所有顏色
print('--------')
print(image[829][0][0]) # 列出第830列第1欄的第一種顏色(B)
print(image[829][0][1]) # 列出第830列第1欄的第一種顏色(G)
print(image[829][0][2]) # 列出第830列第1欄的第一種顏色(R)
# 底下是output
>>> [[ 3 6 11]
>>> [ 3 6 11]
>>> [ 2 5 10]
>>> ...
>>> [18 23 38]
>>> [18 23 38]
>>> [19 24 39]]
>>> --------
>>> [ 3 6 11]
>>> --------
>>> 3
>>> 6
>>> 11
Comments