Skip to content

Commit 9efcd31

Browse files
Draw center (#1)
* add a function for drawing the center and fix some deprecated function DCO issue Signed-off-by [email protected] * dummy commit Signed-off-by: DESKTOP-E7HAUHK\Vincenzo <[email protected]> --------- Signed-off-by: DESKTOP-E7HAUHK\Vincenzo <[email protected]>
1 parent cb4ab09 commit 9efcd31

File tree

5 files changed

+76
-12
lines changed

5 files changed

+76
-12
lines changed

label_img.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ label_img::label_img(QWidget *parent)
2626

2727
void label_img::mouseMoveEvent(QMouseEvent *ev)
2828
{
29-
setMousePosition(ev->x(), ev->y());
29+
setMousePosition(ev->position().x(), ev->position().y());
3030

3131
showImage();
3232
emit Mouse_Moved();
3333
}
3434

3535
void label_img::mousePressEvent(QMouseEvent *ev)
3636
{
37-
setMousePosition(ev->x(), ev->y());
37+
setMousePosition(ev->position().x(), ev->position().y());
3838

3939
if(ev->button() == Qt::RightButton)
4040
{
@@ -174,6 +174,9 @@ void label_img::showImage()
174174
if(m_bVisualizeClassName)
175175
drawObjectLabels(painter, penThick, fontSize, xMargin, yMargin);
176176

177+
if(m_bVisualizeClassCenter)
178+
drawCenter(painter, penThick*1.5);
179+
177180
this->setPixmap(QPixmap::fromImage(img));
178181
}
179182

@@ -271,6 +274,15 @@ void label_img::drawFocusedObjectBox(QPainter& painter, Qt::GlobalColor color, i
271274
QPoint absolutePoint2 = cvtRelativeToAbsolutePoint(m_relative_mouse_pos_in_ui);
272275

273276
painter.drawRect(QRect(absolutePoint1, absolutePoint2));
277+
278+
if(m_bVisualizeClassCenter)
279+
{
280+
const auto center = 0.5*(absolutePoint1 + absolutePoint2);
281+
painter.drawPoint(center);
282+
}
283+
284+
285+
274286
}
275287
}
276288

@@ -288,6 +300,28 @@ void label_img::drawObjectBoxes(QPainter& painter, int thickWidth)
288300
}
289301
}
290302

303+
void label_img::drawCenter(QPainter& painter, int minThickWidth)
304+
{
305+
QPen pen;
306+
for(ObjectLabelingBox boundingbox: m_objBoundingBoxes)
307+
{
308+
pen.setWidth(minThickWidth);
309+
pen.setColor(m_drawObjectBoxColor.at(boundingbox.label));
310+
painter.setPen(pen);
311+
const auto center = cvtRelativeToAbsolutePoint(boundingbox.box.center());
312+
painter.drawPoint(center);
313+
314+
const auto relative_box=cvtRelativeToAbsoluteRectInUi(boundingbox.box);
315+
const int thickWidth = std::max((int)std::sqrt(std::min(relative_box.width(), relative_box.height())), minThickWidth);
316+
317+
if(minThickWidth * 2 < thickWidth)
318+
{// the rectangle is big, draw a circle too
319+
painter.drawEllipse(center, thickWidth, thickWidth);
320+
}
321+
322+
};
323+
}
324+
291325
void label_img::drawObjectLabels(QPainter& painter, int thickWidth, int fontPixelSize, int xMargin, int yMargin)
292326
{
293327
QFontMetrics fontMetrics = painter.fontMetrics();

label_img.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class label_img : public QLabel
3535

3636
bool m_bLabelingStarted;
3737
bool m_bVisualizeClassName;
38+
bool m_bVisualizeClassCenter = false;
3839

3940
static QColor BOX_COLORS[10];
4041

@@ -88,6 +89,7 @@ class label_img : public QLabel
8889
void drawCrossLine(QPainter& , QColor , int thickWidth = 3);
8990
void drawFocusedObjectBox(QPainter& , Qt::GlobalColor , int thickWidth = 3);
9091
void drawObjectBoxes(QPainter& , int thickWidth = 3);
92+
void drawCenter(QPainter& , int thickWidth);
9193
void drawObjectLabels(QPainter& , int thickWidth = 3, int fontPixelSize = 14, int xMargin = 5, int yMargin = 2);
9294
void gammaTransform(QImage& image);
9395
void removeFocusedObjectBox(QPointF);

mainwindow.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,10 @@ void MainWindow::on_checkBox_visualize_class_name_clicked(bool checked)
481481
ui->label_image->m_bVisualizeClassName = checked;
482482
ui->label_image->showImage();
483483
}
484+
485+
void MainWindow::on_checkBox_visualize_center_stateChanged(int checked)
486+
{
487+
ui->label_image->m_bVisualizeClassCenter = checked;
488+
ui->label_image->showImage();
489+
}
490+

mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ private slots:
4646

4747
void on_checkBox_visualize_class_name_clicked(bool checked);
4848

49+
void on_checkBox_visualize_center_stateChanged(int arg1);
50+
4951
private:
5052
void init();
5153
void init_table_widget();

mainwindow.ui

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
<font>
8080
<family>Arial</family>
8181
<pointsize>18</pointsize>
82-
<weight>75</weight>
8382
<bold>true</bold>
8483
</font>
8584
</property>
@@ -211,7 +210,6 @@ QSlider::handle:horizontal {
211210
<font>
212211
<family>Arial</family>
213212
<pointsize>12</pointsize>
214-
<weight>75</weight>
215213
<bold>true</bold>
216214
</font>
217215
</property>
@@ -322,7 +320,6 @@ QSlider::handle:horizontal {
322320
<font>
323321
<family>Arial</family>
324322
<pointsize>12</pointsize>
325-
<weight>75</weight>
326323
<bold>true</bold>
327324
</font>
328325
</property>
@@ -380,7 +377,6 @@ border-color: rgb(0, 255, 255);</string>
380377
<font>
381378
<family>Arial</family>
382379
<pointsize>12</pointsize>
383-
<weight>75</weight>
384380
<bold>true</bold>
385381
<kerning>true</kerning>
386382
</font>
@@ -432,7 +428,6 @@ border-color: rgb(0, 255, 255);</string>
432428
<font>
433429
<family>Arial</family>
434430
<pointsize>12</pointsize>
435-
<weight>75</weight>
436431
<bold>true</bold>
437432
</font>
438433
</property>
@@ -453,10 +448,13 @@ border-color: rgb(0, 255, 255);</string>
453448
</property>
454449
<property name="html">
455450
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
456-
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
451+
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;meta charset=&quot;utf-8&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
457452
p, li { white-space: pre-wrap; }
458-
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Arial'; font-size:12pt; font-weight:600; font-style:normal;&quot;&gt;
459-
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Gulim'; font-size:9pt;&quot;&gt;Last Labeled Image:&lt;br /&gt;Current Image:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
453+
hr { height: 1px; border-width: 0; }
454+
li.unchecked::marker { content: &quot;\2610&quot;; }
455+
li.checked::marker { content: &quot;\2612&quot;; }
456+
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Arial'; font-size:12pt; font-weight:700; font-style:normal;&quot;&gt;
457+
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Gulim'; font-size:9pt; font-weight:600;&quot;&gt;Last Labeled Image:&lt;br /&gt;Current Image:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
460458
</property>
461459
</widget>
462460
</item>
@@ -487,7 +485,6 @@ p, li { white-space: pre-wrap; }
487485
<property name="font">
488486
<font>
489487
<pointsize>10</pointsize>
490-
<weight>75</weight>
491488
<bold>true</bold>
492489
</font>
493490
</property>
@@ -581,6 +578,28 @@ QTableView {
581578
</item>
582579
<item row="0" column="0">
583580
<layout class="QHBoxLayout" name="horizontalLayout_6">
581+
<item>
582+
<widget class="QCheckBox" name="checkBox_visualize_center">
583+
<property name="font">
584+
<font>
585+
<family>Arial</family>
586+
<pointsize>12</pointsize>
587+
<underline>false</underline>
588+
<strikeout>false</strikeout>
589+
</font>
590+
</property>
591+
<property name="styleSheet">
592+
<string notr="true">background-color : rgb(0, 0, 17);color : rgb(0, 255, 255);
593+
</string>
594+
</property>
595+
<property name="text">
596+
<string>Visualize Center</string>
597+
</property>
598+
<property name="shortcut">
599+
<string>V</string>
600+
</property>
601+
</widget>
602+
</item>
584603
<item>
585604
<widget class="QCheckBox" name="checkBox_visualize_class_name">
586605
<property name="font">
@@ -613,7 +632,7 @@ QTableView {
613632
<x>0</x>
614633
<y>0</y>
615634
<width>1180</width>
616-
<height>21</height>
635+
<height>22</height>
617636
</rect>
618637
</property>
619638
</widget>

0 commit comments

Comments
 (0)