Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -307,11 +307,6 @@ def merge_images_in_2_folder(folder1, folder2, outdir, suffix_need_remove = None
|
|
| 307 |
result = merge_2_images(img1, img2, mode, erosion_para, dilate)
|
| 308 |
cv2.imwrite(os.path.join(outdir, filename + extensions_folder1[index]), result)
|
| 309 |
|
| 310 |
-
def process_line(img_path = './input', outdir = './output'):
|
| 311 |
-
depth_anything(img_path, os.path.join(outdir,"depth_anything"))
|
| 312 |
-
teed_imgs(img_path, os.path.join(outdir,"teed_imgs"), [1,7,2])
|
| 313 |
-
teed_imgs(os.path.join(outdir,"depth_anything"), os.path.join(outdir,"dp_teed_imgs"), [0,7,2])
|
| 314 |
-
merge_images_in_2_folder(os.path.join(outdir,"teed_imgs"), os.path.join(outdir,"dp_teed_imgs"), os.path.join(outdir,"merged_imgs"),'_depth', 1, 'multiply', [[2,0],[2,1]],[1,0])
|
| 315 |
|
| 316 |
def invert_image(image):
|
| 317 |
# 将图片从BGR转为灰度图
|
|
@@ -350,28 +345,28 @@ def process_images(input_folder='./output/merged_imgs'):
|
|
| 350 |
def process_line(img, outdir='./output'):
|
| 351 |
img_path = "./input"
|
| 352 |
|
| 353 |
-
#
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
# 确保输出目录存在
|
| 357 |
-
os.makedirs(outdir, exist_ok=True)
|
| 358 |
-
|
| 359 |
-
try:
|
| 360 |
-
depth_anything(img_path, os.path.join(outdir, "depth_anything"))
|
| 361 |
-
teed_imgs(img_path, os.path.join(outdir, "teed_imgs"), [1, 7, 2])
|
| 362 |
-
teed_imgs(os.path.join(outdir, "depth_anything"), os.path.join(outdir, "dp_teed_imgs"), [0, 7, 2])
|
| 363 |
-
merge_images_in_2_folder(os.path.join(outdir, "teed_imgs"),
|
| 364 |
-
os.path.join(outdir, "dp_teed_imgs"),
|
| 365 |
-
os.path.join(outdir, "merged_imgs"),
|
| 366 |
-
'_depth', 1, 'multiply', [[2, 0], [2, 1]], [1, 0])
|
| 367 |
|
| 368 |
-
#
|
| 369 |
-
|
| 370 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
|
| 372 |
-
except Exception as e:
|
| 373 |
-
print(f"Error processing the image: {e}")
|
| 374 |
-
return None
|
| 375 |
|
| 376 |
|
| 377 |
if __name__ == '__main__':
|
|
|
|
| 307 |
result = merge_2_images(img1, img2, mode, erosion_para, dilate)
|
| 308 |
cv2.imwrite(os.path.join(outdir, filename + extensions_folder1[index]), result)
|
| 309 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
|
| 311 |
def invert_image(image):
|
| 312 |
# 将图片从BGR转为灰度图
|
|
|
|
| 345 |
def process_line(img, outdir='./output'):
|
| 346 |
img_path = "./input"
|
| 347 |
|
| 348 |
+
# 确保 img 是一个有效的 NumPy 数组
|
| 349 |
+
if isinstance(img, np.ndarray):
|
| 350 |
+
print(f"Image type: {type(img)}, shape: {img.shape}, dtype: {img.dtype}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
|
| 352 |
+
# 确保图像是 uint8 类型
|
| 353 |
+
img = img.astype(np.uint8)
|
| 354 |
+
|
| 355 |
+
# 保存上传的图像
|
| 356 |
+
cv2.imwrite(os.path.join(img_path, "input_image.png"), img)
|
| 357 |
+
else:
|
| 358 |
+
raise ValueError("Input img is not a valid NumPy array")
|
| 359 |
+
|
| 360 |
+
# 继续处理
|
| 361 |
+
depth_anything(img_path, os.path.join(outdir, "depth_anything"))
|
| 362 |
+
teed_imgs(img_path, os.path.join(outdir, "teed_imgs"), [1, 7, 2])
|
| 363 |
+
teed_imgs(os.path.join(outdir, "depth_anything"), os.path.join(outdir, "dp_teed_imgs"), [0, 7, 2])
|
| 364 |
+
merge_images_in_2_folder(os.path.join(outdir, "teed_imgs"), os.path.join(outdir, "dp_teed_imgs"), os.path.join(outdir, "merged_imgs"), '_depth', 1, 'multiply', [[2, 0], [2, 1]], [1, 0])
|
| 365 |
+
|
| 366 |
+
# 返回处理后的最后一张图像
|
| 367 |
+
result_img_path = os.path.join(outdir, "merged_imgs", "your_final_image_name.png") # 修改为你的输出图像路径
|
| 368 |
+
return Image.open(result_img_path)
|
| 369 |
|
|
|
|
|
|
|
|
|
|
| 370 |
|
| 371 |
|
| 372 |
if __name__ == '__main__':
|