UPDATE Vision 保存图片和点云
This commit is contained in:
@ -16,6 +16,8 @@ from Vision.yolo.yolov8_pt_seg import yolov8_segment
|
|||||||
from Vision.yolo.yolov8_openvino import yolov8_segment_openvino
|
from Vision.yolo.yolov8_openvino import yolov8_segment_openvino
|
||||||
from Vision.tool.utils import find_position
|
from Vision.tool.utils import find_position
|
||||||
from Vision.tool.utils import class_names
|
from Vision.tool.utils import class_names
|
||||||
|
from Vision.tool.utils import get_disk_space
|
||||||
|
import time
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class Detection:
|
class Detection:
|
||||||
@ -36,7 +38,7 @@ class Detection:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_position(self, Point_isVision=False):
|
def get_position(self, Point_isVision=False, save_img_piont=True):
|
||||||
""
|
""
|
||||||
'''
|
'''
|
||||||
:param api: None
|
:param api: None
|
||||||
@ -45,6 +47,22 @@ class Detection:
|
|||||||
ret, img, pm = self.camera_rvc.get_img_and_point_map() # 拍照,获取图像及
|
ret, img, pm = self.camera_rvc.get_img_and_point_map() # 拍照,获取图像及
|
||||||
if self.camera_rvc.caminit_isok == True:
|
if self.camera_rvc.caminit_isok == True:
|
||||||
if ret == 1:
|
if ret == 1:
|
||||||
|
if save_img_piont == True:
|
||||||
|
if get_disk_space(path=os.getcwd()) < 15: # 内存小于15G,停止保存数据
|
||||||
|
save_img_piont = False
|
||||||
|
print('系统内存不足,无法保存数据')
|
||||||
|
else:
|
||||||
|
save_path = ''.join([os.getcwd(), '/Vision/model/data/',
|
||||||
|
time.strftime('%Y_%m_%d_%H_%M_%S', time.localtime(time.time()))])
|
||||||
|
save_img_name = ''.join([save_path, '.png'])
|
||||||
|
save_piont_name = ''.join([save_path, '.xyz'])
|
||||||
|
row_list = list(range(1, 1080, 2))
|
||||||
|
column_list = list(range(1, 1440, 2))
|
||||||
|
pm_save = pm.copy()
|
||||||
|
pm_save1 = np.delete(pm_save, row_list, axis=0)
|
||||||
|
point_new = np.delete(pm_save1, column_list, axis=1)
|
||||||
|
point_new = point_new.reshape(-1, 3)
|
||||||
|
np.savetxt(save_piont_name, point_new)
|
||||||
if self.use_openvino_model == False:
|
if self.use_openvino_model == False:
|
||||||
flag, det_cpu, dst_img, masks, category_names = self.model.model_inference(img, 0)
|
flag, det_cpu, dst_img, masks, category_names = self.model.model_inference(img, 0)
|
||||||
else:
|
else:
|
||||||
@ -196,9 +214,14 @@ class Detection:
|
|||||||
outlier_cloud = pcd.select_by_index(inliers, invert=True)
|
outlier_cloud = pcd.select_by_index(inliers, invert=True)
|
||||||
outlier_cloud.paint_uniform_color([0, 1, 0])
|
outlier_cloud.paint_uniform_color([0, 1, 0])
|
||||||
o3d.visualization.draw_geometries([inlier_cloud, outlier_cloud, pcd2])
|
o3d.visualization.draw_geometries([inlier_cloud, outlier_cloud, pcd2])
|
||||||
|
if save_img_piont == True:
|
||||||
|
save_img = cv2.resize(img, (720, 540))
|
||||||
|
cv2.imwrite(save_img_name, save_img)
|
||||||
return 1, img, xyz[_idx], nx_ny_nz[_idx]
|
return 1, img, xyz[_idx], nx_ny_nz[_idx]
|
||||||
else:
|
else:
|
||||||
|
if save_img_piont == True:
|
||||||
|
save_img = cv2.resize(img,(720, 540))
|
||||||
|
cv2.imwrite(save_img_name, save_img)
|
||||||
return 1, img, None, None
|
return 1, img, None, None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -11,11 +11,13 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2
|
import cv2
|
||||||
import open3d as o3d
|
import open3d as o3d
|
||||||
|
import time
|
||||||
from Vision.tool.CameraRVC import camera
|
from Vision.tool.CameraRVC import camera
|
||||||
from Vision.yolo.yolov8_pt_seg import yolov8_segment
|
from Vision.yolo.yolov8_pt_seg import yolov8_segment
|
||||||
from Vision.yolo.yolov8_openvino import yolov8_segment_openvino
|
from Vision.yolo.yolov8_openvino import yolov8_segment_openvino
|
||||||
from Vision.tool.utils import find_position
|
from Vision.tool.utils import find_position
|
||||||
from Vision.tool.utils import class_names
|
from Vision.tool.utils import class_names
|
||||||
|
from Vision.tool.utils import get_disk_space
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class Detection:
|
class Detection:
|
||||||
@ -39,7 +41,7 @@ class Detection:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_position(self, Point_isVision=False):
|
def get_position(self, Point_isVision=False, save_img_piont=True):
|
||||||
""
|
""
|
||||||
'''
|
'''
|
||||||
:param api: None
|
:param api: None
|
||||||
@ -50,6 +52,24 @@ class Detection:
|
|||||||
img = self.img
|
img = self.img
|
||||||
pm = self.point
|
pm = self.point
|
||||||
if ret == 1:
|
if ret == 1:
|
||||||
|
if save_img_piont == True:
|
||||||
|
if get_disk_space(path=os.getcwd())<15: # 内存小于15G,停止保存数据
|
||||||
|
save_img_piont = False
|
||||||
|
print('系统内存不足,无法保存数据')
|
||||||
|
else:
|
||||||
|
save_path = ''.join([os.getcwd(), '/Vision/model/data/',
|
||||||
|
time.strftime('%Y_%m_%d_%H_%M_%S', time.localtime(time.time()))])
|
||||||
|
save_img_name = ''.join([save_path, '.png'])
|
||||||
|
save_piont_name = ''.join([save_path, '.xyz'])
|
||||||
|
row_list = list(range(1, 1080, 2))
|
||||||
|
column_list = list(range(1, 1440, 2))
|
||||||
|
pm_save = pm.copy()
|
||||||
|
pm_save1 = np.delete(pm_save, row_list, axis=0)
|
||||||
|
point_new = np.delete(pm_save1, column_list, axis=1)
|
||||||
|
point_new = point_new.reshape(-1, 3)
|
||||||
|
np.savetxt(save_piont_name, point_new)
|
||||||
|
|
||||||
|
|
||||||
if self.use_openvino_model == False:
|
if self.use_openvino_model == False:
|
||||||
flag, det_cpu, dst_img, masks, category_names = self.model.model_inference(img, 0)
|
flag, det_cpu, dst_img, masks, category_names = self.model.model_inference(img, 0)
|
||||||
else:
|
else:
|
||||||
@ -61,6 +81,7 @@ class Detection:
|
|||||||
Depth_Z = []
|
Depth_Z = []
|
||||||
uv = []
|
uv = []
|
||||||
seg_point = []
|
seg_point = []
|
||||||
|
|
||||||
if Point_isVision == True:
|
if Point_isVision == True:
|
||||||
pm2 = pm.copy()
|
pm2 = pm.copy()
|
||||||
pm2 = pm2.reshape(-1, 3)
|
pm2 = pm2.reshape(-1, 3)
|
||||||
@ -200,9 +221,16 @@ class Detection:
|
|||||||
outlier_cloud = pcd.select_by_index(inliers, invert=True)
|
outlier_cloud = pcd.select_by_index(inliers, invert=True)
|
||||||
outlier_cloud.paint_uniform_color([0, 1, 0])
|
outlier_cloud.paint_uniform_color([0, 1, 0])
|
||||||
o3d.visualization.draw_geometries([inlier_cloud, outlier_cloud, pcd2])
|
o3d.visualization.draw_geometries([inlier_cloud, outlier_cloud, pcd2])
|
||||||
|
if save_img_piont == True:
|
||||||
|
save_img = cv2.resize(img,(720, 540))
|
||||||
|
cv2.imwrite(save_img_name, save_img)
|
||||||
|
|
||||||
return 1, img, xyz[_idx], nx_ny_nz[_idx]
|
return 1, img, xyz[_idx], nx_ny_nz[_idx]
|
||||||
else:
|
else:
|
||||||
|
if save_img_piont == True:
|
||||||
|
save_img = cv2.resize(img, (720, 540))
|
||||||
|
cv2.imwrite(save_img_name, save_img)
|
||||||
|
|
||||||
return 1, img, None, None
|
return 1, img, None, None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
'''
|
'''
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from camera_coordinate_dete import Detection
|
from camera_coordinate_dete_img import Detection
|
||||||
import cv2
|
import cv2
|
||||||
|
|
||||||
detection = Detection()
|
detection = Detection()
|
||||||
|
|||||||
@ -10,7 +10,18 @@
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2
|
import cv2
|
||||||
|
import psutil
|
||||||
|
from psutil._common import bytes2human
|
||||||
|
def get_disk_space(path='C:'):
|
||||||
|
|
||||||
|
usage = psutil.disk_usage(path)
|
||||||
|
space_free = bytes2human(usage.free)
|
||||||
|
# space_total = bytes2human(usage.total)
|
||||||
|
# space_used = bytes2human(usage.used)
|
||||||
|
# space_free = bytes2human(usage.free)
|
||||||
|
# space_used_percent = bytes2human(usage.percent)
|
||||||
|
space_free = float(space_free[:-1])
|
||||||
|
return space_free
|
||||||
def find_position(Depth_Z, RegionalArea, RegionalArea_Threshold, first_depth=True):
|
def find_position(Depth_Z, RegionalArea, RegionalArea_Threshold, first_depth=True):
|
||||||
if first_depth == True:
|
if first_depth == True:
|
||||||
sorted_id = sorted(range(len(Depth_Z)), key=lambda k: Depth_Z[k], reverse=False)
|
sorted_id = sorted(range(len(Depth_Z)), key=lambda k: Depth_Z[k], reverse=False)
|
||||||
|
|||||||
13
app.py
13
app.py
@ -35,13 +35,14 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(MainWindow, self).__init__()
|
super(MainWindow, self).__init__()
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
self.init_qss()
|
||||||
self.init_UI()
|
self.init_UI()
|
||||||
self.init_Run()
|
self.init_Run()
|
||||||
self.init_robot_info()
|
self.init_robot_info()
|
||||||
self.init_FeedLine()
|
self.init_FeedLine()
|
||||||
self.start_Runing()
|
self.start_Runing()
|
||||||
self.init_log()
|
self.init_log()
|
||||||
self.init_qss()
|
|
||||||
|
|
||||||
def init_qss(self):
|
def init_qss(self):
|
||||||
self.active_status_Qss = """
|
self.active_status_Qss = """
|
||||||
@ -683,11 +684,11 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||||||
else:
|
else:
|
||||||
self.stackedWidget_num.setCurrentIndex(1)
|
self.stackedWidget_num.setCurrentIndex(1)
|
||||||
|
|
||||||
if self.feeding.feedConfig.num==2:
|
# if self.feeding.feedConfig.num==2:
|
||||||
self.feeding.pause=True
|
# self.feeding.pause=True
|
||||||
self.send_pause_command(True)
|
# self.send_pause_command(True)
|
||||||
self.show_messagebox_of_person()
|
# self.show_messagebox_of_person()
|
||||||
log.log_message(logging.ERROR, '人员进入安全区')
|
# log.log_message(logging.ERROR, '人员进入安全区')
|
||||||
self.label_date.setText(datetime.now().strftime("%Y-%m-%d"))
|
self.label_date.setText(datetime.now().strftime("%Y-%m-%d"))
|
||||||
self.label_time.setText(datetime.now().strftime("%H:%M:%S"))
|
self.label_time.setText(datetime.now().strftime("%H:%M:%S"))
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,8 @@
|
|||||||
'''
|
'''
|
||||||
from Vision.camera_coordinate_dete_img import Detection
|
from Vision.camera_coordinate_dete_img import Detection
|
||||||
from Trace.handeye_calibration import *
|
from Trace.handeye_calibration import *
|
||||||
|
from Vision.tool.utils import get_disk_space
|
||||||
|
import platform
|
||||||
import cv2
|
import cv2
|
||||||
|
|
||||||
detection = Detection()
|
detection = Detection()
|
||||||
@ -24,3 +25,9 @@ while True:
|
|||||||
print("noraml_base", noraml_base)
|
print("noraml_base", noraml_base)
|
||||||
cv2.imshow('img', img)
|
cv2.imshow('img', img)
|
||||||
cv2.waitKey(0)
|
cv2.waitKey(0)
|
||||||
|
# sysstr = platform.system()
|
||||||
|
# if sysstr == "Windows":
|
||||||
|
# space_free = get_disk_space(path=os.getcwd())
|
||||||
|
# else:
|
||||||
|
# space_free = get_disk_space(path = "D:")
|
||||||
|
# print('剩余空间: ', space_free)
|
||||||
Reference in New Issue
Block a user