Skip to content

Commit dacdc31

Browse files
committed
add merge mask option
1 parent c280c8f commit dacdc31

File tree

6 files changed

+58
-800
lines changed

6 files changed

+58
-800
lines changed

qtproj/SAMQT/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CMakeLists.txt.user*

qtproj/SAMQT/CMakeLists.txt.user

Lines changed: 0 additions & 345 deletions
This file was deleted.

qtproj/SAMQT/CMakeLists.txt.user.5b6e006

Lines changed: 0 additions & 436 deletions
This file was deleted.

qtproj/SAMQT/mainwindow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void MainWindow::on_btn_remove_obj_clicked()
5656
dilate_size = 111;
5757
if (dilate_size < 5)
5858
dilate_size = 5;
59-
this->ui->label->ShowRemoveObject(dilate_size, this->ui->progressBar_remove_obj);
59+
this->ui->label->ShowRemoveObject(dilate_size, this->ui->progressBar_remove_obj, ui->ch_merge_mask->isChecked());
6060
this->setEnabled(true);
6161
}
6262

@@ -122,11 +122,11 @@ void MainWindow::on_btn_save_img_clicked()
122122
}
123123
else
124124
{
125-
if(!(filename.endsWith(".bmp") || filename.endsWith(".png") || filename.endsWith(".jpg")))
125+
if (!(filename.endsWith(".bmp") || filename.endsWith(".png") || filename.endsWith(".jpg")))
126126
{
127127
filename += ".png";
128128
}
129-
129+
130130
if (!(cur_image.save(filename))) // 保存图像
131131
{
132132
QMessageBox::information(this,

qtproj/SAMQT/mainwindow.ui

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@
104104
</item>
105105
</layout>
106106
</item>
107+
<item>
108+
<widget class="QCheckBox" name="ch_merge_mask">
109+
<property name="text">
110+
<string>MergeMask</string>
111+
</property>
112+
</widget>
113+
</item>
107114
<item>
108115
<widget class="QPushButton" name="btn_remove_obj">
109116
<property name="enabled">

qtproj/SAMQT/myqlabel.h

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class myQLabel : public QLabel
3535
bool mouseHolding = false;
3636
QPoint pt_img_first, pt_img_secend;
3737
SAM mSam;
38-
// LamaInpaintOnnx mInpaint;
38+
// LamaInpaintOnnx mInpaint;
3939
std::shared_ptr<LamaInpaint> mInpaint;
4040

4141
void dragEnterEvent(QDragEnterEvent *event) override
@@ -221,7 +221,7 @@ class myQLabel : public QLabel
221221
void InitModel(std::string encoder_model, std::string decoder_model, std::string inpaint_model)
222222
{
223223
mSam.Load(encoder_model, decoder_model);
224-
// mInpaint.Load(inpaint_model);
224+
// mInpaint.Load(inpaint_model);
225225

226226
if (string_utility<std::string>::ends_with(inpaint_model, ".onnx"))
227227
{
@@ -238,7 +238,7 @@ class myQLabel : public QLabel
238238
mInpaint->Load(inpaint_model);
239239
}
240240

241-
void ShowRemoveObject(int dilate_size, QProgressBar *bar)
241+
void ShowRemoveObject(int dilate_size, QProgressBar *bar, bool remove_mask_by_merge = true)
242242
{
243243
if (!cur_image.bits() || !grab_masks.size())
244244
{
@@ -262,21 +262,52 @@ class myQLabel : public QLabel
262262
bar->setMinimum(0);
263263
bar->setMaximum(grab_masks.size());
264264
}
265-
for (auto grab_mask : grab_masks)
265+
if (remove_mask_by_merge)
266266
{
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+
}
279291
}
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+
280311
cur_masks.clear();
281312
rgba_masks.clear();
282313
grab_masks.clear();

0 commit comments

Comments
 (0)