作業說明:
影像形態學函式練習
計算每張圖圍棋個數
執行環境:
- Arch Linux x86_64
- Python 3.9.2
- Python venv
- OpenCV 4.5.1
實作方式:
- step 1 : read image in grayscale and median blur
- step 2 : find stone of go by erode
- step 2-1 : otsu thresholding
- step 2-2 : erode
- step 2-3 : find all connected components
- step 2-4 : standrize area of connected components
- step 2-5 : assume stone is found if abs(std) < 1.0
- step 2-6 : mask thresholding image with circle of found stones
- step 2-7 : count connected components
- step 3 : find stone of go by adaptive threshold
- step 3-1 : adaptive thresholding
- step 3-2 : mask previous result with adaptive threshold
- step 3-3 : erode
- step 3-4 : find all connected components
- step 3-5 : standrize area of connected components
- step 3-6 : assume stone is found if abs(std) < 1.0
- step 3-7 : mask erode image with circle of found stones
- step 3-8 : count connected components
- step 4 : find stone of go by clahe and adaptive threhold
- step 4-1 : adaptive thresholding after clahe
- step 4-2 : dilate previous result
- step 4-3 : mask it with adaptive threshold
- step 4-4 : erode
- step 4-5 : closing
- step 4-6 : find all connected components
- step 4-7 : remove connected componets are too small
- step 4-8 : count connected components
- step 5 : add all counts
- step 6 : merge all result binary image into B,G,R and save
執行結果:
如下圖
藍色、綠色、紅色分別為第二步、第三步、第四步的結果
三種顏色可能重疊 因為找到的棋子將會假設在色塊中心
因此若色塊太大 前一步驟的色塊就會與後一步驟的重疊
執行結果 三步驟分別找到 15 顆、2 顆、7 顆棋子
共 24 顆 誤差 0
原圖 棋子數為 31
執行結果 三步驟分別找到 25 顆、4 顆、2 顆棋子
共 31 顆 誤差 0
原圖 棋子數為 31
沒有留言:
張貼留言