@@ -35,7 +35,7 @@ class myQLabel : public QLabel
35
35
bool mouseHolding = false ;
36
36
QPoint pt_img_first, pt_img_secend;
37
37
SAM mSam ;
38
- // LamaInpaintOnnx mInpaint;
38
+ // LamaInpaintOnnx mInpaint;
39
39
std::shared_ptr<LamaInpaint> mInpaint ;
40
40
41
41
void dragEnterEvent (QDragEnterEvent *event) override
@@ -221,7 +221,7 @@ class myQLabel : public QLabel
221
221
void InitModel (std::string encoder_model, std::string decoder_model, std::string inpaint_model)
222
222
{
223
223
mSam .Load (encoder_model, decoder_model);
224
- // mInpaint.Load(inpaint_model);
224
+ // mInpaint.Load(inpaint_model);
225
225
226
226
if (string_utility<std::string>::ends_with (inpaint_model, " .onnx" ))
227
227
{
@@ -238,7 +238,7 @@ class myQLabel : public QLabel
238
238
mInpaint ->Load (inpaint_model);
239
239
}
240
240
241
- void ShowRemoveObject (int dilate_size, QProgressBar *bar)
241
+ void ShowRemoveObject (int dilate_size, QProgressBar *bar, bool remove_mask_by_merge = true )
242
242
{
243
243
if (!cur_image.bits () || !grab_masks.size ())
244
244
{
@@ -262,21 +262,52 @@ class myQLabel : public QLabel
262
262
bar->setMinimum (0 );
263
263
bar->setMaximum (grab_masks.size ());
264
264
}
265
- for ( auto grab_mask : grab_masks )
265
+ if (remove_mask_by_merge )
266
266
{
267
- auto time_start = std::chrono::high_resolution_clock::now ();
268
- inpainted = mInpaint ->Inpaint (inpainted, grab_mask, dilate_size);
269
- auto time_end = std::chrono::high_resolution_clock::now ();
270
- std::chrono::duration<double > diff = time_end - time_start;
271
- std::cout << " Inpaint Inference Cost time : " << diff.count () << " s" << std::endl;
272
- QImage qinpainted (inpainted.data , inpainted.cols , inpainted.rows , inpainted.step1 (), QImage::Format_BGR888);
273
- cur_image = qinpainted.copy ();
274
- if (cur_masks.size ())
275
- cur_masks.removeFirst ();
276
- repaint ();
277
- if (bar)
278
- bar->setValue (bar->value () + 1 );
267
+ if (grab_masks.size ())
268
+ {
269
+ auto base_mask = grab_masks[0 ];
270
+ if (bar)
271
+ bar->setValue (bar->value () + 1 );
272
+
273
+ // merge all mask
274
+ for (size_t i = 1 ; i < grab_masks.size (); i++)
275
+ {
276
+ base_mask |= grab_masks[i];
277
+ if (bar)
278
+ bar->setValue (bar->value () + 1 );
279
+ }
280
+
281
+ auto time_start = std::chrono::high_resolution_clock::now ();
282
+ inpainted = mInpaint ->Inpaint (inpainted, base_mask, dilate_size);
283
+ auto time_end = std::chrono::high_resolution_clock::now ();
284
+ std::chrono::duration<double > diff = time_end - time_start;
285
+ std::cout << " Inpaint Inference Cost time : " << diff.count () << " s" << std::endl;
286
+ QImage qinpainted (inpainted.data , inpainted.cols , inpainted.rows , inpainted.step1 (), QImage::Format_BGR888);
287
+ cur_image = qinpainted.copy ();
288
+ cur_masks.clear ();
289
+ repaint ();
290
+ }
279
291
}
292
+ else
293
+ {
294
+ for (auto grab_mask : grab_masks)
295
+ {
296
+ auto time_start = std::chrono::high_resolution_clock::now ();
297
+ inpainted = mInpaint ->Inpaint (inpainted, grab_mask, dilate_size);
298
+ auto time_end = std::chrono::high_resolution_clock::now ();
299
+ std::chrono::duration<double > diff = time_end - time_start;
300
+ std::cout << " Inpaint Inference Cost time : " << diff.count () << " s" << std::endl;
301
+ QImage qinpainted (inpainted.data , inpainted.cols , inpainted.rows , inpainted.step1 (), QImage::Format_BGR888);
302
+ cur_image = qinpainted.copy ();
303
+ if (cur_masks.size ())
304
+ cur_masks.removeFirst ();
305
+ repaint ();
306
+ if (bar)
307
+ bar->setValue (bar->value () + 1 );
308
+ }
309
+ }
310
+
280
311
cur_masks.clear ();
281
312
rgba_masks.clear ();
282
313
grab_masks.clear ();
0 commit comments