Skip to content

Commit b11ef66

Browse files
committed
Merge pull request #13 from andywang0607/param-setting-window
Param setting window
2 parents e17f8a1 + d93b5d1 commit b11ef66

12 files changed

+225
-5
lines changed

AutoAnnotationTool/AutoAnnotationTool.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
1717

1818
SOURCES += \
1919
CV/cvmodule.cpp \
20+
CV/cvparam.cpp \
2021
datasaver.cpp \
2122
labelcollector.cpp \
2223
labeldatamodel.cpp \
@@ -38,6 +39,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
3839

3940
HEADERS += \
4041
CV/cvmodule.h \
42+
CV/cvparam.h \
4143
datasaver.h \
4244
labelcollector.h \
4345
labeldata.h \

AutoAnnotationTool/CV/cvmodule.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ void CVModule::GetCroppedImg(QRectF rect, qreal factor)
2222
cv::imshow("Cropped", croppedImg);
2323
}
2424

25-
void CVModule::GetContour(QVector<LabelData *> &dataVec, int labelIdx, qreal factor)
25+
void CVModule::GetContour(QVector<LabelData *> &dataVec, int labelIdx, qreal factor, CVParam *param)
2626
{
2727
qDebug()<< Q_FUNC_INFO << "start";
2828
if(m_imgOri.empty()) return;
2929

3030
// grabcut
3131
cv::Mat grab, bg, fg;
32-
cv::grabCut(m_imgOri, grab, GetROIRect(dataVec.at(labelIdx)->rect, factor), bg, fg, 5, cv::GC_INIT_WITH_RECT);
32+
cv::grabCut(m_imgOri, grab, GetROIRect(dataVec.at(labelIdx)->rect, factor), bg, fg, param->iteration(), cv::GC_INIT_WITH_RECT);
3333

3434
// equalizeHist
3535
equalizeHist(grab, grab);
@@ -59,7 +59,7 @@ void CVModule::GetContour(QVector<LabelData *> &dataVec, int labelIdx, qreal fac
5959
}
6060
}
6161
std::vector<std::vector<cv::Point>> contoursPoly(contours.size());
62-
approxPolyDP(cv::Mat(contours[largestContourIndex]), contoursPoly[largestContourIndex], 1, true);
62+
approxPolyDP(cv::Mat(contours[largestContourIndex]), contoursPoly[largestContourIndex], param->epsilon(), true);
6363
SetContours(dataVec, labelIdx, contoursPoly.at(largestContourIndex), factor);
6464
qDebug()<< Q_FUNC_INFO << "end";
6565
}

AutoAnnotationTool/CV/cvmodule.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CVMODULE_H
22
#define CVMODULE_H
33
#include "labeldata.h"
4+
#include "CV/cvparam.h"
45

56
#include <QRectF>
67
#include <QString>
@@ -14,7 +15,7 @@ class CVModule
1415
public:
1516
CVModule();
1617
void GetCroppedImg(QRectF rect, qreal factor);
17-
void GetContour(QVector<LabelData*> &dataVec, int labelIdx, qreal factor);
18+
void GetContour(QVector<LabelData*> &dataVec, int labelIdx, qreal factor, CVParam *param);
1819
void GetOriginImg(QString imgSrc);
1920
private:
2021
cv::Rect GetROIRect(QRectF rect, qreal factor);

AutoAnnotationTool/CV/cvparam.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "cvparam.h"
2+
3+
CVParam::CVParam(QObject *parent) : QObject(parent)
4+
, m_iteration(4)
5+
, m_epsilon(1)
6+
{
7+
8+
}
9+
10+
int CVParam::iteration() const
11+
{
12+
return m_iteration;
13+
}
14+
15+
qreal CVParam::epsilon() const
16+
{
17+
return m_epsilon;
18+
}
19+
20+
void CVParam::setIteration(int iteration)
21+
{
22+
if (m_iteration == iteration)
23+
return;
24+
25+
m_iteration = iteration;
26+
emit iterationChanged(m_iteration);
27+
}
28+
29+
void CVParam::setEpsilon(qreal epsilon)
30+
{
31+
if (qFuzzyCompare(m_epsilon, epsilon))
32+
return;
33+
34+
m_epsilon = epsilon;
35+
emit epsilonChanged(m_epsilon);
36+
}

