UPDATE Vision 限定料袋的图像中心点

This commit is contained in:
hjw
2024-12-21 21:32:11 +08:00
parent 1efd0385e1
commit 9812481423
3 changed files with 15 additions and 7 deletions

View File

@ -66,7 +66,7 @@ class Detection:
self.model = yolov8_segment_openvino(model_path, device, conf_thres=0.3, iou_thres=0.3) self.model = yolov8_segment_openvino(model_path, device, conf_thres=0.3, iou_thres=0.3)
def get_position(self, Point_isVision=False, Box_isPoint=True, First_Depth =True, Iter_Max_Pixel = 30, save_img_point=0, Height_reduce = 60, width_reduce = 100): def get_position(self, Point_isVision=False, Box_isPoint=True, First_Depth =True, Iter_Max_Pixel = 30, save_img_point=0, Height_reduce = 60, width_reduce = 100, Xmin =330, Xmax = 1050, Ymin =290 ,Ymax = 690 ):
""" """
检测料袋相关信息 检测料袋相关信息
:param Point_isVision: 点云可视化 :param Point_isVision: 点云可视化
@ -76,6 +76,10 @@ class Detection:
:param save_img_point: 0不保存 ; 1保存原图 ;2保存处理后的图 ; 3保存点云和原图4 保存点云和处理后的图; 5 异常数据保存点云NAN :param save_img_point: 0不保存 ; 1保存原图 ;2保存处理后的图 ; 3保存点云和原图4 保存点云和处理后的图; 5 异常数据保存点云NAN
:param Height_reduce: 检测框的高内缩像素 :param Height_reduce: 检测框的高内缩像素
:param width_reduce: 检测框的宽内缩像素 :param width_reduce: 检测框的宽内缩像素
:param Xmin: 限定中心点的范围
:param Xmax: 限定中心点的范围
:param Ymin: 限定中心点的范围
:param Ymax: 限定中心点的范围
:return ret: bool 相机是否正常工作 :return ret: bool 相机是否正常工作
:return img: ndarray 返回img :return img: ndarray 返回img
:return xyz: list 目标中心点云值形如[x,y,z] :return xyz: list 目标中心点云值形如[x,y,z]
@ -261,6 +265,8 @@ class Detection:
x_rotation_center = int((box[0][0][0] + box[1][0][0] + box[2][0][0] + box[3][0][0]) / 4) x_rotation_center = int((box[0][0][0] + box[1][0][0] + box[2][0][0] + box[3][0][0]) / 4)
y_rotation_center = int((box[0][0][1] + box[1][0][1] + box[2][0][1] + box[3][0][1]) / 4) y_rotation_center = int((box[0][0][1] + box[1][0][1] + box[2][0][1] + box[3][0][1]) / 4)
point_x, point_y, point_z = remove_nan_mean_value(pm, y_rotation_center, x_rotation_center, iter_max=Iter_Max_Pixel) point_x, point_y, point_z = remove_nan_mean_value(pm, y_rotation_center, x_rotation_center, iter_max=Iter_Max_Pixel)
if x_rotation_center<Xmin or x_rotation_center>Xmax or y_rotation_center<Ymin or y_rotation_center>Ymax:
continue
cv2.circle(img, (x_rotation_center, y_rotation_center), 4, (255, 255, 255), 5) # 标出中心点 cv2.circle(img, (x_rotation_center, y_rotation_center), 4, (255, 255, 255), 5) # 标出中心点
if np.isnan(point_x): # 点云值为无效值 if np.isnan(point_x): # 点云值为无效值
continue continue

View File

@ -8,18 +8,20 @@
import cv2 import cv2
import numpy as np import numpy as np
img = cv2.imread('./model/data/0925_01_28.png') img = cv2.imread('./model/data/2024_12_16_18_32_40.png')
img2 = img[:600, 380:] img2 = img[:600, 380:]
cv2.imshow('img2',img2) img = cv2.resize(img,(640,480))
cv2.imshow('img',img) # cv2.imshow('img3',img3)
cv2.waitKey(0) # cv2.imshow('img2',img2)
# cv2.imshow('img',img)
# cv2.waitKey(0)
def on_EVENT_LBUTTONDOWN(event, x, y, flags, param): def on_EVENT_LBUTTONDOWN(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN: if event == cv2.EVENT_LBUTTONDOWN:
xy = "%d,%d" % (x, y) xy = "%d,%d" % (x, y)
cv2.circle(img, (x, y), 1, (255, 0, 0), thickness = -1) cv2.circle(img, (x, y), 1, (0, 0, 255), thickness = -1)
cv2.putText(img, xy, (x, y), cv2.FONT_HERSHEY_PLAIN, cv2.putText(img, xy, (x, y), cv2.FONT_HERSHEY_PLAIN,
1.0, (0,0,0), thickness = 1) 1.0, (0,0,255), thickness = 1)
cv2.imshow("image", img) cv2.imshow("image", img)
cv2.namedWindow("image") cv2.namedWindow("image")
cv2.setMouseCallback("image", on_EVENT_LBUTTONDOWN) cv2.setMouseCallback("image", on_EVENT_LBUTTONDOWN)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB