Created
January 3, 2016 01:17
-
-
Save mikoim/777b32c8adcc86d61dd1 to your computer and use it in GitHub Desktop.
画像から円弧で切り出してcountNonZero
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
#!/usr/bin/env python | |
# coding=utf-8 | |
import cv2 | |
import numpy as np | |
img = cv2.imread('./images/s01.png') | |
height, width, channels = img.shape | |
g_img = cv2.bilateralFilter(img, 9, 75, 75) | |
c_img = cv2.Canny(g_img, 50, 150) | |
cv2.imshow('filtered', c_img) | |
mask = np.zeros((height, width, 1), np.uint8) | |
cv2.ellipse(mask, center=(50, 100), axes=(100, 100), angle=0, startAngle=0, endAngle=-22.5, color=255, thickness=cv2.cv.CV_FILLED) | |
cv2.imshow('mask', mask) | |
masked = cv2.bitwise_and(c_img, c_img, mask=mask) | |
cv2.imshow('masked', masked) | |
print('countNonZero : {:d}'.format(cv2.countNonZero(masked))) | |
cv2.waitKey() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment