-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessingSubBunches.py
35 lines (35 loc) · 1.18 KB
/
processingSubBunches.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
import cv2
import numpy as np
import get3DModel
from get3DModel import get3DModel
def getSparseFactor(mask,bw,color):
ret, th = cv2.threshold(bw, 0, 255, cv2.THRESH_OTSU)
threshLevel = ret
if color == 'p':
bw_bunch_s = ~th
elif color == 'g':
bw_bunch_s = th
else:
print('wrong color!')
sf = np.sum(bw_bunch_s)/np.sum(mask)
sf = sf/255
return sf,bw_bunch_s
def processingSubBunches(subBunches,color):
for i in range(len(subBunches)):
if color == 'p':
HSV = subBunches[i].rgb
(h, s, v) = cv2.split(subBunches[i].rgb)
bw = h
elif color == 'g':
lab = cv2.cvtColor(subBunches[i].rgb, cv2.COLOR_BGR2LAB)
bw = lab[:, :, 2]
else:
print('wrong color!')
sf,bw_bunch_s = getSparseFactor(subBunches[i].mask,bw,color)
subBunches[i].sf = sf
subBunches[i].bw_bunch_s = bw_bunch_s
existing_berries, newBerries_atEdge, visibleBerries = get3DModel(subBunches[i],color)
subBunches[i].existing_berries = existing_berries
subBunches[i].newBerries_atEdge = newBerries_atEdge
subBunches[i].visibleBerries = visibleBerries
return subBunches