7 changed files with 280 additions and 7 deletions
@ -0,0 +1,86 @@ |
|||||||
|
import open3d as o3d |
||||||
|
import numpy as np |
||||||
|
import matplotlib.pyplot as plt |
||||||
|
import sys |
||||||
|
import statistics |
||||||
|
import math |
||||||
|
import copy |
||||||
|
import os,time |
||||||
|
from scipy.stats import mode |
||||||
|
from scipy.spatial import KDTree |
||||||
|
from scipy.spatial import cKDTree |
||||||
|
import matplotlib.font_manager as fm |
||||||
|
|
||||||
|
#处理点云文件保存脚踝一下的部分点云 |
||||||
|
def dealPointData(pidPath,pidNewPath): |
||||||
|
# 读取 PLY 文件 |
||||||
|
point_cloud = o3d.io.read_point_cloud(pidPath) |
||||||
|
# 移除离散点 |
||||||
|
cl, ind = point_cloud.remove_statistical_outlier(nb_neighbors=20, std_ratio=0.06) |
||||||
|
point_cloud = point_cloud.select_by_index(ind) |
||||||
|
# 保存处理后的点云 |
||||||
|
o3d.io.write_point_cloud(pidNewPath, point_cloud) |
||||||
|
data = np.loadtxt(pidNewPath) |
||||||
|
# 提取xyz坐标 |
||||||
|
x = data[:, 0] |
||||||
|
y = data[:, 1] |
||||||
|
z = data[:, 2] |
||||||
|
# 创建一个布尔索引,筛选出在x-y平面内,半径在0.5范围内的点 (z >= 0.00) & |
||||||
|
mask = (z >=0) & (z <= 0.1) & (x**2 + y**2 <= 0.7**2) |
||||||
|
# 根据索引,保留符合条件的点 |
||||||
|
filtered_data = data[mask] |
||||||
|
# 将保留的点云数据保存到新的文件 |
||||||
|
np.savetxt(pidNewPath, filtered_data, delimiter=' ') |
||||||
|
|
||||||
|
|
||||||
|
#计算点云的数据中,脚底和地板的切线位置 |
||||||
|
def boxCenter(pid): |
||||||
|
pidPath = "D:\\xyz\\" + str(pid) + "_point.xyz" |
||||||
|
pidNewPath = "D:\\xyz\\" + str(pid) + "_new.xyz" |
||||||
|
dealPointData(pidPath,pidNewPath) |
||||||
|
|
||||||
|
pcd = o3d.io.read_point_cloud(pidNewPath) |
||||||
|
allPoints = np.asarray(pcd.points) |
||||||
|
if len(allPoints) == 0: |
||||||
|
print("点云为空,无法计算均值。") |
||||||
|
return 0 |
||||||
|
|
||||||
|
# 使用RANSAC算法提取平面 |
||||||
|
plane_model, inliers = pcd.segment_plane(distance_threshold=0.00670, ransac_n=3, num_iterations=1000) |
||||||
|
inlier_cloud = pcd.select_by_index(inliers) |
||||||
|
# 获取被染成红色的点的坐标数组 |
||||||
|
red_points = inlier_cloud.points |
||||||
|
red_points_np = np.asarray(red_points) |
||||||
|
# 获取 red_points_np 的 z 值数组 |
||||||
|
z_red_values = red_points_np[:, 2] |
||||||
|
# 计算中位数 |
||||||
|
medianRed = np.median(z_red_values) |
||||||
|
# 计算中位数向上的平均数 |
||||||
|
meanRedUp = np.mean(z_red_values[z_red_values > medianRed]) |
||||||
|
#计算中位数向下的平均数 |
||||||
|
#meanRedDown = np.mean(z_red_values[z_red_values < medianRed]) |
||||||
|
|
||||||
|
# Exclude ground points from allPoints |
||||||
|
foot_points_np = np.asarray([point for point in allPoints if point not in red_points_np]) |
||||||
|
if len(foot_points_np) == 0 : |
||||||
|
print("脚部点云为空。") |
||||||
|
return 0 |
||||||
|
#过滤掉地板,计算出脚底的点云数据 |
||||||
|
points_np_foot = foot_points_np[(foot_points_np[:, 2] < 0.046) & (foot_points_np[:, 2] > meanRedUp)] |
||||||
|
# 计算平均值 |
||||||
|
mean = np.mean(points_np_foot[:, 2]) |
||||||
|
|
||||||
|
# 按照 Z 值进行排序 |
||||||
|
sorted_points = points_np_foot[np.argsort(points_np_foot[:, 2])] |
||||||
|
# 获取 Z 值最低的前十个点 |
||||||
|
if len(sorted_points) == 0: |
||||||
|
print("脚底板最低的点云为空") |
||||||
|
return 0 |
||||||
|
try: |
||||||
|
lowest_points = sorted_points[10:20] |
||||||
|
except Exception as e: |
||||||
|
print("获取脚底板最低的倒数第十到20的点出现异常错误") |
||||||
|
return 0 |
||||||
|
# 计算平均值 |
||||||
|
meanLowEst = np.mean(lowest_points[:, 2]) + 1.05 |
||||||
|
return meanLowEst |
||||||
@ -0,0 +1,76 @@ |
|||||||
|
|
||||||
|
import redis,requests,json,os,sys |
||||||
|
|
||||||
|
import platform |
||||||
|
if platform.system() == 'Windows': |
||||||
|
sys.path.append('e:\\libs\\') |
||||||
|
else: |
||||||
|
sys.path.append('/data/deploy/make3d/make2/libs/') |
||||||
|
import config |
||||||
|
|
||||||
|
import requests |
||||||
|
from PIL import Image |
||||||
|
from io import BytesIO |
||||||
|
|
||||||
|
def main(): |
||||||
|
#连接mp 的redis |
||||||
|
r = redis.Redis(host="106.14.158.208",password="kcV2000",port=6379,db=1) |
||||||
|
#取出数据 |
||||||
|
oemId = r.lpop('setup') |
||||||
|
oemId = 21 |
||||||
|
if oemId is None: |
||||||
|
print("没有从redis中获取到oemId的数据") |
||||||
|
return |
||||||
|
print("oemId",oemId) |
||||||
|
#请求mp的接口,获取对应的oem的数据 |
||||||
|
res = requests.get("http://172.16.20.7:8199/api/oem/infoById",params={"id":oemId}) |
||||||
|
#获取数据解析数据 |
||||||
|
# print(res.text) |
||||||
|
#解析数据 |
||||||
|
data = json.loads(res.text) |
||||||
|
# print(data) |
||||||
|
if data['code'] != 1000: |
||||||
|
print("根据id获取oem数据失败") |
||||||
|
return |
||||||
|
print(data['data']) |
||||||
|
|
||||||
|
#pythob 进入到 E:\wails\oemProject ,将 data 数据写入到 wails.json 文件中的 ext_oem 字段中 |
||||||
|
with open("D:\\oemProject\\wails.json","r",encoding="utf-8") as f: |
||||||
|
wailsData = json.load(f) |
||||||
|
wailsData['ext_oem'] = data['data'] |
||||||
|
wailsData['name'] = data['data']['brand_name'] |
||||||
|
wailsData["outputfilename"] = str(data['data']['id']) |
||||||
|
with open("D:\\oemProject\\wails.json","w",encoding="utf-8") as f: |
||||||
|
json.dump(wailsData,f,ensure_ascii=False,indent=4) |
||||||
|
|
||||||
|
# #将图片下载到本地 |
||||||
|
getExeImg(data['data']['logo'], "D:\\oemProject\\build\\appicon.png") |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#写入成功后在 E:\\wails\\oemProject\\ 目录下执行 wails build 命令 |
||||||
|
os.system("cd D:\\oemProject && wails build") |
||||||
|
|
||||||
|
# #执行 wails build 命令后,将 E:\wails\oemProject\build\bin ,在上传到 oss 中 |
||||||
|
config.oss_bucket.put_object_from_file(f'exe/'+str(data['data']['id'])+".exe", "D:\\oemProject\\build\\bin\\"+str(data['data']['id'])+".exe") |
||||||
|
print("上传成功") |
||||||
|
# #上传成功后,调用接口,告诉mp,已经生成exe及上传成功 |
||||||
|
requests.get("http://172.16.20.7:8199/api/oem/infoSetupUpdate",params={"id":oemId}) |
||||||
|
|
||||||
|
|
||||||
|
def getExeImg(image_url, output_path): |
||||||
|
# 从URL获取图片 |
||||||
|
response = requests.get(image_url) |
||||||
|
if response.status_code == 200: |
||||||
|
# 将内容读取为图片 |
||||||
|
image = Image.open(BytesIO(response.content)) |
||||||
|
# 修改图片尺寸为1024x1024 |
||||||
|
resized_image = image.resize((1024, 1024)) |
||||||
|
# 保存图片为PNG格式 |
||||||
|
resized_image.save(output_path, 'PNG') |
||||||
|
else: |
||||||
|
print(f"Failed to download image. Status code: {response.status_code}") |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__': |
||||||
|
main() |
||||||
Loading…
Reference in new issue