UPDATE Vision 保存图片和点云

This commit is contained in:
HJW
2024-09-14 14:41:08 +08:00
parent a058281441
commit 7517e9eac7
6 changed files with 83 additions and 13 deletions

View File

@ -16,11 +16,13 @@ from Vision.yolo.yolov8_pt_seg import yolov8_segment
from Vision.yolo.yolov8_openvino import yolov8_segment_openvino
from Vision.tool.utils import find_position
from Vision.tool.utils import class_names
from Vision.tool.utils import get_disk_space
import time
import os
class Detection:
def __init__(self, use_openvino_model = True):
def __init__(self, use_openvino_model=True):
self.use_openvino_model = use_openvino_model
if self.use_openvino_model==False:
model_path = ''.join([os.getcwd(), '/Vision/model/pt/best.pt'])
@ -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
@ -45,6 +47,22 @@ class Detection:
ret, img, pm = self.camera_rvc.get_img_and_point_map() # 拍照,获取图像及
if self.camera_rvc.caminit_isok == True:
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:
flag, det_cpu, dst_img, masks, category_names = self.model.model_inference(img, 0)
else:
@ -196,9 +214,14 @@ class Detection:
outlier_cloud = pcd.select_by_index(inliers, invert=True)
outlier_cloud.paint_uniform_color([0, 1, 0])
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]
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
else:

View File

@ -11,11 +11,13 @@
import numpy as np
import cv2
import open3d as o3d
import time
from Vision.tool.CameraRVC import camera
from Vision.yolo.yolov8_pt_seg import yolov8_segment
from Vision.yolo.yolov8_openvino import yolov8_segment_openvino
from Vision.tool.utils import find_position
from Vision.tool.utils import class_names
from Vision.tool.utils import get_disk_space
import os
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
@ -50,6 +52,24 @@ class Detection:
img = self.img
pm = self.point
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:
flag, det_cpu, dst_img, masks, category_names = self.model.model_inference(img, 0)
else:
@ -61,6 +81,7 @@ class Detection:
Depth_Z = []
uv = []
seg_point = []
if Point_isVision == True:
pm2 = pm.copy()
pm2 = pm2.reshape(-1, 3)
@ -200,9 +221,16 @@ class Detection:
outlier_cloud = pcd.select_by_index(inliers, invert=True)
outlier_cloud.paint_uniform_color([0, 1, 0])
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]
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
else:

View File

@ -7,7 +7,7 @@
'''
import time
from camera_coordinate_dete import Detection
from camera_coordinate_dete_img import Detection
import cv2
detection = Detection()

View File

@ -10,7 +10,18 @@
import numpy as np
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):
if first_depth == True:
sorted_id = sorted(range(len(Depth_Z)), key=lambda k: Depth_Z[k], reverse=False)