Last active
May 24, 2019 06:01
-
-
Save ochilab/956fd3305a0466d86c0172ec9598dbac to your computer and use it in GitHub Desktop.
OpenCV:ラベリング処理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#画像をグレースケールで読み込み | |
grayImage = cv2.imread(fileName,0) | |
#二値変換 | |
_ ,binImage = cv2.threshold(grayImage,0, 255, cv2.THRESH_BINARY) | |
# ラベリング処理 | |
nLabels, labelImages, data, center = cv2.connectedComponentsWithStats(binImage) | |
#ここのラベルの情報を取り出したい場合 | |
for label in range(0,nLabels): | |
x,y = center[label] | |
x,y,w,h,size = data[label] | |
# 面積最大のインデックスを求める場合 | |
max_index = np.argmax(data[:,4]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment