dongchangxi 8 months ago
parent
commit
9297d3c0f1
  1. 5
      .gitignore
  2. BIN
      apps/__pycache__/white_purification.cpython-310.pyc
  3. 27
      apps/auto_convert3d_new.py
  4. 53
      apps/flat_fridge_glb.py
  5. 138
      apps/white_purification.py
  6. BIN
      new_studio_to_reg/__pycache__/tools_to_xmps.cpython-310.pyc
  7. BIN
      timer/27.zip
  8. BIN
      timer/31.zip
  9. 31
      timer/external_order_glb.py
  10. 1
      tools/100.txt
  11. BIN
      tools/weights.xlsx

5
.gitignore vendored

@ -10,3 +10,8 @@ yj_local_build/build/main_step1/main_step1.exe
new_studio_to_reg/__pycache__ new_studio_to_reg/__pycache__
new_studio_to_reg/__pycache__/tools_to_xmps.cpython-310.pyc new_studio_to_reg/__pycache__/tools_to_xmps.cpython-310.pyc
new_studio_to_reg/__pycache__/tools_to_xmps.cpython-310.pyc new_studio_to_reg/__pycache__/tools_to_xmps.cpython-310.pyc
new_studio_to_reg/__pycache__/tools_to_xmps.cpython-310.pyc
test/test1.py
timer/29.zip
yj_local_build/main_step1.spec
yj_local_build/建模source_code.zip

BIN
apps/__pycache__/white_purification.cpython-310.pyc

Binary file not shown.

27
apps/auto_convert3d_new.py

@ -3,6 +3,7 @@ import os, oss2, time, redis, requests, shutil, sys, subprocess, json, platform
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont
from retrying import retry from retrying import retry
import atexit,platform import atexit,platform
import white_purification
if platform.system() == 'Windows': if platform.system() == 'Windows':
sys.path.append('e:\\libs\\') sys.path.append('e:\\libs\\')
import common import common
@ -42,6 +43,8 @@ def down_obj_fromoss(pid,order_id):
prefix = f'objs/print/{pid}/' prefix = f'objs/print/{pid}/'
if ossPath != "": if ossPath != "":
prefix = os.path.join("objs","print",pid,ossPath,order_id) prefix = os.path.join("objs","print",pid,ossPath,order_id)
if "base/" in ossPath:
prefix = os.path.join("objs","print",pid,ossPath)
prefix = prefix.replace("\\","/") prefix = prefix.replace("\\","/")
print(f'prefix:{prefix}') print(f'prefix:{prefix}')
@ -109,6 +112,8 @@ def team_check(r):
if repair_id is None: return if repair_id is None: return
repair_id = repair_id.decode('utf-8') repair_id = repair_id.decode('utf-8')
# repair_id = 62922
res = requests.get(f'{getRepairInfo_url}?id={repair_id}') res = requests.get(f'{getRepairInfo_url}?id={repair_id}')
print(f'getRepairInfo_url:{getRepairInfo_url}?id={repair_id}') print(f'getRepairInfo_url:{getRepairInfo_url}?id={repair_id}')
print(res.text) print(res.text)
@ -119,9 +124,16 @@ def team_check(r):
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), f'pid:{pid} repair_id:{repair_id} 生成团队审核模型 start model:IndependentRepairTeamcheckGLBQueue', ) print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), f'pid:{pid} repair_id:{repair_id} 生成团队审核模型 start model:IndependentRepairTeamcheckGLBQueue', )
ossPath = down_obj_fromoss(pid,orderId) ossPath = down_obj_fromoss(pid,orderId)
# if ossPath == "": #对文件进行白色提纯处理
# print("ossPath is null") imagePath = os.path.join(workdir, 'print', pid,pid+"Tex1.jpg")
# return print("开始处理白色提纯")
white_purification.white_purification_utils(imagePath)
print("贴图文件白色提纯完成",imagePath)
#提纯完重新上传提纯图片
ossImagePath = os.path.join("objs/print", pid,ossPath,"texture","process_"+pid+"Tex1.jpg")
oss_client.put_object_from_file(f"objs/print/{pid}/{ossPath}/texture/process_{pid}Tex1.jpg",imagePath)
print("白色提纯上传图片路径-",ossImagePath,imagePath)
obj_filename = f'{pid}.obj' obj_filename = f'{pid}.obj'
glb_filename = f'{orderId}.glb' glb_filename = f'{orderId}.glb'
print('开始转换obj文件为glb文件...') print('开始转换obj文件为glb文件...')
@ -141,15 +153,8 @@ def team_check(r):
config.oss_bucket_3d_view.put_object_from_file(f'{uuid}/3d_view.png', f'D://print/{pid}/{pid}_pic.png') config.oss_bucket_3d_view.put_object_from_file(f'{uuid}/3d_view.png', f'D://print/{pid}/{pid}_pic.png')
if ossPath == "model/smsize":
ossPath = "smsize"
if ossPath == "model/standard_size":
ossPath = "normal"
print('上传glb文件到oss...',f'glbs/print/{ossPath}/{glb_filename}',os.path.join(workdir, "print", pid, glb_filename)) oss_client.put_object_from_file(f'glbs/print/order_id/{glb_filename}', os.path.join(workdir, "print", pid, glb_filename))
oss_client.put_object_from_file(f'glbs/print/{ossPath}/{glb_filename}', os.path.join(workdir, "print", pid, glb_filename))
print(f'{update_repair_status_url}?id={repair_id}') print(f'{update_repair_status_url}?id={repair_id}')
res = requests.get(f'{update_repair_status_url}?id={repair_id}') res = requests.get(f'{update_repair_status_url}?id={repair_id}')