AutoAnnotationTool/CV/cvparam.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef CVPARAM_H
2+
#define CVPARAM_H
3+
4+
#include <QObject>
5+
6+
class CVParam : public QObject
7+
{
8+
Q_OBJECT
9+
Q_PROPERTY(int iteration READ iteration WRITE setIteration NOTIFY iterationChanged)
10+
Q_PROPERTY(qreal epsilon READ epsilon WRITE setEpsilon NOTIFY epsilonChanged)
11+
12+
public:
13+
explicit CVParam(QObject *parent = nullptr);
14+
15+
int iteration() const;
16+
17+
qreal epsilon() const;
18+
19+
public slots:
20+
void setIteration(int iteration);
21+
22+
void setEpsilon(qreal epsilon);
23+
24+
signals:
25+
26+
void iterationChanged(int iteration);
27+
void epsilonChanged(qreal epsilon);
28+
29+
private:
30+
int m_iteration;
31+
qreal m_epsilon;
32+
};
33+
34+
#endif // CVPARAM_H
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import QtQuick 2.0
2+
import QtQuick.Controls 2.14
3+
import QtQuick.Layouts 1.0
4+
5+
Page {
6+
property int defaultIteration: 4
7+
property double defaultEpsilon: 1
8+
ColumnLayout{
9+
anchors.fill: parent
10+
anchors.margins: 20
11+
Layout.fillWidth: true
12+
RowLayout{
13+
Label{
14+
id: iterationLabel
15+
Layout.preferredWidth: 100
16+
text: qsTr("Iteration")
17+
}
18+
Label{
19+
id: iterationShow
20+
horizontalAlignment: Text.AlignHCenter
21+
Layout.preferredWidth: 60
22+
text: CVParam.iteration
23+
}
24+
Slider {
25+
id: iterationSlider
26+
Layout.fillWidth: true
27+
value: defaultIteration
28+
from: 1
29+
to: 10
30+
stepSize :1
31+
onValueChanged: {
32+
CVParam.iteration = value
33+
}
34+
}
35+
}
36+
RowLayout{
37+
Label{
38+
id: epsilonLabel
39+
Layout.preferredWidth: 100
40+
text: qsTr("Epsilon")
41+
}
42+
Label{
43+
id: epsilonShow
44+
horizontalAlignment: Text.AlignHCenter
45+
Layout.preferredWidth: 60
46+
text: CVParam.epsilon
47+
}
48+
Slider {
49+
id: epsilonLabelSlider
50+
Layout.fillWidth: true
51+
value: defaultEpsilon
52+
from: 1
53+
to: 10
54+
stepSize :0.01
55+
onValueChanged: {
56+
CVParam.epsilon = value.toFixed(2)
57+
}
58+
}
59+
}
60+
}
61+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import QtQuick 2.0
2+
import QtQuick.Controls 2.14
3+
import QtQuick.Layouts 1.0
4+
import QtQuick.Window 2.14
5+
6+
Window {
7+
id: settingWindow
8+
width: 350
9+
height: 150
10+
title: qsTr("Setting")
11+
flags: Qt.Window
12+
modality: Qt.WindowModal
13+
visible: false
14+
property color tabButtonColorPressed: "#CCCCCC"
15+
property color tabButtonColorReleased: "#808080"
16+
17+
TabBar {
18+
id: settingWindowTab
19+
anchors.top: parent.top
20+
anchors.horizontalCenter: parent.horizontalCenter
21+
width: parent.width
22+
height: 30
23+
TabButton{
24+
text: qsTr("CV Setting")
25+
background: Rectangle {
26+
color: settingWindowTab.currentIndex == 0 ? tabButtonColorPressed : tabButtonColorReleased
27+
}
28+
}
29+
}
30+
SwipeView{
31+
id: settingSwipe
32+
interactive: false
33+
visible: true
34+
width: parent.width
35+
height: parent.height - settingWindowTab.height
36+
anchors.top: settingWindowTab.bottom
37+
anchors.horizontalCenter: parent.horizontalCenter
38+
CVParamSettingPage{
39+
id: cvParamSettingPage
40+
}
41+
}
42+
}

AutoAnnotationTool/labelcollector.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ LabelCollector::LabelCollector(QQuickItem *parent) : QQuickPaintedItem(parent)
2727

2828
menu.addAction(QStringLiteral("Get Polygon"),this, [&](){
2929
setCursor(QCursor(Qt::BusyCursor));
30-
future = QtConcurrent::run(cvModule.get(), &CVModule::GetContour, m_dataVec, m_selectLabelIdx.front(), getFactorScaled());
30+
future = QtConcurrent::run(cvModule.get(), &CVModule::GetContour, m_dataVec, m_selectLabelIdx.front(), getFactorScaled(), m_cvParam);
3131
watcher.setFuture(future);
3232
});
3333

@@ -164,6 +164,11 @@ int LabelCollector::fileIdx() const
164164
return m_fileIdx;
165165
}
166166

