Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -307,6 +307,11 @@ 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 |
|
| 311 |
def invert_image(image):
|
| 312 |
# 将图片从BGR转为灰度图
|
|
@@ -342,40 +347,12 @@ def process_images(input_folder='./output/merged_imgs'):
|
|
| 342 |
except Exception as e:
|
| 343 |
print(f"Error processing file {image_file}: {e}")
|
| 344 |
|
| 345 |
-
def process_line(
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
# 检查输入是否为字符串路径
|
| 349 |
-
if isinstance(img, str):
|
| 350 |
-
# 打印尝试读取的路径
|
| 351 |
-
print(f"Trying to read image from: {img}")
|
| 352 |
-
|
| 353 |
-
# 检查文件是否存在
|
| 354 |
-
if not os.path.isfile(img):
|
| 355 |
-
raise ValueError(f"The file {img} does not exist.")
|
| 356 |
-
|
| 357 |
-
img = cv2.imread(img) # 读取图像文件
|
| 358 |
-
if img is None:
|
| 359 |
-
raise ValueError("Failed to read the image. Check the file path.")
|
| 360 |
-
elif isinstance(img, np.ndarray):
|
| 361 |
-
img = img.astype(np.uint8) # 转换为 uint8
|
| 362 |
-
else:
|
| 363 |
-
raise ValueError("Input img is not a valid NumPy array")
|
| 364 |
-
|
| 365 |
-
# 创建输入目录
|
| 366 |
-
os.makedirs("./input", exist_ok=True)
|
| 367 |
-
# 保存上传的图像
|
| 368 |
-
cv2.imwrite(os.path.join("./input", "input_image.png"), img)
|
| 369 |
-
|
| 370 |
-
# 继续处理
|
| 371 |
-
depth_anything("./input", os.path.join(outdir, "depth_anything"))
|
| 372 |
-
teed_imgs("./input", os.path.join(outdir, "teed_imgs"), [1, 7, 2])
|
| 373 |
teed_imgs(os.path.join(outdir, "depth_anything"), os.path.join(outdir, "dp_teed_imgs"), [0, 7, 2])
|
| 374 |
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])
|
| 375 |
-
|
| 376 |
-
# 返回处理后的最后一张图像
|
| 377 |
-
result_img_path = os.path.join(outdir, "merged_imgs", "your_final_image_name.png") # 修改为你的输出图像路径
|
| 378 |
-
return Image.open(result_img_path)
|
| 379 |
|
| 380 |
|
| 381 |
|
|
|
|
| 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转为灰度图
|
|
|
|
| 347 |
except Exception as e:
|
| 348 |
print(f"Error processing file {image_file}: {e}")
|
| 349 |
|
| 350 |
+
def process_line(img_path='./input', outdir='./output'):
|
| 351 |
+
depth_anything(img_path, os.path.join(outdir, "depth_anything"))
|
| 352 |
+
teed_imgs(img_path, os.path.join(outdir, "teed_imgs"), [1, 7, 2])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
teed_imgs(os.path.join(outdir, "depth_anything"), os.path.join(outdir, "dp_teed_imgs"), [0, 7, 2])
|
| 354 |
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])
|
| 355 |
+
process_images(os.path.join(outdir, "merged_imgs")) # 处理merged_imgs文件夹中的图片
|
|
|
|
|
|
|
|
|
|
| 356 |
|
| 357 |
|
| 358 |
|