Skip to content

Instantly share code, notes, and snippets.

@danielharan
Created January 15, 2018 21:45
Show Gist options
  • Save danielharan/ce562cf9cde0590b4cdf4eb022c200e7 to your computer and use it in GitHub Desktop.
Save danielharan/ce562cf9cde0590b4cdf4eb022c200e7 to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
import glob
from gray_contourer2 import GrayContourer
def mask(img):
c = GrayContourer(img,60,0)
# only give data for the biggest object found
contours = sorted(c.contours, key=cv2.contourArea)
if len(contours) == 0:
print "no contour found"
return []
contour = contours[-1]
mask = np.zeros(img.shape[:2],np.uint8)
cv2.drawContours(mask,[contour],0,255,-1)
return mask
f = '../process_accepted/2017-11-22T20:35:01.999624.jpg'
img = cv2.imread(f)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
res = cv2.bitwise_and(hsv,hsv,mask = mask(img))
rav = cv2.bitwise_and(hsv,hsv,mask = mask(img))[:,:,0].ravel()
rav[rav>35]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment