質問編集履歴

3

print()に修正

2020/02/08 03:24

投稿

nikoniko3
nikoniko3

スコア5

test CHANGED
File without changes
test CHANGED
@@ -74,95 +74,113 @@
74
74
 
75
75
  output_dir = os.path.join(OUT_FOLDER, image_dir)
76
76
 
77
+ print("Processing input {i}...".format(i=image_dir))
78
+
79
+
80
+
81
+ # Search for images to process
82
+
83
+ source_names = collect_files(r'C:\Users\〇〇〇\Desktop\poisson-image-editing-master\input'*source.'))
84
+
85
+ target_names = collect_files(r'C:\Users\〇〇〇\Desktop\poisson-image-editing-master\input'*target.'))
86
+
87
+ mask_names = collect_files(r'C:\Users\〇〇〇\Desktop\poisson-image-editing-master\input'*mask.'))
88
+
89
+
90
+
91
+ if not len(source_names) == len(target_names) == len(mask_names) == 1:
92
+
93
+ print("There must be one source, one target, and one mask per input.")
94
+
95
+ continue
96
+
97
+
98
+
99
+ # Read images
100
+
101
+ source_img = cv2.imread(source_names[0], cv2.IMREAD_COLOR)
102
+
103
+ target_img = cv2.imread(target_names[0], cv2.IMREAD_COLOR)
104
+
105
+ mask_img = cv2.imread(mask_names[0], cv2.IMREAD_GRAYSCALE)
106
+
107
+
108
+
109
+ # Normalize mask to range [0,1]
110
+
111
+ mask = np.atleast_3d(mask_img).astype(np.float) / 255.
112
+
113
+ # Make mask binary
114
+
115
+ mask[mask != 1] = 0
116
+
117
+ # Trim to one channel
118
+
119
+ mask = mask[:,:,0]
120
+
121
+ channels = source_img.shape[-1]
122
+
123
+ # Call the poisson method on each individual channel
124
+
125
+ result_stack = [poisson.process(source_img[:,:,i], target_img[:,:,i], mask) for i in range(channels)]
126
+
127
+ # Merge the channels back into one image
128
+
129
+ result = cv2.merge(result_stack)
130
+
131
+ # Make result directory if needed
132
+
133
+ try:
134
+
135
+ os.makedirs(output_dir)
136
+
137
+ except OSError as exception:
138
+
139
+ if exception.errno != errno.EEXIST:
140
+
141
+ raise
142
+
143
+ # Write result
144
+
145
+ cv2.imwrite(r'C:\Users\〇〇〇〇\Desktop\test\Blended.jpg', result)
146
+
147
+ print("Finished processing input {i}.".format(i=image_dir))
148
+
149
+
150
+
151
+ ```
152
+
153
+ ### 前提・実現したいこと
154
+
155
+ pythonで合成画像を作っています。
156
+
157
+ ■■な機能を実装中に以下のエラーメッセージが発生しました。
158
+
159
+
160
+
161
+ ### 発生している問題・エラーメッセージ
162
+
163
+
164
+
165
+ ```
166
+
167
+ File "<ipython-input-3-dda816a77788>", line 39
168
+
77
169
  print "Processing input {i}...".format(i=image_dir)
78
170
 
79
-
80
-
81
- # Search for images to process
82
-
83
- source_names = collect_files(r'C:\Users\〇〇〇\Desktop\poisson-image-editing-master\input'*source.'))
84
-
85
- target_names = collect_files(r'C:\Users\〇〇〇\Desktop\poisson-image-editing-master\input'*target.'))
86
-
87
- mask_names = collect_files(r'C:\Users\〇〇〇\Desktop\poisson-image-editing-master\input'*mask.'))
88
-
89
-
90
-
91
- if not len(source_names) == len(target_names) == len(mask_names) == 1:
92
-
93
- print("There must be one source, one target, and one mask per input.")
94
-
95
- continue
96
-
97
-
98
-
99
- # Read images
100
-
101
- source_img = cv2.imread(source_names[0], cv2.IMREAD_COLOR)
102
-
103
- target_img = cv2.imread(target_names[0], cv2.IMREAD_COLOR)
104
-
105
- mask_img = cv2.imread(mask_names[0], cv2.IMREAD_GRAYSCALE)
106
-
107
-
108
-
109
- # Normalize mask to range [0,1]
110
-
111
- mask = np.atleast_3d(mask_img).astype(np.float) / 255.
112
-
113
- # Make mask binary
114
-
115
- mask[mask != 1] = 0
116
-
117
- # Trim to one channel
118
-
119
- mask = mask[:,:,0]
120
-
121
- channels = source_img.shape[-1]
122
-
123
- # Call the poisson method on each individual channel
124
-
125
- result_stack = [poisson.process(source_img[:,:,i], target_img[:,:,i], mask) for i in range(channels)]
126
-
127
- # Merge the channels back into one image
128
-
129
- result = cv2.merge(result_stack)
130
-
131
- # Make result directory if needed
132
-
133
- try:
171
+ ^
134
-
135
- os.makedirs(output_dir)
172
+
136
-
137
- except OSError as exception:
173
+ SyntaxError: invalid syntax
138
-
139
- if exception.errno != errno.EEXIST:
174
+
140
-
141
- raise
142
-
143
- # Write result
144
-
145
- cv2.imwrite(r'C:\Users\〇〇〇〇\Desktop\test\Blended.jpg', result)
146
-
147
- print "Finished processing input {i}.".format(i=image_dir)
148
-
149
-
150
-
151
- ```
175
+ ```
152
-
176
+
177
+
178
+
153
- ### 前提・実現したいこと
179
+ ### 該当のソースコード
154
-
180
+
181
+
182
+
155
- pythonで合成画像作っています。
183
+ ```ここに言語名入力
156
-
157
- ■■な機能を実装中に以下のエラーメッセージが発生しました。
158
-
159
-
160
-
161
- ### 発生している問題・エラーメッセージ
162
-
163
-
164
-
165
- ```
166
184
 
167
185
  File "<ipython-input-3-dda816a77788>", line 39
168
186
 
@@ -176,24 +194,6 @@
176
194
 
177
195
 
178
196
 
179
- ### 該当のソースコード
180
-
181
-
182
-
183
- ```ここに言語名を入力
184
-
185
- File "<ipython-input-3-dda816a77788>", line 39
186
-
187
- print "Processing input {i}...".format(i=image_dir)
188
-
189
- ^
190
-
191
- SyntaxError: invalid syntax
192
-
193
- ```
194
-
195
-
196
-
197
197
  ### 試したこと
198
198
 
199
199
 

2

リンクを追加しました。

2020/02/08 03:24

投稿

nikoniko3
nikoniko3

スコア5

test CHANGED
File without changes
test CHANGED
@@ -207,3 +207,5 @@
207
207
 
208
208
 
209
209
  GitHubからダウンロードしました。
210
+
211
+ https://github.com/willemmanuel/poisson-image-editing

1

更新しました

2020/02/08 03:19

投稿

nikoniko3
nikoniko3

スコア5

test CHANGED
File without changes
test CHANGED
@@ -80,11 +80,11 @@
80
80
 
81
81
  # Search for images to process
82
82
 
83
- source_names = collect_files(os.path.join(dirpath, '*source.'))
83
+ source_names = collect_files(r'C:\Users\〇〇〇\Desktop\poisson-image-editing-master\input'*source.'))
84
-
84
+
85
- target_names = collect_files(os.path.join(dirpath, '*target.'))
85
+ target_names = collect_files(r'C:\Users\〇〇〇\Desktop\poisson-image-editing-master\input'*target.'))
86
-
86
+
87
- mask_names = collect_files(os.path.join(dirpath, '*mask.'))
87
+ mask_names = collect_files(r'C:\Users\〇〇〇\Desktop\poisson-image-editing-master\input'*mask.'))
88
88
 
89
89
 
90
90