111
This commit is contained in:
1 parent
2951906785
commit
9297d3c0f1
11 files changed
+225
-30
No files matched your search
Binary file not shown.
+16
-11
@@ -3,6 +3,7 @@ import os, oss2, time, redis, requests, shutil, sys, subprocess, json, platform
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from retrying import retry
|
||||
import atexit,platform
|
||||
import white_purification
|
||||
if platform.system() == 'Windows':
|
||||
sys.path.append('e:\\libs\\')
|
||||
import common
|
||||
@@ -42,6 +43,8 @@ def down_obj_fromoss(pid,order_id):
|
||||
prefix = f'objs/print/{pid}/'
|
||||
if ossPath != "":
|
||||
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("\\","/")
|
||||
|
||||
print(f'prefix:{prefix}')
|
||||
@@ -109,6 +112,8 @@ def team_check(r):
|
||||
if repair_id is None: return
|
||||
repair_id = repair_id.decode('utf-8')
|
||||
|
||||
# repair_id = 62922
|
||||
|
||||
res = requests.get(f'{getRepairInfo_url}?id={repair_id}')
|
||||
print(f'getRepairInfo_url:{getRepairInfo_url}?id={repair_id}')
|
||||
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', )
|
||||
ossPath = down_obj_fromoss(pid,orderId)
|
||||
# if ossPath == "":
|
||||
# print("ossPath is null")
|
||||
# return
|
||||
#对文件进行白色提纯处理
|
||||
imagePath = os.path.join(workdir, 'print', pid,pid+"Tex1.jpg")
|
||||
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'
|
||||
glb_filename = f'{orderId}.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')
|
||||
|
||||
|
||||
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/{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))
|
||||
|
||||
print(f'{update_repair_status_url}?id={repair_id}')
|
||||
res = requests.get(f'{update_repair_status_url}?id={repair_id}')
|
||||
|
||||
+35
-18
@@ -20,9 +20,9 @@ def find_blender_bin_path():
|
||||
exit(1)
|
||||
|
||||
@retry(stop_max_attempt_number=10, wait_fixed=3000)
|
||||
def down_obj_fromoss(pid):
|
||||
def down_obj_fromoss(pid,orderId):
|
||||
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)
|
||||
# 根据前缀获取文件列表
|
||||
prefix = f'objs/print/{pid}/base/fridge'
|
||||
@@ -33,17 +33,17 @@ def down_obj_fromoss(pid):
|
||||
for file in filelist:
|
||||
filename = file.key.split('/')[-1]
|
||||
if filename == '': continue
|
||||
if filename.endswith(f'.obj') and find == True:
|
||||
continue
|
||||
# if filename.endswith(f'.obj') and find == True:
|
||||
# continue
|
||||
|
||||
if filename.endswith(f'{pid}.obj'):
|
||||
find = True
|
||||
# if filename.endswith(f'{pid}.obj'):
|
||||
# find = True
|
||||
localfile = os.path.join(path, filename)
|
||||
res = oss_client.get_object_to_file(file.key, localfile)
|
||||
print(f'下载文件:{file.key},状态:{res.status}')
|
||||
if not find:
|
||||
print('找不到obj文件,异常退出')
|
||||
sys.exit(1)
|
||||
# if not find:
|
||||
# print('找不到obj文件,异常退出')
|
||||
# sys.exit(1)
|
||||
return
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ def down_obj_fromoss(pid):
|
||||
|
||||
def team_check(r):
|
||||
try:
|
||||
if r.llen('glb:flat_fridge_repair_order') == 0:
|
||||
if r.llen('glb:flat_fridge') == 0:
|
||||
time.sleep(5)
|
||||
return
|
||||
except Exception as e:
|
||||
@@ -62,19 +62,34 @@ def team_check(r):
|
||||
time.sleep(5)
|
||||
r = create_redis_connection()
|
||||
return
|
||||
pid = r.lpop('glb:flat_fridge_repair_order')
|
||||
if pid is None: return
|
||||
pid = pid.decode('utf-8')
|
||||
repair_id = r.lpop('glb:flat_fridge')
|
||||
if repair_id is None: return
|
||||
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'
|
||||
glb_filename = f'{pid}.glb'
|
||||
glb_filename = f'{orderId}.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
|
||||
oss_client.put_object_from_file(f'glbs/print/flat_fridge/{glb_filename}', os.path.join(workdir, "print", pid, glb_filename))
|
||||
shutil.rmtree(os.path.join(workdir, 'print', pid), ignore_errors=True)
|
||||
oss_client.put_object_from_file(f'glbs/print/flat_fridge/order_id/{glb_filename}', os.path.join(workdir, "print", pid,orderId, glb_filename))
|
||||
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')
|
||||
|
||||
def create_redis_connection():
|
||||
@@ -109,6 +124,8 @@ if __name__ == '__main__':
|
||||
Endpoint = 'oss-cn-shanghai.aliyuncs.com'
|
||||
Bucket = 'suwa3d-securedata'
|
||||
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':
|
||||
workdir = 'D:\\'
|
||||
else:
|
||||
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user