return inverted_image


def nothing(x):
    pass


################################################################################
# Preprocessing stuff
# cv2.namedWindow('cannyOutput')
################################################################################

c = cv2.VideoCapture(0)
_, f = c.read()
avg2 = np.float32(f)
background = BackgroundRemoval.preprocessbackground(c, f, avg2)
_, f = c.read()
gray = cv2.cvtColor(f, cv2.COLOR_BGR2GRAY)
while True:
    _, f = c.read()
    gray = cv2.cvtColor(f, cv2.COLOR_BGR2GRAY)
    image_nobackground = BackgroundRemoval.removebackground(gray, background)
    b, g, r = cv2.split(f)
    nb = np.minimum(image_nobackground, b)
    ng = np.minimum(image_nobackground, g)
    nr = np.minimum(image_nobackground, r)
    bn, gn, rn = normalized(ng, nr, ng)
    backgroundRemovedImage = cv2.merge((nb, ng, nr))

    res = ColorSegmenter.getMagentaBlob(backgroundRemovedImage)
    objectdetection = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)
Example #2
0

def normalized(b,g,r):
    clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(3,3))
    #b,g,r = cv2.split(img)
    b1 = clahe.apply(b)
    g1 = clahe.apply(g)
    r1 = clahe.apply(r)
    #bgr = cv2.merge((b1,g1,r1))
    return b1,g1,r1

c = cv2.VideoCapture(0)
_,f = c.read()
avg2 = np.float32(f)
# Get clean - unmoving background
background=BackgroundRemoval.preprocessbackground(c, f, avg2)
# get new frame
_,f = c.read()
gray=cv2.cvtColor(f, cv2.COLOR_BGR2GRAY)
while True:
    _,f = c.read()
    # Remove fixed background from image
    mask=BackgroundRemoval.removebackground(f, background)
    #split channels to remove backround and normalize color
    b,g,r = cv2.split(f)
    # remove background
    nb=np.minimum(mask, b)
    ng=np.minimum(mask, g)
    nr=np.minimum(mask, r)

    # normalize color