53
apps/flat_fridge_glb.py

@ -20,9 +20,9 @@ def find_blender_bin_path():
exit(1) exit(1)
@retry(stop_max_attempt_number=10, wait_fixed=3000) @retry(stop_max_attempt_number=10, wait_fixed=3000)
def down_obj_fromoss(pid): def down_obj_fromoss(pid,orderId):
print('开始下载obj文件...' , pid) print('开始下载obj文件...' , pid)
path = os.path.join(workdir, 'print', pid) path = os.path.join(workdir, 'print', pid,orderId)
if not os.path.exists(path): os.makedirs(path) if not os.path.exists(path): os.makedirs(path)
# 根据前缀获取文件列表 # 根据前缀获取文件列表
prefix = f'objs/print/{pid}/base/fridge' prefix = f'objs/print/{pid}/base/fridge'
@ -33,17 +33,17 @@ def down_obj_fromoss(pid):
for file in filelist: for file in filelist:
filename = file.key.split('/')[-1] filename = file.key.split('/')[-1]
if filename == '': continue if filename == '': continue
if filename.endswith(f'.obj') and find == True: # if filename.endswith(f'.obj') and find == True:
continue # continue
if filename.endswith(f'{pid}.obj'): # if filename.endswith(f'{pid}.obj'):
find = True # find = True
localfile = os.path.join(path, filename) localfile = os.path.join(path, filename)
res = oss_client.get_object_to_file(file.key, localfile) res = oss_client.get_object_to_file(file.key, localfile)
print(f'下载文件:{file.key},状态:{res.status}') print(f'下载文件:{file.key},状态:{res.status}')
if not find: # if not find:
print('找不到obj文件,异常退出') # print('找不到obj文件,异常退出')
sys.exit(1) # sys.exit(1)
return return
@ -53,7 +53,7 @@ def down_obj_fromoss(pid):
def team_check(r): def team_check(r):
try: try:
if r.llen('glb:flat_fridge_repair_order') == 0: if r.llen('glb:flat_fridge') == 0:
time.sleep(5) time.sleep(5)
return return
except Exception as e: except Exception as e:
@ -62,19 +62,34 @@ def team_check(r):
time.sleep(5) time.sleep(5)
r = create_redis_connection() r = create_redis_connection()
return return
pid = r.lpop('glb:flat_fridge_repair_order') repair_id = r.lpop('glb:flat_fridge')
if pid is None: return if repair_id is None: return
pid = pid.decode('utf-8') repair_id = repair_id.decode('utf-8')
res = requests.get(f'{getRepairInfo_url}?id={repair_id}')
print(f'getRepairInfo_url:{getRepairInfo_url}?id={repair_id}')
print(res.text)
pid = res.json()['data']['pid']
orderId = res.json()['data']['order_id']
pid = str(pid)
orderId = str(orderId)
#下载数据 #下载数据
down_obj_fromoss(pid) down_obj_fromoss(pid,orderId)
obj_filename = f'{pid}.obj' obj_filename = f'{pid}.obj'
glb_filename = f'{pid}.glb' glb_filename = f'{orderId}.glb'
print('开始转换obj文件为glb文件...') print('开始转换obj文件为glb文件...')
os.system(f'gltfpack -c -i {os.path.join(workdir, "print", pid, obj_filename)} -o {os.path.join(workdir, "print", pid, glb_filename)} -vt 16 -vc 16') os.system(f'gltfpack -c -i {os.path.join(workdir, "print", pid,orderId, obj_filename)} -o {os.path.join(workdir, "print", pid,orderId, glb_filename)} -vt 16 -vc 16')
#上传glb文件到oss #上传glb文件到oss
oss_client.put_object_from_file(f'glbs/print/flat_fridge/{glb_filename}', os.path.join(workdir, "print", pid, glb_filename)) oss_client.put_object_from_file(f'glbs/print/flat_fridge/order_id/{glb_filename}', os.path.join(workdir, "print", pid,orderId, glb_filename))
shutil.rmtree(os.path.join(workdir, 'print', pid), ignore_errors=True) print(f'{update_repair_status_url}?id={repair_id}')
res = requests.get(f'{update_repair_status_url}?id={repair_id}')
print('更新团队审核状态:', res.text)
# shutil.rmtree(os.path.join(workdir, 'print', pid), ignore_errors=True)
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), f'pid:{pid} 生成团队审核模型 end')
# shutil.rmtree(os.path.join(workdir, 'print', pid), ignore_errors=True)
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), f'pid:{pid} 压平冰箱贴的glb已生成 end') print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), f'pid:{pid} 压平冰箱贴的glb已生成 end')
def create_redis_connection(): def create_redis_connection():
@ -109,6 +124,8 @@ if __name__ == '__main__':
Endpoint = 'oss-cn-shanghai.aliyuncs.com' Endpoint = 'oss-cn-shanghai.aliyuncs.com'
Bucket = 'suwa3d-securedata' Bucket = 'suwa3d-securedata'
oss_client = oss2.Bucket(oss2.Auth(AccessKeyId, AccessKeySecret), Endpoint, Bucket) oss_client = oss2.Bucket(oss2.Auth(AccessKeyId, AccessKeySecret), Endpoint, Bucket)
getRepairInfo_url = 'https://repair.api.suwa3d.com/api/modelRepairOrder/teamCheckGLBInfo'
update_repair_status_url = 'https://repair.api.suwa3d.com/api/modelRepairOrder/updateStatusToWaitingTeamCheckingStatus'
if platform.system() == 'Windows': if platform.system() == 'Windows':
workdir = 'D:\\' workdir = 'D:\\'
else: else:

