Skip to content

Instantly share code, notes, and snippets.

@mikoim
Created January 3, 2016 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikoim/777b32c8adcc86d61dd1 to your computer and use it in GitHub Desktop.
Save mikoim/777b32c8adcc86d61dd1 to your computer and use it in GitHub Desktop.
画像から円弧で切り出してcountNonZero
#!/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