Skip to content

Commit

Permalink
1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ES-Alexander committed Sep 19, 2020
1 parent 415cc74 commit 51470b7
Show file tree
Hide file tree
Showing 11 changed files with 1,810 additions and 0 deletions.
Empty file added build/lib/pcv/__init__.py
Empty file.
43 changes: 43 additions & 0 deletions build/lib/pcv/interact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3

import cv2


waitKey = lambda ms : cv2.waitKey(ms) & 0xFF


class DoNothing:
''' A context manager that does nothing. '''
def __init__(self): pass
def __enter__(self): return self
def __exit__(self, *args): pass


class MouseCallback:
''' A context manager for temporary mouse callbacks. '''
def __init__(self, window, handler, param=None,
restore=lambda *args: None, restore_param=None):
''' Initialise with the window, handler, and restoration command.
'window' is the name of the window to set the callback for.
'handler' is the function for handling the callback, which should take
x, y, flags ('&'ed EVENT_FLAG bits), and an optional param passed
in from the callback handler.
'param' is any Python object that should get passed to the handler
on each call - useful for tracking state.
'restore' is the function to restore as the handler on context exit.
'restore_param' is the handler param to restore on context exit.
'''
self.window = window
self.handler = handler
self.param = param
self.restore = restore
self.restore_param = restore_param

def __enter__(self):
cv2.setMouseCallback(self.window, self.handler, self.param)
return self

def __exit__(self, *args):
cv2.setMouseCallback(self.window, self.restore, self.restore_param)
39 changes: 39 additions & 0 deletions build/lib/pcv/process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3

import cv2

def downsize(img, ratio):
''' downsize 'img' by 'ratio'. '''
return cv2.resize(img,
tuple(dim // ratio for dim in reversed(img.shape[:2])),
interpolation = cv2.INTER_AREA)

def channel_options(img):
''' Create a composite image of img in all of opencv's colour channels
|img| -> | blue | green | red |
| hue | saturation | value |
| hue2 | luminosity | saturation2 |
| lightness | green-red | blue-yellow |
| lightness2 | u | v |
'''
B,G,R = cv2.split(img)
H,S,V = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))
H2,L2,S2 = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HLS))
L,a,b = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2LAB))
L3,u,v = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2LUV))
channels = (((B, 'blue'), (G, 'green'), (R, 'red')),
((H, 'hue'), (S, 'saturation'), (V, 'value')),
((H2, 'hue2'), (L2, 'luminosity'), (S2, 'saturation2')),
((L, 'lightness'), (a, 'green-red'), (b, 'blue-yellow')),
((L3,'lightness2'), (u, 'u'), (v, 'v')))
out = []
for row in channels:
img_row = []
for img, name in row:
cv2.putText(img, name, (10, 30), cv2.FONT_HERSHEY_SIMPLEX,
0.6, 255, 1)
img_row.append(img)
out.append(cv2.hconcat(img_row))
return cv2.vconcat(out)
Loading

0 comments on commit 51470b7

Please sign in to comment.