138
apps/white_purification.py

@ -0,0 +1,138 @@
import argparse
import cv2
import numpy as np
def find_last_x(image, slope_threshold = 1000):
x,y = [],[]
hist, bins = np.histogram(image, bins=256, range=[0, 256])
#找到50以内的最高峰
max_y , max_i = 0, 5
for i in range(5, 25):
if hist[i] > max_y:
max_y = hist[i]
max_i = i
print(f'50以内最高峰值y:{max_y},最高峰位置x:{max_i}')
for i in range(2, max_i):
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 find_last_high(image, slope_threshold = 2500):
x = []
y = []
hist, bins = np.histogram(image, bins=255, range=[2, 255])
#找到200以上的最高峰
max_y = 0
max_i = 254
for i in range(220, 255):
if hist[i] > max_y:
max_y = hist[i]
max_i = i
print(f'200以上的最高峰值y:{max_y},最高峰位置x:{max_i}')
for i in range(max_i, 255):
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 = {}
find = False
for i in range(len(slopes) - 1, -1, -1):
slope = slopes[i]
current_interval.append(slope)
if slope >= slope_threshold:
find = True
if len(current_interval) > len(max_interval):
max_interval = current_interval.copy()
max_x[x[i]] = slope
current_interval = []
#如果没有找到200以上很平,而且高度小于5000,就按220位置削平
if not find and hist[220] < 5000:
max_x[220] = hist[220]
print(max_x)
if len(max_x) > 0:
last_x = list(max_x)[0]
last_y = max_x[last_x]
else:
print(f'找不到200以上曲线较平的区间,使用254作为最高峰')
last_x = 254
last_y = hist[254]
return last_x, last_y
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 white_purification_utils(image_path):
input_image = cv2.imread(image_path)
# 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)
# high_x_thresh, high_y_frequency = high_find_histogram_range(input_image, high_y_limit)
high_x_thresh, high_y_frequency = find_last_high(input_image)
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)
file_extension = image_path.lower().split('.')[-1]
if file_extension == 'png':
cv2.imwrite(image_path, high_output_image) # PNG格式无需压缩参数
else:
# cv2.imwrite(image_path.replace(".jpg", '_white.jpg'), high_output_image, [cv2.IMWRITE_JPEG_QUALITY, 95]) # 保存图片的质量是原图的 95%
cv2.imwrite(image_path, high_output_image, [cv2.IMWRITE_JPEG_QUALITY, 95]) # 保存图片的质量是原图的 95%
# if __name__ == "__main__":
# parser = argparse.ArgumentParser()
# parser.add_argument("-i","--image_path", type=str, default="")
# args = parser.parse_args()
# white_purification_utils(args.image_path)

