Draw center (#1)

- add a function for drawing the center
---------

Signed-off-by: Vincenzo La Spesa <vincenzolaspesa@gmail.com>
This commit is contained in:
Vincenzo La Spesa 2023-07-09 18:39:31 +02:00 committed by DESKTOP-E7HAUHK\Vincenzo
parent cb4ab0970a
commit 74edf6fa94
5 changed files with 76 additions and 12 deletions

View File

@ -26,7 +26,7 @@ label_img::label_img(QWidget *parent)
void label_img::mouseMoveEvent(QMouseEvent *ev)
{
setMousePosition(ev->x(), ev->y());
setMousePosition(ev->position().x(), ev->position().y());
showImage();
emit Mouse_Moved();
@ -34,7 +34,7 @@ void label_img::mouseMoveEvent(QMouseEvent *ev)
void label_img::mousePressEvent(QMouseEvent *ev)
{
setMousePosition(ev->x(), ev->y());
setMousePosition(ev->position().x(), ev->position().y());
if(ev->button() == Qt::RightButton)
{
@ -174,6 +174,9 @@ void label_img::showImage()
if(m_bVisualizeClassName)
drawObjectLabels(painter, penThick, fontSize, xMargin, yMargin);
if(m_bVisualizeClassCenter)
drawCenter(painter, penThick*1.5);
this->setPixmap(QPixmap::fromImage(img));
}
@ -271,6 +274,15 @@ void label_img::drawFocusedObjectBox(QPainter& painter, Qt::GlobalColor color, i
QPoint absolutePoint2 = cvtRelativeToAbsolutePoint(m_relative_mouse_pos_in_ui);
painter.drawRect(QRect(absolutePoint1, absolutePoint2));
if(m_bVisualizeClassCenter)
{
const auto center = 0.5*(absolutePoint1 + absolutePoint2);
painter.drawPoint(center);
}
}
}
@ -288,6 +300,28 @@ void label_img::drawObjectBoxes(QPainter& painter, int thickWidth)
}
}
void label_img::drawCenter(QPainter& painter, int minThickWidth)
{
QPen pen;
for(ObjectLabelingBox boundingbox: m_objBoundingBoxes)
{
pen.setWidth(minThickWidth);
pen.setColor(m_drawObjectBoxColor.at(boundingbox.label));
painter.setPen(pen);
const auto center = cvtRelativeToAbsolutePoint(boundingbox.box.center());
painter.drawPoint(center);
const auto relative_box=cvtRelativeToAbsoluteRectInUi(boundingbox.box);
const int thickWidth = std::max((int)std::sqrt(std::min(relative_box.width(), relative_box.height())), minThickWidth);
if(minThickWidth * 2 < thickWidth)
{// the rectangle is big, draw a circle too
painter.drawEllipse(center, thickWidth, thickWidth);
}
};
}
void label_img::drawObjectLabels(QPainter& painter, int thickWidth, int fontPixelSize, int xMargin, int yMargin)
{
QFontMetrics fontMetrics = painter.fontMetrics();

View File

@ -35,6 +35,7 @@ public:
bool m_bLabelingStarted;
bool m_bVisualizeClassName;
bool m_bVisualizeClassCenter = false;
static QColor BOX_COLORS[10];
@ -88,6 +89,7 @@ private:
void drawCrossLine(QPainter& , QColor , int thickWidth = 3);
void drawFocusedObjectBox(QPainter& , Qt::GlobalColor , int thickWidth = 3);
void drawObjectBoxes(QPainter& , int thickWidth = 3);
void drawCenter(QPainter& , int thickWidth);
void drawObjectLabels(QPainter& , int thickWidth = 3, int fontPixelSize = 14, int xMargin = 5, int yMargin = 2);
void gammaTransform(QImage& image);
void removeFocusedObjectBox(QPointF);

View File

@ -481,3 +481,10 @@ void MainWindow::on_checkBox_visualize_class_name_clicked(bool checked)
ui->label_image->m_bVisualizeClassName = checked;
ui->label_image->showImage();
}
void MainWindow::on_checkBox_visualize_center_stateChanged(int checked)
{
ui->label_image->m_bVisualizeClassCenter = checked;
ui->label_image->showImage();
}

View File

@ -46,6 +46,8 @@ private slots:
void on_checkBox_visualize_class_name_clicked(bool checked);
void on_checkBox_visualize_center_stateChanged(int arg1);
private:
void init();
void init_table_widget();

View File

@ -79,7 +79,6 @@
<font>
<family>Arial</family>
<pointsize>18</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -211,7 +210,6 @@ QSlider::handle:horizontal {
<font>
<family>Arial</family>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -322,7 +320,6 @@ QSlider::handle:horizontal {
<font>
<family>Arial</family>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -380,7 +377,6 @@ border-color: rgb(0, 255, 255);</string>
<font>
<family>Arial</family>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
<kerning>true</kerning>
</font>
@ -432,7 +428,6 @@ border-color: rgb(0, 255, 255);</string>
<font>
<family>Arial</family>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -453,10 +448,13 @@ border-color: rgb(0, 255, 255);</string>
</property>
<property name="html">
<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;
&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;
&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;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Arial'; font-size:12pt; font-weight:600; font-style:normal;&quot;&gt;
&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>
hr { height: 1px; border-width: 0; }
li.unchecked::marker { content: &quot;\2610&quot;; }
li.checked::marker { content: &quot;\2612&quot;; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Arial'; font-size:12pt; font-weight:700; font-style:normal;&quot;&gt;
&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>
</property>
</widget>
</item>
@ -487,7 +485,6 @@ p, li { white-space: pre-wrap; }
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -581,6 +578,28 @@ QTableView {
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QCheckBox" name="checkBox_visualize_center">
<property name="font">
<font>
<family>Arial</family>
<pointsize>12</pointsize>
<underline>false</underline>
<strikeout>false</strikeout>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color : rgb(0, 0, 17);color : rgb(0, 255, 255);
</string>
</property>
<property name="text">
<string>Visualize Center</string>
</property>
<property name="shortcut">
<string>V</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_visualize_class_name">
<property name="font">
@ -613,7 +632,7 @@ QTableView {
<x>0</x>
<y>0</y>
<width>1180</width>
<height>21</height>
<height>22</height>
</rect>
</property>
</widget>