41 lines
670 B
Python
41 lines
670 B
Python
from __future__ import annotations
|
|
|
|
import cv2
|
|
from funcy import first, iterate
|
|
from numpy import generic
|
|
|
|
|
|
def copy_and_normalize_channels(image):
|
|
|
|
image = image.copy()
|
|
try:
|
|
image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
|
|
except cv2.error:
|
|
pass
|
|
|
|
return image
|
|
|
|
|
|
def npconvert(ob):
|
|
if isinstance(ob, generic):
|
|
return ob.item()
|
|
raise TypeError
|
|
|
|
|
|
def lift(fn):
|
|
def lifted(coll):
|
|
yield from map(fn, coll)
|
|
|
|
return lifted
|
|
|
|
|
|
def star(fn):
|
|
def starred(*args):
|
|
return fn(*args)
|
|
|
|
return starred
|
|
|
|
|
|
def until(cond, func, *args, **kwargs):
|
|
return first(filter(cond, iterate(func, *args, **kwargs)))
|