BIN
new_studio_to_reg/__pycache__/tools_to_xmps.cpython-310.pyc

Binary file not shown.

BIN
timer/27.zip

Binary file not shown.

BIN
timer/31.zip

Binary file not shown.

31
timer/external_order_glb.py

@ -1,4 +1,4 @@
import os, sys, time, bpy, math, requests, bmesh, json, shutil import os, sys, time, bpy, math, requests, bmesh, json, shutil,oss2
from PIL import Image from PIL import Image
import platform,redis import platform,redis
if platform.system() == 'Windows': if platform.system() == 'Windows':
@ -44,6 +44,35 @@ def find_pid_objname(pid):
return obj.name return obj.name
def down_obj_from_oss(workdir, pid, action):
if os.path.exists(os.path.join(workdir, action, pid)):
print(f'目录{os.path.join(workdir, action, pid)}已存在,跳过')
return
else:
os.makedirs(os.path.join(workdir, action, pid))
# 根据前缀获取文件列表
prefix = f'objs/print/{pid}/base/model/'
filelist = oss2.ObjectIteratorV2(config.oss_bucket, prefix=prefix)
print('正在下载:', prefix)
obj_filename = ""
for file in filelist:
filename = file.key.split('/')[-1]
if filename.endswith(".exr"):
continue
if filename.endswith("_1.jpg") or filename.endswith("_8.jpg"):
continue
if filename.endswith('.obj'):
obj_filename = filename
# print('正在下载:', file.key)
localfile = os.path.join(workdir, action, pid, filename)
config.oss_bucket.get_object_to_file(file.key, localfile)
return obj_filename
#加载obj文件 #加载obj文件
def reload_obj(pid): def reload_obj(pid):

1
tools/100.txt

@ -0,0 +1 @@
235777,235759,235272,235022,234683,234678,233973,233634,233618,233589,233588,233106,232673,231611,231604,231394,231306,231061,230812,230528,230523,230513,230329,230328,230327,230325,230272,230268,230259,229967,229935,229634,229380,229309,229308,229202,228698,228693,228515,227743,227740,227647,227372,227357,227295,227103,227026,226503,226502,226280,226137,225927,225438,225077,225059,224944,224898,224894,224493,224237,224229,224136,224131,223288,223139,223137,222902,222897,222636,222516,222507,222488,222467,222278,222251,222248,222232,222196,221876,221679,221672,221462,221461,221460,221448,220781,220748,218310,217964,217050,216319,216311,215959,215488,215477,215466,214955,214951,214729,214726

BIN
tools/weights.xlsx

Binary file not shown.
Loading…
Cancel
Save