回答編集履歴

1

d

2020/01/23 14:41

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -18,25 +18,27 @@
18
18
 
19
19
  def File_open():
20
20
 
21
- img_path = tkdialog.askopenfilename(filetypes=[(".png", "*.png")], initialdir=dir)
21
+ paths = tkdialog.askopenfilenames(filetypes=[(".png", "*.png")], initialdir=dir)
22
22
 
23
- if not img_path:
23
+ for img_path in paths:
24
24
 
25
- return # ファイルを選択しなかった場合
25
+ img = cv2.imread(img_path)
26
26
 
27
- base_path, ext = os.path.splitext(img_path)
27
+ if img is None:
28
28
 
29
+ continue # 読み込みに失敗した場合
30
+
31
+ base_path, ext = os.path.splitext(img_path)
32
+
29
- save_path = f"{base_path}-crop{ext}"
33
+ save_path = f"{base_path}-crop{ext}"
30
34
 
31
35
 
32
36
 
33
- img = cv2.imread(img_path)
37
+ crop = img[80: , 80:]
34
38
 
35
- crop = img[80: , 80:]
39
+ cv2.imwrite(save_path, crop)
36
40
 
37
- cv2.imwrite(save_path, crop)
38
-
39
- print(f"image saved! {save_path}")
41
+ print(f"image saved! {save_path}")
40
42
 
41
43
 
42
44