first commit
This commit is contained in:
commit
677a836569
29 files changed
+1785
No files matched your search
@@ -0,0 +1,237 @@
|
||||
import os, oss2, sys, time
|
||||
import cv2
|
||||
import numpy as np
|
||||
from tqdm import tqdm
|
||||
import matplotlib.pyplot as plt
|
||||
from PIL import Image, ImageEnhance
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
import config, libs
|
||||
|
||||
def ps_color_scale_adjustment(image, shadow=0, highlight=255, midtones=1):
|
||||
'''
|
||||
模拟 PS 的色阶调整; 0 <= Shadow < Highlight <= 255
|
||||
:param image: 传入的图片
|
||||
:param shadow: 黑场(0-Highlight)
|
||||
:param highlight: 白场(Shadow-255)
|
||||
:param midtones: 灰场(9.99-0.01)
|
||||
:return: 图片
|
||||
'''
|
||||
if highlight > 255:
|
||||
highlight = 255
|
||||
if shadow < 0:
|
||||
shadow = 0
|
||||
if shadow >= highlight:
|
||||
shadow = highlight - 2
|
||||
if midtones > 9.99:
|
||||
midtones = 9.99
|
||||
if midtones < 0.01:
|
||||
midtones = 0.01
|
||||
image = np.array(image, dtype=np.float16)
|
||||
# 计算白场 黑场离差
|
||||
Diff = highlight - shadow
|
||||
image = image - shadow
|
||||
image[image < 0] = 0
|
||||
image = (image / Diff) ** (1 / midtones) * 255
|
||||
image[image > 255] = 255
|
||||
image = np.array(image, dtype=np.uint8)
|
||||
|
||||
return image
|
||||
|
||||
|
||||
def show_histogram(image, image_id, save_hist_dir, min_threshold, max_threshold):
|
||||
'''
|
||||
画出直方图展示
|
||||
:param image: 导入图片
|
||||
:param image_id: 图片id编号
|
||||
:param save_hist_dir: 保存路径
|
||||
:param min_threshold: 最小阈值
|
||||
:param max_threshold: 最大阈值
|
||||
:return: 原图image,和裁剪原图直方图高低阈值后的图片image_change
|
||||
'''
|
||||
plt.rcParams['font.family'] = 'SimHei'
|
||||
plt.rcParams['axes.unicode_minus'] = False
|
||||
plt.hist(image.ravel(), 254, range=(2, 256), density=False)
|
||||
plt.hist(image.ravel(), 96, range=(2, 50), density=False) # 放大 range(0, 50),bins值最好是range的两倍,显得更稀疏,便于对比
|
||||
plt.hist(image.ravel(), 110, range=(200, 255), density=False) # 放大 range(225, 255)
|
||||
plt.annotate('thresh1=' + str(min_threshold), # 文本内容
|
||||
xy=(min_threshold, 0), # 箭头指向位置 # 阈值设定值!
|
||||
xytext=(min_threshold, 500000), # 文本位置 # 阈值设定值!
|
||||
arrowprops=dict(facecolor='black', width=1, shrink=5, headwidth=2)) # 箭头
|
||||
plt.annotate('thresh2=' + str(max_threshold), # 文本内容
|
||||
xy=(max_threshold, 0), # 箭头指向位置 # 阈值设定值!
|
||||
xytext=(max_threshold, 500000), # 文本位置 # 阈值设定值!
|
||||
arrowprops=dict(facecolor='black', width=1, shrink=5, headwidth=2)) # 箭头
|
||||
# 在y轴上绘制一条直线
|
||||
# plt.axhline(y=10000, color='r', linestyle='--', linewidth=0.5)
|
||||
plt.title(str(image_id))
|
||||
# plt.show()
|
||||
# 保存直方图
|
||||
save_hist_name = os.path.join(save_hist_dir, f'{image_id}_{min_threshold}&{max_threshold}.jpg')
|
||||
plt.savefig(save_hist_name)
|
||||
# 清空画布, 防止重叠展示
|
||||
plt.clf()
|
||||
|
||||
|
||||
def low_find_histogram_range(image, target_frequency):
|
||||
'''
|
||||
循环查找在 target_frequency (y)频次限制下的直方图区间值(x)
|
||||
:param image: 导入图片
|
||||
:param target_frequency: 直方图 y 频次限制条件
|
||||
:return: 直方图区间 x,和 该区间频次 y
|
||||
'''
|
||||
# 计算灰度直方图
|
||||
hist, bins = np.histogram(image, bins=256, range=[0, 256])
|
||||
# 初始化区间和频次
|
||||
interval = 2
|
||||
frequency = hist[255]
|
||||
while frequency < target_frequency:
|
||||
# 更新区间和频次
|
||||
interval += 1
|
||||
# 检查直方图的频次是否为None,如果频次是None,则将其设为0,这样可以避免将None和int进行比较报错。
|
||||
frequency = hist[interval] if hist[interval] is not None else 0
|
||||
frequency += hist[interval] if hist[interval] is not None else 0
|
||||
print(f'x={interval}, y={frequency}')
|
||||
# 如果频次接近10000则停止循环
|
||||
if target_frequency - 2000 <= frequency <= target_frequency + 1000:
|
||||
break
|
||||
|
||||
return interval, frequency
|
||||
|
||||
|
||||
def high_find_histogram_range(image, target_frequency):
|
||||
'''
|
||||
循环查找在 target_frequency (y)频次限制下的直方图区间值(x)
|
||||
:param image: 导入图片
|
||||
:param target_frequency: 直方图 y 频次限制条件
|
||||
:return: 直方图区间 x,和 该区间频次 y
|
||||
'''
|
||||
# 计算灰度直方图
|
||||
hist, bins = np.histogram(image, bins=256, range=[0, 256])
|
||||
# 初始化区间和频次
|
||||
interval = 255
|
||||
frequency = hist[255]
|
||||
while frequency < target_frequency:
|
||||
# 更新区间和频次
|
||||
interval -= 1
|
||||
# 检查直方图的频次是否为None,如果频次是None,则将其设为0,这样可以避免将None和int进行比较报错。
|
||||
frequency = hist[interval] if hist[interval] is not None else 0
|
||||
frequency += hist[interval] if hist[interval] is not None else 0
|
||||
# 如果频次接近10000则停止循环
|
||||
if target_frequency - 2000 <= frequency <= target_frequency + 2000:
|
||||
break
|
||||
|
||||
return interval, frequency
|
||||
|
||||
|
||||
def sharpening_filter(image):
|
||||
'''
|
||||
锐化滤波器对图片进行锐化,增强图像中的边缘和细节
|
||||
:param image: 导入图片
|
||||
:return: 锐化后的图片
|
||||
'''
|
||||
# sharp_kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]])
|
||||
sharp_kernel = np.array([[0, -0.5, 0], [-0.5, 3, -0.5], [0, -0.5, 0]])
|
||||
sharpened_image = cv2.filter2D(image, -1, sharp_kernel)
|
||||
return sharpened_image
|
||||
|
||||
def reduce_sharpness(image, factor):
|
||||
'''
|
||||
使用PIL库减弱图像锐度
|
||||
:param image: 图像
|
||||
:param factor: 锐度因子,0表示最大程度减弱锐度,1表示原始图像
|
||||
:return: 减弱锐度后的图像
|
||||
'''
|
||||
# OpenCV 格式的图像转换为 PIL 的 Image 对象
|
||||
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||
pil_image = Image.fromarray(image_rgb)
|
||||
enhancer = ImageEnhance.Sharpness(pil_image)
|
||||
reduced_image = enhancer.enhance(factor)
|
||||
# PIL 的 Image 对象转换为 OpenCV 的图像格式
|
||||
image_array = np.array(reduced_image)
|
||||
sharpened_image = cv2.cvtColor(image_array, cv2.COLOR_RGB2BGR)
|
||||
|
||||
return sharpened_image
|
||||
|
||||
def find_last_x(image, slope_threshold = 1000):
|
||||
x = []
|
||||
y = []
|
||||
hist, bins = np.histogram(image, bins=256, range=[0, 256])
|
||||
for i in range(2, 50):
|
||||
x.append(i)
|
||||
y.append(hist[i])
|
||||
slopes = [abs(y[i + 1] - y[i]) for i in range(len(x) - 1)]
|
||||
|
||||
current_interval = []
|
||||
max_interval = []
|
||||
max_x = {}
|
||||
for i, slope in enumerate(slopes):
|
||||
current_interval.append(slope)
|
||||
if slope >= slope_threshold:
|
||||
if len(current_interval) > len(max_interval):
|
||||
max_interval = current_interval.copy()
|
||||
max_x[x[i]] = slope
|
||||
current_interval = []
|
||||
|
||||
print(max_x)
|
||||
last_x = list(max_x)[-1]
|
||||
last_y = max_x[last_x]
|
||||
return last_x, last_y
|
||||
|
||||
def main(pid, print_id):
|
||||
texture_filename = f'{input_dir}{pid}Tex1.{print_id}.jpg'
|
||||
input_image = cv2.imread(texture_filename)
|
||||
# low_x_thresh, low_y_frequency = low_find_histogram_range(input_image, low_y_limit)
|
||||
low_x_thresh, low_y_frequency = find_last_x(input_image, 1000)
|
||||
high_x_thresh, high_y_frequency = high_find_histogram_range(input_image, high_y_limit)
|
||||
print(f"{low_x_thresh} 区间, {low_y_frequency} 频次")
|
||||
print(f"{high_x_thresh} 区间, {high_y_frequency} 频次")
|
||||
high_output_image = ps_color_scale_adjustment(input_image, shadow=low_x_thresh, highlight=high_x_thresh, midtones=1)
|
||||
# high_output_image = ps_color_scale_adjustment(low_ouput_image, shadow=0, highlight=high_x_thresh, midtones=1)
|
||||
|
||||
# 人体贴图和黑色背景交界处不进行锐化
|
||||
gray = cv2.cvtColor(input_image, cv2.COLOR_BGR2GRAY)
|
||||
_, thresh = cv2.threshold(gray, 2, 255, cv2.THRESH_BINARY)
|
||||
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (7, 7))
|
||||
gradient = cv2.morphologyEx(thresh, cv2.MORPH_GRADIENT, kernel)
|
||||
roi_gradient = cv2.bitwise_and(high_output_image, high_output_image, mask=gradient)
|
||||
|
||||
# 锐化滤波器
|
||||
# sharpened_image = sharpening_filter(high_output_image)
|
||||
sharpened_image = reduce_sharpness(high_output_image, factor=4)
|
||||
# 将原图边界替换锐化后的图片边界
|
||||
sharpened_image[gradient != 0] = roi_gradient[gradient != 0]
|
||||
|
||||
# 直方图标记并保存
|
||||
# show_histogram(input_image, img_id, low_x_thresh, high_x_thresh)
|
||||
cv2.imwrite(texture_filename, sharpened_image, [cv2.IMWRITE_JPEG_QUALITY, 95]) # 保存图片的质量是原图的 95%
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
input_dir = "D:\\AI_pycharm\\Change_grayscale\\Texture_photos\\original_images\\"
|
||||
save_dir = "D:\\AI_pycharm\\Change_grayscale\\Texture_photos\\test\\"
|
||||
|
||||
low_y_limit = 48000
|
||||
high_y_limit = 13000
|
||||
|
||||
input_dir = '/data/datasets/texure_photos/'
|
||||
|
||||
pids = '99724,99747,99762,99763,99777,99778,99807,99812,99823,99843,99405,99416,97984,97662,86153'
|
||||
for pid in pids.split(','):
|
||||
pid, print_id = pid.split('_')
|
||||
# 根据前缀获取文件列表
|
||||
path = f'/data/datasets/texure_photos/'
|
||||
texture_filename = f'{path}{pid}Tex1.{print_id}.jpg'
|
||||
|
||||
prefix = f'objs/print/{pid}/'
|
||||
if config.oss_bucket.object_exists(f'{prefix}{pid}Tex1.{print_id}.jpg'):
|
||||
print(f'{pid}Tex1.{print_id}.jpg 处理中...')
|
||||
if not os.path.exists(texture_filename):
|
||||
os.makedirs(path, exist_ok=True)
|
||||
config.oss_bucket.get_object_to_file(f'{prefix}{pid}Tex1.{print_id}.jpg', texture_filename)
|
||||
main(pid, print_id)
|
||||
else:
|
||||
print(f'文件已存在,直接上传')
|
||||
config.oss_bucket.put_object_from_file(f'objs/print/{pid}/{pid}Tex1.{print_id}.jpg', texture_filename)
|
||||
|
||||
print(f'{pid}Tex1.{print_id}.jpg 处理完成')
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import win32gui, win32con, time, os, sys
|
||||
import pyautogui as ag
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
import config, libs
|
||||
|
||||
def find_and_maximize_window(window_title):
|
||||
windows = []
|
||||
win32gui.EnumWindows(lambda hwnd, windows: windows.append(hwnd), windows)
|
||||
|
||||
for hwnd in windows:
|
||||
if win32gui.IsWindowVisible(hwnd):
|
||||
if window_title in win32gui.GetWindowText(hwnd):
|
||||
print(f'found {window_title} hwnd:{hwnd}')
|
||||
# win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
|
||||
win32gui.SetForegroundWindow(hwnd)
|
||||
pid = win32gui.GetWindowText(hwnd).split('wait')[0].split(' ')[0].split('-')[0].split('*')[0]
|
||||
left, top, right, bottom = win32gui.GetWindowRect(hwnd)
|
||||
return pid, left, top, right, bottom
|
||||
return '0', 0, 0, 0, 0
|
||||
|
||||
def get_defineDistances(pid, left, top, right, bottom):
|
||||
psid = libs.getPSid(pid)
|
||||
distances = config.ps_floor_sticker.get(psid, config.ps_floor_sticker['default'])
|
||||
for index, d in enumerate(distances.split(';')):
|
||||
p1, p2, distance = d.split(' ')
|
||||
if index == 0:
|
||||
ag.moveTo(left + 80, top + 290)
|
||||
else:
|
||||
ag.moveTo(left + 80, top + 290 + 15) # Create distance line height 15
|
||||
ag.click()
|
||||
|
||||
ag.moveTo(left + 302, (bottom - 100)) # A point
|
||||
ag.click();repeat_backspace(20)
|
||||
ag.typewrite(p1)
|
||||
|
||||
ag.moveTo(left + 302, (bottom - 80)) # B point
|
||||
ag.click();repeat_backspace(20)
|
||||
ag.typewrite(p2)
|
||||
|
||||
ag.moveTo(left + 302, (bottom - 35)) # Definded distance
|
||||
ag.click();repeat_backspace(8)
|
||||
ag.typewrite(distance)
|
||||
ag.press('enter')
|
||||
|
||||
|
||||
def repeat_backspace(times):
|
||||
for i in range(times):
|
||||
ag.press('backspace')
|
||||
for i in range(times):
|
||||
ag.press('delete')
|
||||
|
||||
def defind_distance(pid, left, top, right, bottom):
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 开始定义定位点距离...')
|
||||
print(f'left: {left}, top: {top}, right: {right}, bottom: {bottom}')
|
||||
# ag.PAUSE = 1
|
||||
|
||||
ag.moveTo(left + 20, top + 200) # open Control points
|
||||
ag.click()
|
||||
|
||||
get_defineDistances(pid, left, top, right, bottom)
|
||||
|
||||
ag.hotkey('ctrl', 's') # save project
|
||||
ag.hotkey('alt', 'f4') # close project
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 定义定位点距离完成')
|
||||
time.sleep(3)
|
||||
|
||||
def main():
|
||||
while True:
|
||||
time.sleep(1)
|
||||
title = "wait"
|
||||
pid, left, top, right, bottom = find_and_maximize_window(title)
|
||||
if pid == '0':
|
||||
pass
|
||||
else:
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 找到{pid}的定位点距离定义窗口,开始定位点距离定义...')
|
||||
start_time = time.time()
|
||||
defind_distance(pid, left, top, right, bottom)
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 定位点距离定义完成,共费时{libs.diff_time(start_time)}')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,92 @@
|
||||
import os, sys, time, bpy, bmesh, shutil
|
||||
import platform
|
||||
if platform.system() == 'Windows':
|
||||
sys.path.append('e:\\libs\\')
|
||||
else:
|
||||
sys.path.append('/data/deploy/make3d/make2/libs/')
|
||||
|
||||
import config, libs, libs_db
|
||||
|
||||
def bmesh_copy_from_object(obj, transform=True, triangulate=True, apply_modifiers=False):
|
||||
"""Returns a transformed, triangulated copy of the mesh"""
|
||||
assert obj.type == 'MESH'
|
||||
if apply_modifiers and obj.modifiers:
|
||||
import bpy
|
||||
depsgraph = bpy.context.evaluated_depsgraph_get()
|
||||
obj_eval = obj.evaluated_get(depsgraph)
|
||||
me = obj_eval.to_mesh()
|
||||
bm = bmesh.new()
|
||||
bm.from_mesh(me)
|
||||
obj_eval.to_mesh_clear()
|
||||
else:
|
||||
me = obj.data
|
||||
if obj.mode == 'EDIT':
|
||||
bm_orig = bmesh.from_edit_mesh(me)
|
||||
bm = bm_orig.copy()
|
||||
else:
|
||||
bm = bmesh.new()
|
||||
bm.from_mesh(me)
|
||||
if transform:
|
||||
matrix = obj.matrix_world.copy()
|
||||
if not matrix.is_identity:
|
||||
bm.transform(matrix)
|
||||
matrix.translation.zero()
|
||||
if not matrix.is_identity:
|
||||
bm.normal_update()
|
||||
if triangulate:
|
||||
bmesh.ops.triangulate(bm, faces=bm.faces)
|
||||
return bm
|
||||
|
||||
def reload_obj(pid, action):
|
||||
obj_filename = os.path.join(config.workdir, action, pid, f'{pid}.obj')
|
||||
bpy.ops.wm.read_homefile()
|
||||
bpy.ops.object.delete(use_global=False, confirm=False)
|
||||
bpy.ops.import_scene.obj(filepath=obj_filename)
|
||||
bpy.context.scene.unit_settings.scale_length = 0.001
|
||||
bpy.context.scene.unit_settings.length_unit = 'CENTIMETERS'
|
||||
bpy.context.scene.unit_settings.mass_unit = 'GRAMS'
|
||||
|
||||
obj = bpy.context.selected_objects[0]
|
||||
bpy.context.view_layer.objects.active = obj
|
||||
obj.select_set(True)
|
||||
|
||||
return obj
|
||||
|
||||
def cal_weight(obj, size):
|
||||
# 统一缩放到9cm标准尺寸
|
||||
scale = size / obj.dimensions.z
|
||||
obj.scale = (scale, scale, scale)
|
||||
bpy.ops.object.transform_apply(scale=True)
|
||||
|
||||
# bpy.ops.wm.save_as_mainfile(filepath=os.path.join(config.workdir, action, pid, f'{pid}-{size/10}cm.blend'))
|
||||
model_info = {}
|
||||
bm = bmesh_copy_from_object(obj)
|
||||
model_info['volume'] = round(bm.calc_volume() / 1000)
|
||||
model_info['weight'] = round(model_info['volume'] * 1.226)
|
||||
print(f'{size/10}cm:体积 {model_info["volume"]}cm³, 克重 {model_info["weight"]}g')
|
||||
|
||||
def main(action, pid, sizes):
|
||||
libs.down_obj_from_oss(config.workdir, pid, action)
|
||||
obj = reload_obj(pid, action)
|
||||
|
||||
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
|
||||
print(f'模型{pid}的体积与克重估算信息:')
|
||||
for size in sizes:
|
||||
size = float(size)
|
||||
cal_weight(obj, size)
|
||||
|
||||
if __name__ == '__main__':
|
||||
sizes = (90, 120, 150, 180)
|
||||
|
||||
if len(sys.argv) == 3:
|
||||
action = sys.argv[1]
|
||||
pids = sys.argv[2].split(',')
|
||||
for pid in pids:
|
||||
main(action, pid, sizes)
|
||||
elif len(sys.argv) == 4:
|
||||
action = sys.argv[1]
|
||||
pids = sys.argv[2].split(',')
|
||||
sizes = sys.argv[3].split(',')
|
||||
for pid in pids:
|
||||
main(action, pid, sizes)
|
||||
print('Usage: python cal_weight.py <pids>')
|
||||
@@ -0,0 +1,82 @@
|
||||
import os, sys, datetime, subprocess, shlex, shutil, requests, time, json, oss2
|
||||
import platform
|
||||
if platform.system() == 'Windows':
|
||||
sys.path.append('e:\\libs\\')
|
||||
else:
|
||||
sys.path.append('/data/deploy/make3d/make2/libs/')
|
||||
|
||||
import config, libs, libs_db
|
||||
|
||||
def down_xmps_from_oss(psid):
|
||||
def need_down():
|
||||
filename = f'xmps/{psid}/{psid}.rcbox'
|
||||
if not config.oss_bucket.object_exists(filename):
|
||||
print(f'未找到{filename}, 请检查是否已经上传{psid}号影棚坐标文件')
|
||||
time.sleep(5)
|
||||
return False
|
||||
oss_file_last_modified = float(config.oss_bucket.get_object_meta(filename).last_modified)
|
||||
local_file = os.path.join(config_path, 'xmps', psid, f'{psid}.rcbox')
|
||||
if not os.path.exists(local_file):
|
||||
print(f'未找到{local_file}, 需要下载影棚坐标文件')
|
||||
os.makedirs(os.path.join(config_path, 'xmps', psid), exist_ok=True)
|
||||
config.oss_bucket.get_object_to_file(filename, local_file)
|
||||
return True
|
||||
local_file_last_modified = os.path.getmtime(local_file)
|
||||
if oss_file_last_modified > local_file_last_modified:
|
||||
print(f'本地{local_file}文件已过期, 需要下载影棚坐标文件')
|
||||
config.oss_bucket.get_object_to_file(filename, local_file)
|
||||
return True
|
||||
|
||||
if not need_down(): return
|
||||
|
||||
print('正在下载影棚坐标文件')
|
||||
dest_path = os.path.join(config_path, 'xmps', psid)
|
||||
|
||||
if os.path.exists(os.path.join(dest_path)):
|
||||
shutil.rmtree(os.path.join(dest_path), ignore_errors=True)
|
||||
|
||||
os.makedirs(os.path.join(dest_path, 'mesh'), exist_ok=True)
|
||||
os.makedirs(os.path.join(dest_path, 'texture'), exist_ok=True)
|
||||
|
||||
prefix = f'xmps/{psid}/mesh/'
|
||||
filelist = oss2.ObjectIteratorV2(config.oss_bucket, prefix=prefix)
|
||||
for file in filelist:
|
||||
if file.key.endswith('.xmp'):
|
||||
filename = file.key.split('/')[-1]
|
||||
print('正在下载:', file.key)
|
||||
config.oss_bucket.get_object_to_file(file.key, os.path.join(dest_path, 'mesh', filename))
|
||||
|
||||
prefix = f'xmps/{psid}/texture/'
|
||||
filelist = oss2.ObjectIteratorV2(config.oss_bucket, prefix=prefix)
|
||||
for file in filelist:
|
||||
if file.key.endswith('.xmp'):
|
||||
filename = file.key.split('/')[-1]
|
||||
print('正在下载:', file.key)
|
||||
config.oss_bucket.get_object_to_file(file.key, os.path.join(dest_path, 'texture', filename))
|
||||
|
||||
print('下载完成')
|
||||
|
||||
if __name__ == '__main__':
|
||||
start = datetime.datetime.now()
|
||||
if len(sys.argv) == 2:
|
||||
pids = sys.argv[1]
|
||||
else:
|
||||
print('usage: python downxmps.py [pids]')
|
||||
exit(1)
|
||||
|
||||
for pid in pids.split(','):
|
||||
input_path = os.path.join('d:\\', pid)
|
||||
ImagesGeometry = os.path.join(input_path, "photo1")
|
||||
ImagesTexture = os.path.join(input_path, "photo2")
|
||||
|
||||
psid = libs.getPSid(pid)
|
||||
config_path = f'D:\\apps\\config\\'
|
||||
xmps_mesh_path = config_path + f'xmps\\{psid}\\mesh\\'
|
||||
xmps_texture_path = config_path + f'xmps\\{psid}\\texture\\'
|
||||
|
||||
down_xmps_from_oss(psid)
|
||||
|
||||
os.system('xcopy /y /q ' + xmps_mesh_path + '*.* ' + ImagesGeometry)
|
||||
os.system('xcopy /y /q ' + xmps_texture_path + '*.* ' + ImagesTexture)
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
import os, sys, time, shutil, subprocess, shlex, json
|
||||
import platform
|
||||
if platform.system() == 'Windows':
|
||||
sys.path.append('e:\\libs\\')
|
||||
else:
|
||||
sys.path.append('/data/deploy/make3d/make2/libs/')
|
||||
|
||||
import config, libs, libs_db
|
||||
|
||||
def upload_xmp(pid):
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 上传xmp文件之前先删除oss上的xmp文件所在目录...')
|
||||
config.oss_bucket.delete_object(f'xmps/{pid}/')
|
||||
start_time = time.time()
|
||||
workdir = os.path.join(config.workdir, pid)
|
||||
psid = libs.getPSid(pid)
|
||||
config.oss_bucket.put_object_from_file(f'xmps/{psid}/{psid}.rcbox', os.path.join(workdir, f'{pid}.rcbox'))
|
||||
for xmp in os.listdir(os.path.join(workdir, 'photo1')):
|
||||
if xmp.endswith('.xmp'):
|
||||
config.oss_bucket.put_object_from_file(f'xmps/{psid}/mesh/{xmp}', os.path.join(workdir, 'photo1', xmp))
|
||||
for xmp in os.listdir(os.path.join(workdir, 'photo2')):
|
||||
if xmp.endswith('.xmp'):
|
||||
config.oss_bucket.put_object_from_file(f'xmps/{psid}/texture/{xmp}', os.path.join(workdir, 'photo2', xmp))
|
||||
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} xmp文件上传完成,共费时{time.time() - start_time}秒')
|
||||
|
||||
def main(pid):
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 开始计算相机位姿...')
|
||||
start_time = time.time()
|
||||
libs.down_from_oss(config.oss_bucket, config.workdir, pid)
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 图片下载完成,共费时{libs.diff_time(start_time)}')
|
||||
|
||||
start_time = time.time()
|
||||
photo1_path = os.path.join(config.workdir, pid, 'photo1')
|
||||
photo2_path = os.path.join(config.workdir, pid, 'photo2')
|
||||
photos1_count = len(os.listdir(photo1_path))
|
||||
photos2_count = len(os.listdir(photo2_path))
|
||||
if photos1_count + photos2_count < 164:
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} photo1数量{photos1_count} photo2数量{photos2_count},未能覆盖所有相机,是否继续计算相机位姿?')
|
||||
continue_or_not = input('是否继续计算相机位姿?(y/n)')
|
||||
if continue_or_not == 'y':
|
||||
pass
|
||||
else:
|
||||
sys.exit(0)
|
||||
|
||||
cmd = f'{config.rcbin} {config.r2["init"]} -setInstanceName {pid} \
|
||||
-save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" \
|
||||
-addFolder "{os.path.join(config.workdir, pid, "photo1")}" -selectAllImages \
|
||||
-detectMarkers "D:\\make2\\config\\detectMarkers.config.xml" \
|
||||
-align -align \
|
||||
-exportXMP "D:\\make2\\config\\exportXMP.config.xml" \
|
||||
-save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" -quit'
|
||||
print(cmd)
|
||||
cmd = shlex.split(cmd)
|
||||
res = subprocess.run(cmd)
|
||||
|
||||
# TODO:加入report相机位姿质量评估
|
||||
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} photo1相机位姿完成,共费时{libs.diff_time(start_time)}')
|
||||
|
||||
for xmp in os.listdir(photo1_path):
|
||||
if xmp.endswith('.xmp'):
|
||||
shutil.copy(os.path.join(photo1_path, xmp), os.path.join(photo2_path, xmp.replace('_1.xmp', '_8.xmp')))
|
||||
|
||||
psid = libs.getPSid(pid)
|
||||
cmd = f'{config.rcbin} {config.r2["init"]} -setInstanceName {pid} \
|
||||
-load "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" {config.r["setTextureFalse"]} \
|
||||
-addFolder "{os.path.join(config.workdir, pid, "photo2")}" -selectAllImages \
|
||||
-detectMarkers "D:\\make2\\config\\detectMarkers.config.xml" \
|
||||
{libs.get_defineDistances(config.ps_floor_sticker.get(psid, config.ps_floor_sticker["default"]))} -align -align -update {config.r2["setRegion"]} \
|
||||
-exportXMP "D:\\make2\\config\\exportXMP.config.xml" \
|
||||
-exportReconstructionRegion "{os.path.join(config.workdir, pid, f"{pid}.rcbox")}" \
|
||||
-save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" -quit'
|
||||
print(cmd)
|
||||
cmd = shlex.split(cmd)
|
||||
res = subprocess.run(cmd)
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} photo2相机位姿完成,共费时{libs.diff_time(start_time)}')
|
||||
|
||||
# TODO:加入report相机位姿质量评估
|
||||
upload_or_not = input('是否上传oss?(y/n)')
|
||||
if upload_or_not == 'y':
|
||||
upload_xmp(pid)
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} xmp文件上传完成,共费时{libs.diff_time(start_time)}')
|
||||
|
||||
delete_or_not = input('是否删除本地文件?(y/n)')
|
||||
if delete_or_not == 'y':
|
||||
shutil.rmtree(os.path.join(config.workdir, pid))
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 本地文件已删除')
|
||||
else:
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 本地文件未删除')
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) == 2:
|
||||
pids = sys.argv[1].split(',')
|
||||
for pid in pids:
|
||||
main(pid)
|
||||
else:
|
||||
print(f'useage: python {sys.argv[0]} pid1,pid2,pid3')
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,37 @@
|
||||
import redis, os, sys
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
import config, libs
|
||||
|
||||
def main(cmd, order_id):
|
||||
if cmd == 'print':
|
||||
key = 'model:printOrder'
|
||||
elif cmd == 'repair':
|
||||
key = 'model:IndependentRepairTeamcheckGLBQueue'
|
||||
elif cmd == 'make3d':
|
||||
key = 'model:make'
|
||||
elif cmd == 'make3d10':
|
||||
key = 'model:make10'
|
||||
elif cmd == 'foot':
|
||||
key = 'model:foot'
|
||||
|
||||
if order_id == 'view':
|
||||
for i in r.lrange(key, 0, -1):
|
||||
print(i)
|
||||
print(f'当前{key}队列长度:{r.llen(key)}')
|
||||
else:
|
||||
order_ids = order_id.split(',')
|
||||
for order_id in order_ids:
|
||||
r.lpush(key, order_id)
|
||||
print(f'已推送{order_id}到{key}, 当前队列长度:{r.llen(key)}')
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) == 3:
|
||||
cmd = sys.argv[1]
|
||||
order_id = sys.argv[2]
|
||||
else:
|
||||
print('用法:python push_cmd.py <cmd> <order_id>')
|
||||
exit(1)
|
||||
|
||||
r = config.redis_local
|
||||
|
||||
main(cmd, order_id)
|
||||
@@ -0,0 +1,56 @@
|
||||
import os, sys, bpy, time
|
||||
import platform
|
||||
if platform.system() == 'Windows':
|
||||
sys.path.append('e:\\libs\\')
|
||||
else:
|
||||
sys.path.append('/data/deploy/make3d/make2/libs/')
|
||||
|
||||
import config, libs, libs_db
|
||||
|
||||
def upload_3d(pid):
|
||||
start_time = time.time()
|
||||
workdir = os.path.join(config.workdir, '3d')
|
||||
|
||||
glb_filename = os.path.join(workdir, pid, f'{pid}_decimate.glb')
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {glb_filename} 开始处理...')
|
||||
if os.path.exists(glb_filename):
|
||||
config.oss_bucket.put_object_from_file(f'glbs/3d/{pid}.glb', glb_filename)
|
||||
# break
|
||||
os.remove(glb_filename)
|
||||
else:
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {glb_filename} 文件不存在,跳过')
|
||||
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} glb文件上传完成,共费时{time.time() - start_time}秒')
|
||||
|
||||
def upload_xmp(pid):
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 上传xmp文件之前先删除oss上的xmp文件所在目录...')
|
||||
config.oss_bucket.delete_object(f'xmps/{pid}/')
|
||||
start_time = time.time()
|
||||
workdir = os.path.join(config.workdir, pid)
|
||||
psid = libs.getPSid(pid)
|
||||
config.oss_bucket.put_object_from_file(f'xmps/{psid}/{psid}.rcbox', os.path.join(workdir, f'{pid}.rcbox'))
|
||||
for xmp in os.listdir(os.path.join(workdir, 'photo1')):
|
||||
if xmp.endswith('.xmp'):
|
||||
config.oss_bucket.put_object_from_file(f'xmps/{psid}/mesh/{xmp}', os.path.join(workdir, 'photo1', xmp))
|
||||
for xmp in os.listdir(os.path.join(workdir, 'photo2')):
|
||||
if xmp.endswith('.xmp'):
|
||||
config.oss_bucket.put_object_from_file(f'xmps/{psid}/texture/{xmp}', os.path.join(workdir, 'photo2', xmp))
|
||||
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} xmp文件上传完成,共费时{time.time() - start_time}秒')
|
||||
|
||||
def main():
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) == 3:
|
||||
action = sys.argv[1]
|
||||
pids = sys.argv[2]
|
||||
else:
|
||||
print(f'useage: python {sys.argv[0]} [3d|xmp] pid1,pid2,pid3')
|
||||
sys.exit(1)
|
||||
|
||||
for pid in pids.split(','):
|
||||
if action == '3d':
|
||||
upload_3d(pid)
|
||||
elif action == 'xmp':
|
||||
upload_xmp(pid)
|
||||
Reference in new issue
Block a user