Last active
October 22, 2017 20:09
-
-
Save crackwitz/82b4a99395f06b144b4491c0a2fd3a08 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 python3 | |
import os | |
import sys | |
import numpy as np | |
import cv2 | |
if __name__ == '__main__': | |
def predicate(pixel): | |
B, G, R = pixel | |
#return G < 140 | |
return R > 1.08*G and R > 1.08*B and G > 30 and G < 140 | |
def repaint(V): | |
global bgr | |
# HSV | |
sat = np.arange(0.0, 1.0, 1/256) | |
hue = np.arange(0.0, 360.0, 1.0) | |
H,S = np.meshgrid(hue, sat) | |
picture = np.zeros((len(sat), len(hue), 3), dtype=np.float32) | |
picture[:,:,0] = H | |
picture[:,:,1] = S | |
picture[:,:,2] = V | |
bgr = cv2.cvtColor(picture, cv2.COLOR_HSV2BGR) | |
bgr = (bgr * 255).astype(np.uint8) | |
mask = np.apply_along_axis(predicate, 2, bgr) | |
bgr[~mask] = 0 | |
cv2.imshow("display", bgr) | |
def ontrackbar(val): | |
repaint(val/255) | |
cv2.namedWindow("display") | |
cv2.createTrackbar('Y', 'display', 255, 256, ontrackbar) | |
repaint(1.0) | |
while True: | |
key = cv2.waitKey(100) | |
if key == -1: continue | |
if key == 27: break | |
cv2.destroyAllWindows() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment