mirror of
https://github.com/NanjingForestryUniversity/supermachine--tomato-passion_fruit.git
synced 2025-11-09 06:44:02 +00:00
fix:修复一些小问题,添加简单番茄背景判断,如果直径小于200,那么全赋0.返回(100,100,3)空图;由于耀哥&旻哥暂时没写管道预热,预热部分注释掉
This commit is contained in:
parent
e14f5f1f4e
commit
86cf933d24
@ -359,7 +359,7 @@ class Data_processing:
|
|||||||
def contour_process(self, image_array):
|
def contour_process(self, image_array):
|
||||||
# 检查图像是否为空或全黑
|
# 检查图像是否为空或全黑
|
||||||
if image_array is None or image_array.size == 0 or np.all(image_array == 0):
|
if image_array is None or image_array.size == 0 or np.all(image_array == 0):
|
||||||
# print("输入的图像为空或全黑,返回一个全黑图像。")
|
logging.error("输入的图像为空或全黑,返回一个全黑图像。")
|
||||||
return np.zeros_like(image_array) if image_array is not None else np.zeros((100, 100), dtype=np.uint8)
|
return np.zeros_like(image_array) if image_array is not None else np.zeros((100, 100), dtype=np.uint8)
|
||||||
# 应用中值滤波
|
# 应用中值滤波
|
||||||
image_filtered = cv2.medianBlur(image_array, 5)
|
image_filtered = cv2.medianBlur(image_array, 5)
|
||||||
@ -488,11 +488,18 @@ class Data_processing:
|
|||||||
# 将处理后的图像转换为 RGB 格式
|
# 将处理后的图像转换为 RGB 格式
|
||||||
rp = cv2.cvtColor(org_defect, cv2.COLOR_BGR2RGB)
|
rp = cv2.cvtColor(org_defect, cv2.COLOR_BGR2RGB)
|
||||||
diameter = (long_axis + short_axis) / 2
|
diameter = (long_axis + short_axis) / 2
|
||||||
|
if diameter < 200:
|
||||||
|
diameter = 0
|
||||||
|
green_percentage = 0
|
||||||
|
number_defects = 0
|
||||||
|
total_pixels = 0
|
||||||
|
rp = cv2.cvtColor(np.ones((100, 100, 3), dtype=np.uint8), cv2.COLOR_BGR2RGB)
|
||||||
|
return diameter, green_percentage, number_defects, total_pixels, rp
|
||||||
return diameter, green_percentage, number_defects, total_pixels, rp
|
return diameter, green_percentage, number_defects, total_pixels, rp
|
||||||
|
|
||||||
def analyze_passion_fruit(self, img, hue_value=37, hue_delta=10, value_target=25, value_delta=10):
|
def analyze_passion_fruit(self, img, hue_value=37, hue_delta=10, value_target=25, value_delta=10):
|
||||||
if img is None:
|
if img is None:
|
||||||
print("Error: 无图像数据.")
|
logging.error("Error: 无图像数据.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# 创建PassionFruit类的实例
|
# 创建PassionFruit类的实例
|
||||||
|
|||||||
@ -99,14 +99,14 @@ def main(is_debug=False):
|
|||||||
pipe = Pipe(rgb_receive_name, rgb_send_name, spec_receive_name)
|
pipe = Pipe(rgb_receive_name, rgb_send_name, spec_receive_name)
|
||||||
rgb_receive, rgb_send, spec_receive = pipe.create_pipes(rgb_receive_name, rgb_send_name, spec_receive_name)
|
rgb_receive, rgb_send, spec_receive = pipe.create_pipes(rgb_receive_name, rgb_send_name, spec_receive_name)
|
||||||
# 预热循环,只处理cmd为'YR'的数据
|
# 预热循环,只处理cmd为'YR'的数据
|
||||||
while True:
|
# while True:
|
||||||
start_time00 = time.time()
|
# start_time00 = time.time()
|
||||||
data = pipe.receive_rgb_data(rgb_receive)
|
# data = pipe.receive_rgb_data(rgb_receive)
|
||||||
cmd, _ = pipe.parse_img(data)
|
# cmd, _ = pipe.parse_img(data)
|
||||||
end_time00 = time.time()
|
# end_time00 = time.time()
|
||||||
print(f'接收预热数据时间:{end_time00 - start_time00}秒')
|
# print(f'接收预热数据时间:{end_time00 - start_time00}秒')
|
||||||
if cmd == 'YR':
|
# if cmd == 'YR':
|
||||||
break # 当接收到的不是预热命令时,结束预热循环
|
# break # 当接收到的不是预热命令时,结束预热循环
|
||||||
while True:
|
while True:
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
images = []
|
images = []
|
||||||
@ -115,13 +115,13 @@ def main(is_debug=False):
|
|||||||
start_time1 = time.time()
|
start_time1 = time.time()
|
||||||
data = pipe.receive_rgb_data(rgb_receive)
|
data = pipe.receive_rgb_data(rgb_receive)
|
||||||
end_time10 = time.time()
|
end_time10 = time.time()
|
||||||
print(f'接收一份数据时间:{end_time10 - start_time1}秒')
|
# print(f'接收一份数据时间:{end_time10 - start_time1}秒')
|
||||||
|
|
||||||
start_time11 = time.time()
|
start_time11 = time.time()
|
||||||
cmd, img = pipe.parse_img(data)
|
cmd, img = pipe.parse_img(data)
|
||||||
end_time1 = time.time()
|
end_time1 = time.time()
|
||||||
print(f'处理一份数据时间:{end_time1 - start_time11}秒')
|
# print(f'处理一份数据时间:{end_time1 - start_time11}秒')
|
||||||
print(f'接收一张图时间:{end_time1 - start_time1}秒')
|
# print(f'接收一张图时间:{end_time1 - start_time1}秒')
|
||||||
|
|
||||||
# 使用分类器进行预测
|
# 使用分类器进行预测
|
||||||
# prediction = classifier.predict(img)
|
# prediction = classifier.predict(img)
|
||||||
@ -133,7 +133,7 @@ def main(is_debug=False):
|
|||||||
else:
|
else:
|
||||||
response = pipe.send_data(cmd='KO', brix=0, diameter=0, green_percentage=0, weigth=0, defect_num=0,
|
response = pipe.send_data(cmd='KO', brix=0, diameter=0, green_percentage=0, weigth=0, defect_num=0,
|
||||||
total_defect_area=0, rp=np.zeros((100, 100, 3), dtype=np.uint8))
|
total_defect_area=0, rp=np.zeros((100, 100, 3), dtype=np.uint8))
|
||||||
print("图像中无果,跳过此图像")
|
logging.info("图像中无果,跳过此图像")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if cmd not in ['TO', 'PF', 'YR', 'KO']:
|
if cmd not in ['TO', 'PF', 'YR', 'KO']:
|
||||||
@ -146,19 +146,19 @@ def main(is_debug=False):
|
|||||||
spec_data = pipe.receive_spec_data(spec_receive)
|
spec_data = pipe.receive_spec_data(spec_receive)
|
||||||
_, spec = pipe.parse_spec(spec_data)
|
_, spec = pipe.parse_spec(spec_data)
|
||||||
end_time2 = time.time()
|
end_time2 = time.time()
|
||||||
print(f'接收光谱数据时间:{end_time2 - start_time2}秒')
|
# print(f'接收光谱数据时间:{end_time2 - start_time2}秒')
|
||||||
|
|
||||||
start_time3 = time.time()
|
start_time3 = time.time()
|
||||||
if images: # 确保images不为空
|
if images: # 确保images不为空
|
||||||
response = process_data(cmd, images, spec, dp, pipe, detector)
|
response = process_data(cmd, images, spec, dp, pipe, detector)
|
||||||
end_time3 = time.time()
|
end_time3 = time.time()
|
||||||
print(f'处理时间:{end_time3 - start_time3}秒')
|
# print(f'处理时间:{end_time3 - start_time3}秒')
|
||||||
if response:
|
if response:
|
||||||
logging.info(f'处理成功,响应为: {response}')
|
logging.info(f'处理成功,响应为: {response}')
|
||||||
else:
|
else:
|
||||||
logging.error('处理失败')
|
logging.error('处理失败')
|
||||||
else:
|
else:
|
||||||
print("没有有效的图像进行处理")
|
logging.error("没有有效的图像进行处理")
|
||||||
|
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
print(f'全流程时间:{end_time - start_time}秒')
|
print(f'全流程时间:{end_time - start_time}秒')
|
||||||
|
|||||||
@ -90,7 +90,7 @@ class MainWindow(QMainWindow):
|
|||||||
img_data = img.tobytes()
|
img_data = img.tobytes()
|
||||||
length = (len(img_data) + 6).to_bytes(4, byteorder='big')
|
length = (len(img_data) + 6).to_bytes(4, byteorder='big')
|
||||||
# cmd = 'TO':测试番茄数据;cmd = 'PF':测试百香果数据
|
# cmd = 'TO':测试番茄数据;cmd = 'PF':测试百香果数据
|
||||||
cmd = 'PF'
|
cmd = 'TO'
|
||||||
data_send = length + cmd.upper().encode('ascii') + height + width + img_data
|
data_send = length + cmd.upper().encode('ascii') + height + width + img_data
|
||||||
win32file.WriteFile(self.rgb_send, data_send)
|
win32file.WriteFile(self.rgb_send, data_send)
|
||||||
print(f'发送的图像数据长度: {len(data_send)}')
|
print(f'发送的图像数据长度: {len(data_send)}')
|
||||||
@ -113,7 +113,7 @@ class MainWindow(QMainWindow):
|
|||||||
bands = bands.to_bytes(2, byteorder='big')
|
bands = bands.to_bytes(2, byteorder='big')
|
||||||
length = (len(spec_data)+8).to_bytes(4, byteorder='big')
|
length = (len(spec_data)+8).to_bytes(4, byteorder='big')
|
||||||
# cmd = 'TO':测试番茄数据;cmd = 'PF':测试百香果数据
|
# cmd = 'TO':测试番茄数据;cmd = 'PF':测试百香果数据
|
||||||
cmd = 'PF'
|
cmd = 'TO'
|
||||||
data_send = length + cmd.upper().encode('ascii') + heigth + weight + bands + spec_data
|
data_send = length + cmd.upper().encode('ascii') + heigth + weight + bands + spec_data
|
||||||
win32file.WriteFile(self.spec_send, data_send)
|
win32file.WriteFile(self.spec_send, data_send)
|
||||||
print(f'发送的光谱数据长度: {len(data_send)}')
|
print(f'发送的光谱数据长度: {len(data_send)}')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user