init trans
Former-commit-id: 32f405e2fbc6096ba6f7a8b3f55e743bf4550d78
This commit is contained in:
@ -13,7 +13,7 @@ import json
|
||||
import Find_COM
|
||||
from threading import Thread
|
||||
|
||||
LOCAL_DEBUG = True
|
||||
LOCAL_DEBUG = False
|
||||
|
||||
if LOCAL_DEBUG:
|
||||
print("WARNING: Local debug mode is enabled. Serial communication will be skipped.")
|
||||
@ -116,9 +116,10 @@ class MAT:
|
||||
return None
|
||||
|
||||
ret = self.my_predictor(im)
|
||||
# print(ret)
|
||||
if ret is None:
|
||||
cv2.imwrite("tmp.jpg",im)
|
||||
return self.predictor("tmp.jpg")
|
||||
print("Failed")
|
||||
self.thr = Thread(target=self._pred).start()
|
||||
else:
|
||||
if ret == self.end_kind:
|
||||
print("Stop at ",self.total_volume)
|
||||
@ -129,22 +130,18 @@ class MAT:
|
||||
return ret,0.9
|
||||
|
||||
def my_predictor(self,im):
|
||||
model = self.model
|
||||
ret = self.preproc(im)
|
||||
if ret is None:
|
||||
return None
|
||||
arr = np.array(ret)
|
||||
if len(arr.shape) == 1:
|
||||
arr = arr.reshape(1, -1)
|
||||
|
||||
# 进行预测并转换为类别名
|
||||
pred_labels = model.predict(arr)
|
||||
# pred_classes = [label_map[label] for label in pred_labels]
|
||||
mp = ["orange", "yellow"]
|
||||
if len(pred_labels) == 1:
|
||||
return mp[pred_labels[0]]
|
||||
# im = cv2.imread(file)
|
||||
hsv = cv2.cvtColor(im,cv2.COLOR_BGR2HSV)
|
||||
s = hsv[:,:,1]
|
||||
mask = s>100
|
||||
# print(mask)
|
||||
tot = mask.shape[0]*mask.shape[1]
|
||||
val = np.sum(mask)
|
||||
# print(val/tot)
|
||||
if val<tot*0.3:
|
||||
return "transport"
|
||||
else:
|
||||
return None
|
||||
return "colored"
|
||||
|
||||
def predictor(self, im_file): # 预测分类
|
||||
image = Image.open(im_file)
|
||||
@ -229,7 +226,6 @@ class MAT:
|
||||
print(f"Total Volume: {self.total_volume} ml")
|
||||
# print(f"Image File: {im_file}")
|
||||
print("Volume List:", self.volume_list)
|
||||
print("Voltage List:", self.voltage_list)
|
||||
print("Color List:", self.color_list)
|
||||
|
||||
|
||||
@ -239,12 +235,12 @@ if __name__ == "__main__":
|
||||
warnings.filterwarnings('ignore')
|
||||
|
||||
# 创建MAT类的实例并运行
|
||||
mat = MAT(videoSourceIndex = 0, weights_path = "resnet34-1Net.pth", json_path = 'class_indices.json', classes = 2)
|
||||
mat = MAT(videoSourceIndex = 1, weights_path = "resnet34-1Net.pth", json_path = 'class_indices.json', classes = 2)
|
||||
mat.run(
|
||||
quick_speed = 0.3,
|
||||
slow_speed = 0.2,
|
||||
expect = 11.2,
|
||||
end_kind = 'orange',
|
||||
expect = 10,
|
||||
end_kind = 'colored',
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user