167+
CVParam *LabelCollector::cvParam() const
168+
{
169+
return m_cvParam;
170+
}
171+
167172
void LabelCollector::setImage(const QImage &image){
168173
if(image.isNull()){
169174
qDebug() << Q_FUNC_INFO << "image is Null";
@@ -570,3 +575,12 @@ void LabelCollector::setFileIdx(int fileIdx)
570575
emit fileIdxChanged(m_fileIdx);
571576
setImgSrc(fileInfoList.at(m_fileIdx).absoluteFilePath());
572577
}
578+
579+
void LabelCollector::setCvParam(CVParam *cvParam)
580+
{
581+
if (m_cvParam == cvParam)
582+
return;
583+
584+
m_cvParam = cvParam;
585+
emit cvParamChanged(m_cvParam);
586+
}

AutoAnnotationTool/labelcollector.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
#include "labeldata.h"
2323
#include "mouseselectresult.h"
2424
#include "CV/cvmodule.h"
25+
#include "CV/cvparam.h"
2526

2627
class LabelCollector : public QQuickPaintedItem
2728
{
2829
Q_OBJECT
2930
Q_PROPERTY(QImage image READ image WRITE setImage NOTIFY imageChanged)
3031
Q_PROPERTY(QString imgSrc READ imgSrc WRITE setImgSrc NOTIFY imgSrcChanged)
3132
Q_PROPERTY(int fileIdx READ fileIdx WRITE setFileIdx NOTIFY fileIdxChanged)
33+
Q_PROPERTY(CVParam* cvParam READ cvParam WRITE setCvParam NOTIFY cvParamChanged)
3234

3335
public:
3436
explicit LabelCollector(QQuickItem *parent = nullptr);
@@ -48,6 +50,8 @@ class LabelCollector : public QQuickPaintedItem
4850
qreal getFactorScaled() const;
4951
int fileIdx() const;
5052

53+
CVParam *cvParam() const;
54+
5155
private:
5256
QImage m_image;
5357
QImage m_imageScaled;
@@ -64,6 +68,8 @@ public slots:
6468

6569
void setFileIdx(int fileIdx);
6670

71+
void setCvParam(CVParam* cvParam);
72+
6773
signals:
6874
void imageChanged();
6975
void imgSrcChanged(QString imgSrc);
@@ -81,6 +87,8 @@ public slots:
8187
void fileIdxChanged(int fileIdx);
8288

8389
//mouse behavior
90+
void cvParamChanged(CVParam* cvParam);
91+
8492
protected:
8593
void mousePressEvent(QMouseEvent *event) override;
8694
void mouseMoveEvent(QMouseEvent *event) override;
@@ -121,6 +129,7 @@ public slots:
121129
QFuture<void> future;
122130
QFutureWatcher<void> watcher;
123131
int m_fileIdx;
132+
CVParam* m_cvParam;
124133
};
125134

126135
#endif // LABELCOLLECTOR_H

AutoAnnotationTool/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include <QApplication>
22
#include <QGuiApplication>
33
#include <QQmlApplicationEngine>
4+
#include <QQmlContext>
45

56
#include <labelcollector.h>
67
#include <labeldatamodel.h>
78
#include <datasaver.h>
9+
#include <CV/cvparam.h>
810

911
int main(int argc, char *argv[])
1012
{
@@ -16,7 +18,9 @@ int main(int argc, char *argv[])
1618
qmlRegisterType<LabelDataModel>("LabelDataModel", 1, 0, "LabelDataModel");
1719
qmlRegisterType<DataSaver>("DataSaver", 1, 0, "DataSaver");
1820

21+
CVParam cvParam;
1922
QQmlApplicationEngine engine;
23+
engine.rootContext()->setContextProperty("CVParam", &cvParam);
2024
const QUrl url(QStringLiteral("qrc:/main.qml"));
2125
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
2226
&app, [url](QObject *obj, const QUrl &objUrl) {

AutoAnnotationTool/main.qml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import LabelCollector 1.0
88
import LabelDataModel 1.0
99
import DataSaver 1.0
1010

11+
import "Setting"
12+
1113
Window {
1214
visible: true
1315
width: 870
@@ -67,13 +69,23 @@ Window {
6769
dataSaver.SaveData(0)
6870
}
6971
}
72+
Button{
73+
id:settingButton
74+
Layout.fillHeight: true
75+
Layout.fillWidth: true
76+
text: qsTr("Setting")
77+
onClicked: {
78+
settingWindow.show()
79+
}
80+
}
7081
}
7182
LabelCollector{
7283
id:labelCollector
7384
Layout.alignment: Qt.AlignLeft
7485
Layout.fillWidth: true
7586
Layout.fillHeight: true
7687
Layout.preferredWidth: 500
88+
cvParam: CVParam
7789
onWidthChanged: {
7890
labelCollector.setImage(labelCollector.image)
7991
}
@@ -176,4 +188,7 @@ Window {
176188
labelCollector: labelCollector
177189
}
178190
}
191+
SettingWindow{
192+
id: settingWindow
193+
}
179194
}

AutoAnnotationTool/qml.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<RCC>
22
<qresource prefix="/">
33
<file>main.qml</file>
4+
<file>Setting/SettingWindow.qml</file>
5+
<file>Setting/CVParamSettingPage.qml</file>
46
</qresource>
57
</RCC>

0 commit comments

Comments
 (0)