回答編集履歴

1

修正

2022/09/16 06:26

投稿

can110
can110

スコア38262

test CHANGED
@@ -1,3 +1,28 @@
1
1
  imgのshapeが`(ファイル数,高,幅,3)`のように意図しないものになっているはずです。
2
2
  横に連結したい場合は` img = np.concatenate(preparation_lt, axis=1)`とすればよいです。
3
+ ```Python
4
+ import numpy as np
5
+ import cv2
3
6
 
7
+ def pil2cv(image):
8
+ ''' PIL型 -> OpenCV型 '''
9
+ new_image = np.array(image, dtype=np.uint8)
10
+ # カラー
11
+ new_image = cv2.cvtColor(new_image, cv2.COLOR_RGB2BGR)
12
+ return new_image
13
+
14
+ if __name__ == "__main__":
15
+
16
+ preparation_lt = []
17
+ preparation_lt.append(cv2.imread('temp.png'))
18
+ preparation_lt.append(cv2.imread('temp.png'))
19
+
20
+ #img = np.array(preparation_lt) # cv2.error: OpenCV(~
21
+ #print(img.shape) # (2, 120, 180, 3)
22
+ img = np.concatenate(preparation_lt, axis=1) # 横方向に
23
+ print(img.shape) # (120, 360, 3)
24
+
25
+ cv2.imshow('hoge', img)
26
+ cv2.waitKey(0)
27
+ cv2.destroyAllWindows()
28
+ ```