Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw center (#1) #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions label_img.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ 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();
}

void label_img::mousePressEvent(QMouseEvent *ev)
{
setMousePosition(ev->x(), ev->y());
setMousePosition(ev->position().x(), ev->position().y());

if(ev->button() == Qt::RightButton)
{
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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);
}



}
}

Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions label_img.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class label_img : public QLabel

bool m_bLabelingStarted;
bool m_bVisualizeClassName;
bool m_bVisualizeClassCenter = false;

static QColor BOX_COLORS[10];

Expand Down Expand Up @@ -88,6 +89,7 @@ class label_img : public QLabel
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);
Expand Down
7 changes: 7 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

2 changes: 2 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
39 changes: 29 additions & 10 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
<font>
<family>Arial</family>
<pointsize>18</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
Expand Down Expand Up @@ -211,7 +210,6 @@ QSlider::handle:horizontal {
<font>
<family>Arial</family>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
Expand Down Expand Up @@ -322,7 +320,6 @@ QSlider::handle:horizontal {
<font>
<family>Arial</family>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -613,7 +632,7 @@ QTableView {
<x>0</x>
<y>0</y>
<width>1180</width>
<height>21</height>
<height>22</height>
</rect>
</property>
</widget>
Expand Down