Skip to content

Commit 305900d

Browse files
author
Gin
committed
m
1 parent 5f22792 commit 305900d

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

SerialPrograms/Source/CommonFramework/Panels/UI/PanelWidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class PanelWidget : public QWidget{
3131
PanelInstance& instance(){ return m_instance; }
3232

3333
protected:
34+
// Generate a collapsible UI element that shows the program panel header.
35+
// It contains the name of the program and its description.
3436
virtual CollapsibleGroupBox* make_header(QWidget& parent);
3537

3638
protected:

SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ JsonValue LabelImages::to_json() const{
228228
// m_annotation_file_path
229229
if (m_annotation_file_path.size() > 0 && !m_fail_to_load_annotation_file){
230230
JsonArray anno_json_arr;
231-
for(const auto& anno_obj: m_annotated_objects){
231+
for(const auto& anno_obj: m_annotations){
232232
anno_json_arr.push_back(object_annotation_to_json(anno_obj));
233233
}
234234
cout << "Saving annotation to " << m_annotation_file_path << endl;
@@ -284,7 +284,7 @@ void LabelImages::load_image_related_data(const std::string& image_path, size_t
284284
for(size_t i = 0; i < json_array->size(); i++){
285285
try{
286286
ObjectAnnotation anno_obj = json_to_object_annotation((*json_array)[i]);
287-
m_annotated_objects.emplace_back(std::move(anno_obj));
287+
m_annotations.emplace_back(std::move(anno_obj));
288288
} catch(JsonParseException&){
289289
m_fail_to_load_annotation_file = true;
290290
QMessageBox box;
@@ -296,16 +296,16 @@ void LabelImages::load_image_related_data(const std::string& image_path, size_t
296296
);
297297
}
298298
}
299-
m_last_object_idx = m_annotated_objects.size();
299+
m_last_object_idx = m_annotations.size();
300300
cout << "Loaded existing annotation file " << m_annotation_file_path << endl;
301301
}
302302

303303
void LabelImages::update_rendered_objects(VideoOverlaySet& overlay_set){
304304
overlay_set.clear();
305305
overlay_set.add(COLOR_RED, {X, Y, WIDTH, HEIGHT});
306306

307-
for(size_t i_obj = 0; i_obj < m_annotated_objects.size(); i_obj++){
308-
const auto& obj = m_annotated_objects[i_obj];
307+
for(size_t i_obj = 0; i_obj < m_annotations.size(); i_obj++){
308+
const auto& obj = m_annotations[i_obj];
309309
// overlayset.add(COLOR_RED, pixelbox_to_floatbox(source_image_width, source_image_height, obj.user_box));
310310
const auto mask_float_box = pixelbox_to_floatbox(source_image_width, source_image_height, obj.mask_box);
311311
std::string label = obj.label;
@@ -400,8 +400,8 @@ void LabelImages::compute_mask(VideoOverlaySet& overlay_set){
400400
}
401401

402402
annotation.label = label;
403-
m_last_object_idx = m_annotated_objects.size();
404-
m_annotated_objects.emplace_back(std::move(annotation));
403+
m_last_object_idx = m_annotations.size();
404+
m_annotations.emplace_back(std::move(annotation));
405405

406406
update_rendered_objects(overlay_set);
407407
}
@@ -444,11 +444,11 @@ LabelImages_Widget::LabelImages_Widget(
444444
scroll_layout->addWidget(button);
445445
connect(button, &QPushButton::clicked, this, [this](bool){
446446
auto& program = this->m_program;
447-
if (program.m_annotated_objects.size() > 0){
448-
program.m_annotated_objects.pop_back();
447+
if (program.m_annotations.size() > 0){
448+
program.m_annotations.pop_back();
449449
}
450-
if (program.m_annotated_objects.size() > 0){
451-
program.m_last_object_idx = program.m_annotated_objects.size() - 1;
450+
if (program.m_annotations.size() > 0){
451+
program.m_last_object_idx = program.m_annotations.size() - 1;
452452
}
453453
program.update_rendered_objects(this->m_overlay_set);
454454
});
@@ -470,8 +470,8 @@ LabelImages_Widget::LabelImages_Widget(
470470
}
471471

472472
void LabelImages_Widget::on_config_value_changed(void* object){
473-
if (m_program.m_annotated_objects.size() > 0 && m_program.m_last_object_idx < m_program.m_annotated_objects.size()){
474-
std::string& cur_label = m_program.m_annotated_objects[m_program.m_last_object_idx].label;
473+
if (m_program.m_annotations.size() > 0 && m_program.m_last_object_idx < m_program.m_annotations.size()){
474+
std::string& cur_label = m_program.m_annotations[m_program.m_last_object_idx].label;
475475
cur_label = m_program.FORM_LABEL.slug();
476476
m_program.update_rendered_objects(m_overlay_set);
477477
}

SerialPrograms/Source/ML/Programs/ML_LabelImages.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class LabelImages_Widget;
4343
// also include the related overlay rendering.
4444
// Since it owns rendering objects and the rendering framework needs
4545
// the address of the rendering objects to keep track of them,
46-
// never copy or move this ObjectAnnotation object!
46+
// never copy or move these ObjectAnnotation objects after rendering code has
47+
// access to them!
4748
struct ObjectAnnotation{
4849
ImagePixelBox user_box; // user drawn loose bounding box
4950
ImagePixelBox mask_box;
@@ -100,7 +101,7 @@ class LabelImages : public PanelInstance{
100101
ImageRGB32 m_mask_image;
101102

102103
SAMSession m_sam_session;
103-
std::vector<ObjectAnnotation> m_annotated_objects;
104+
std::vector<ObjectAnnotation> m_annotations;
104105
size_t m_last_object_idx = 0;
105106
std::string m_annotation_file_path;
106107
// if we find an annotation file that is supposed to be created by user in a previous session, but

0 commit comments

Comments
 (0)