-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolor_vision.py
47 lines (39 loc) · 1.27 KB
/
color_vision.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np
import cv2
import time
from Image import *
def SlicePart(im, images, slices):
height, width = im.shape[:2]
sl = int(height/slices);
for i in range(slices):
part = sl*i
crop_img = im[part:part+sl, 0:width]
images[i].image = crop_img
images[i].Process()
def RepackImages(images):
img = images[0].image
for i in range(len(images)):
if i == 0:
img = np.concatenate((img, images[1].image), axis=0)
if i > 1:
img = np.concatenate((img, images[i].image), axis=0)
return img
def Center(moments):
if moments["m00"] == 0:
return 0
x = int(moments["m10"]/moments["m00"])
y = int(moments["m01"]/moments["m00"])
return x, y
def RemoveBackground(image, b):
up = 150
lower = np.array([0, 0, 0], dtype = "uint8")
upper = np.array([up, up, up], dtype = "uint8")
#----------------COLOR SELECTION-------------- (Remove any area that is whiter than 'upper')
if b == True:
mask = cv2.inRange(image, lower, upper)
image = cv2.bitwise_and(image, image, mask = mask)
image = cv2.bitwise_not(image, image, mask = mask)
image = (255-image)
return image
else:
return image