UPDATE Vision 修正box输出
This commit is contained in:
@ -18,7 +18,6 @@ from Vision.tool.utils import find_position
|
||||
from Vision.tool.utils import class_names
|
||||
from Vision.tool.utils import get_disk_space
|
||||
from Vision.tool.utils import remove_nan
|
||||
from Vision.tool.utils import compute_pca_direction
|
||||
import time
|
||||
import os
|
||||
|
||||
@ -77,7 +76,6 @@ class Detection:
|
||||
uv = []
|
||||
seg_point = []
|
||||
box_list = []
|
||||
pca_list = []
|
||||
if Point_isVision==True:
|
||||
pm2 = pm.copy()
|
||||
pm2 = pm2.reshape(-1, 3)
|
||||
@ -153,9 +151,6 @@ class Detection:
|
||||
continue
|
||||
|
||||
# cv2.imshow('result', piont_result)
|
||||
|
||||
pca_list.append(compute_pca_direction(pm_seg))
|
||||
|
||||
'''
|
||||
拟合平面,计算法向量
|
||||
'''
|
||||
@ -231,20 +226,20 @@ class Detection:
|
||||
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], box_list[_idx], pca_list[_idx]
|
||||
return 1, img, xyz[_idx], nx_ny_nz[_idx], box_list[_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, None, None
|
||||
return 1, img, None, None, None
|
||||
|
||||
else:
|
||||
print("RVC X Camera capture failed!")
|
||||
return 0, None, None, None, None, None
|
||||
return 0, None, None, None, None
|
||||
|
||||
else:
|
||||
print("RVC X Camera is not opened!")
|
||||
return 0, None, None, None, None, None
|
||||
return 0, None, None, None, None
|
||||
|
||||
def release(self):
|
||||
self.camera_rvc.release()
|
||||
|
||||
@ -19,8 +19,6 @@ from Vision.tool.utils import find_position
|
||||
from Vision.tool.utils import class_names
|
||||
from Vision.tool.utils import get_disk_space
|
||||
from Vision.tool.utils import remove_nan
|
||||
from Vision.tool.utils import compute_pca_direction
|
||||
from Vision.tool.utils import pca
|
||||
|
||||
import os
|
||||
|
||||
@ -86,8 +84,6 @@ class Detection:
|
||||
uv = []
|
||||
seg_point = []
|
||||
box_list = []
|
||||
pca_list = []
|
||||
pca_nx_ny_nz = []
|
||||
|
||||
if Point_isVision == True:
|
||||
pm2 = pm.copy()
|
||||
@ -163,8 +159,6 @@ class Detection:
|
||||
print("分割点云数量较少,无法拟合平面")
|
||||
continue
|
||||
# cv2.imshow('result', piont_result)
|
||||
pca_list.append(compute_pca_direction(pm_seg))
|
||||
pca_nx_ny_nz.append(pca(pm_seg))
|
||||
'''
|
||||
拟合平面,计算法向量
|
||||
'''
|
||||
@ -240,17 +234,17 @@ class Detection:
|
||||
save_img = cv2.resize(img,(720, 540))
|
||||
cv2.imwrite(save_img_name, save_img)
|
||||
|
||||
return 1, img, xyz[_idx], nx_ny_nz[_idx], box_list[_idx], pca_list[_idx], pca_nx_ny_nz[_idx]
|
||||
return 1, img, xyz[_idx], nx_ny_nz[_idx], box_list[_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, None, None, None
|
||||
return 1, img, None, None, None
|
||||
|
||||
else:
|
||||
print("RVC X Camera capture failed!")
|
||||
return 0, None, None, None, None, None, None
|
||||
return 0, None, None, None, None
|
||||
|
||||
def release(self):
|
||||
self.model.clear()
|
||||
|
||||
@ -14,7 +14,7 @@ detection = Detection()
|
||||
|
||||
while True:
|
||||
t1 = time.time()
|
||||
ret, img, xyz, nx_ny_nz = detection.get_position()
|
||||
ret, img, xyz, nx_ny_nz, box = detection.get_position()
|
||||
if ret==1:
|
||||
print('xyz点云坐标:', xyz)
|
||||
print('nx_ny_nz法向量:', nx_ny_nz)
|
||||
|
||||
@ -13,13 +13,14 @@ import cv2
|
||||
detection = Detection()
|
||||
|
||||
while True:
|
||||
ret, img, xyz, nx_ny_nz = detection.get_position()
|
||||
ret, img, xyz, nx_ny_nz, box = detection.get_position()
|
||||
if ret==1:
|
||||
print('xyz点云坐标:', xyz)
|
||||
print('nx_ny_nz法向量:', nx_ny_nz)
|
||||
print('矩形框四顶点:', box)
|
||||
img = cv2.resize(img,(720, 540))
|
||||
transformation_matrix = R_matrix(521.534, 0.705, 850.03, 0.0, 90.0, 0.0) # (x, y, z, u, v, w)
|
||||
target_position, noraml_base = getPosition(xyz[0], xyz[1], xyz[2], nx_ny_nz[0], nx_ny_nz[1], nx_ny_nz[2], transformation_matri,box)
|
||||
target_position, noraml_base = getPosition(xyz[0], xyz[1], xyz[2], nx_ny_nz[0], nx_ny_nz[1], nx_ny_nz[2], transformation_matrix, box)
|
||||
print("target_position:", target_position)
|
||||
print("noraml_base", noraml_base)
|
||||
cv2.imshow('img', img)
|
||||
|
||||
@ -12,37 +12,6 @@ import numpy as np
|
||||
import cv2
|
||||
import psutil
|
||||
from psutil._common import bytes2human
|
||||
from sklearn.decomposition import PCA
|
||||
|
||||
def pca(points):
|
||||
# 计算PCA
|
||||
mean = np.mean(points, axis=0)
|
||||
cov = np.cov(points, rowvar=False)
|
||||
eigenvalues, eigenvectors = np.linalg.eigh(cov)
|
||||
|
||||
# 对特征值进行排序并找到对应的特征向量
|
||||
sorted_indices = np.argsort(eigenvalues)[::-1]
|
||||
sorted_eigenvalues = eigenvalues[sorted_indices]
|
||||
sorted_eigenvectors = eigenvectors[:, sorted_indices]
|
||||
|
||||
# # 打印PCA结果
|
||||
# print("PCA Mean:", mean)
|
||||
# print("PCA Eigenvalues:", sorted_eigenvalues)
|
||||
# print("PCA Eigenvectors:\n", sorted_eigenvectors)
|
||||
|
||||
# 通常,最小特征值对应的特征向量是平面的法线
|
||||
normal_vector = sorted_eigenvectors[:, 0] if sorted_eigenvalues[0] < sorted_eigenvalues[
|
||||
1] else sorted_eigenvectors[:, 1]
|
||||
# print("法向量:", normal_vector)
|
||||
return normal_vector
|
||||
|
||||
|
||||
def compute_pca_direction(points):
|
||||
# points 是物体点云的坐标
|
||||
pca = PCA(n_components=3)
|
||||
pca.fit(points)
|
||||
primary_direction = pca.components_[0] # 第一主成分对应的方向向量
|
||||
return primary_direction
|
||||
|
||||
def remove_nan(pm, y, x):
|
||||
piont_x, piont_y, piont_z = pm[y, x]
|
||||
|
||||
@ -14,20 +14,15 @@ import cv2
|
||||
detection = Detection()
|
||||
|
||||
while True:
|
||||
ret, img, xyz, nx_ny_nz = detection.get_position()
|
||||
ret, img, xyz, nx_ny_nz, box = detection.get_position()
|
||||
if ret==1:
|
||||
print('xyz点云坐标:', xyz)
|
||||
print('nx_ny_nz法向量:', nx_ny_nz)
|
||||
print('矩形框四顶点:', box)
|
||||
img = cv2.resize(img,(720, 540))
|
||||
transformation_matrix = R_matrix(521.534, 0.705, 850.03, 0.0, 90.0, 0.0) # (x, y, z, u, v, w)
|
||||
target_position, noraml_base = getPosition(xyz[0], xyz[1], xyz[2], nx_ny_nz[0], nx_ny_nz[1], nx_ny_nz[2], transformation_matrix)
|
||||
target_position, noraml_base = getPosition(xyz[0], xyz[1], xyz[2], nx_ny_nz[0], nx_ny_nz[1], nx_ny_nz[2], transformation_matrix, box)
|
||||
print("target_position:", target_position)
|
||||
print("noraml_base", noraml_base)
|
||||
cv2.imshow('img', img)
|
||||
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)
|
||||
cv2.waitKey(0)
|
||||
Reference in New Issue
Block a user