Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ar_sandbox_lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AR_Sandbox
ar_sandbox_lib
Commits
e371e2ea
Commit
e371e2ea
authored
4 years ago
by
simon.fanetti
Browse files
Options
Downloads
Patches
Plain Diff
add edit mask on UI
parent
fafe110c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/SandboxSetup/croppingmask.cpp
+1
-0
1 addition, 0 deletions
app/SandboxSetup/croppingmask.cpp
app/SandboxSetup/maskedit.cpp
+77
-13
77 additions, 13 deletions
app/SandboxSetup/maskedit.cpp
app/SandboxSetup/maskedit.h
+10
-0
10 additions, 0 deletions
app/SandboxSetup/maskedit.h
with
88 additions
and
13 deletions
app/SandboxSetup/croppingmask.cpp
+
1
−
0
View file @
e371e2ea
...
@@ -10,6 +10,7 @@ CroppingMask::CroppingMask(SandboxSetup *sandbox, QWidget *parent) :
...
@@ -10,6 +10,7 @@ CroppingMask::CroppingMask(SandboxSetup *sandbox, QWidget *parent) :
ui
->
setupUi
(
this
);
ui
->
setupUi
(
this
);
maskEdit
=
new
MaskEdit
(
ui
->
frame
->
geometry
());
maskEdit
=
new
MaskEdit
(
ui
->
frame
->
geometry
());
ui
->
vLayout
->
addWidget
(
maskEdit
,
1
);
ui
->
vLayout
->
addWidget
(
maskEdit
,
1
);
// TODO : try to load cropping mask from file
// TODO : try to load cropping mask from file
}
}
...
...
This diff is collapsed.
Click to expand it.
app/SandboxSetup/maskedit.cpp
+
77
−
13
View file @
e371e2ea
...
@@ -5,7 +5,9 @@ MaskEdit::MaskEdit(const QRect geo, QWidget *parent) :
...
@@ -5,7 +5,9 @@ MaskEdit::MaskEdit(const QRect geo, QWidget *parent) :
QFrame
(
parent
),
QFrame
(
parent
),
ui
(
new
Ui
::
MaskEdit
)
ui
(
new
Ui
::
MaskEdit
)
{
{
this
->
installEventFilter
(
this
);
ui
->
setupUi
(
this
);
ui
->
setupUi
(
this
);
// set size like the parent widget's size
setGeometry
(
0
,
0
,
geo
.
width
(),
geo
.
height
());
setGeometry
(
0
,
0
,
geo
.
width
(),
geo
.
height
());
ui
->
lblFrame
->
setGeometry
(
0
,
0
,
width
(),
height
());
ui
->
lblFrame
->
setGeometry
(
0
,
0
,
width
(),
height
());
}
}
...
@@ -19,21 +21,22 @@ MaskEdit::~MaskEdit()
...
@@ -19,21 +21,22 @@ MaskEdit::~MaskEdit()
void
MaskEdit
::
updateFrame
(
cv
::
Mat
*
frame
,
std
::
vector
<
cv
::
Point
>
*
points
){
void
MaskEdit
::
updateFrame
(
cv
::
Mat
*
frame
,
std
::
vector
<
cv
::
Point
>
*
points
){
capture
=
frame
;
capture
=
frame
;
rectPoints
=
points
;
rectPoints
=
points
;
if
(
frame
!=
nullptr
&&
points
!=
nullptr
){
ratioX
=
(
float
)
capture
->
size
().
width
/
ui
->
lblFrame
->
width
();
ratioY
=
(
float
)
capture
->
size
().
height
/
ui
->
lblFrame
->
height
();
}
update
();
update
();
}
}
void
MaskEdit
::
updateFrame
(
cv
::
Mat
*
frame
){
void
MaskEdit
::
updateFrame
(
cv
::
Mat
*
frame
){
capture
=
frame
;
updateFrame
(
frame
,
rectPoints
);
update
();
}
}
void
MaskEdit
::
updateFrame
(
std
::
vector
<
cv
::
Point
>
*
points
){
void
MaskEdit
::
updateFrame
(
std
::
vector
<
cv
::
Point
>
*
points
){
rectPoints
=
points
;
updateFrame
(
capture
,
points
);
update
();
}
}
void
MaskEdit
::
paintEvent
(
QPaintEvent
*
){
void
MaskEdit
::
paintEvent
(
QPaintEvent
*
){
if
(
capture
!=
nullptr
){
if
(
capture
!=
nullptr
){
...
@@ -64,16 +67,77 @@ void MaskEdit::paintEvent(QPaintEvent *){
...
@@ -64,16 +67,77 @@ void MaskEdit::paintEvent(QPaintEvent *){
}
}
}
}
/*
void CroppingMask::scaleMaskWindowToFrame(){
float xCoeff = cameraRGBFrame.size().width / ui->vLayout->width();
bool
MaskEdit
::
eventFilter
(
QObject
*
object
,
QEvent
*
ev
)
float yCoeff = cameraRGBFrame.size().height / ui->vLayout->height();
{
if
(
ev
->
type
()
==
QEvent
::
MouseButtonPress
){
selectedCornerIndex
=
selectCorner
((
QMouseEvent
*
)
ev
);
}
else
if
(
ev
->
type
()
==
QEvent
::
MouseButtonRelease
){
selectedCornerIndex
=
-
1
;
}
else
if
(
ev
->
type
()
==
QEvent
::
MouseMove
){
QMouseEvent
*
eMouse
=
(
QMouseEvent
*
)
ev
;
if
(
eMouse
->
type
()
==
QMouseEvent
::
MouseMove
){
UpdateSelectedCornerPosition
(
eMouse
);
}
}
(
void
)
object
;
// var unused
return
false
;
}
for(uint i=0; i<rectPoints.size(); i++){
int
MaskEdit
::
selectCorner
(
QMouseEvent
*
eMouse
){
rectPoints[i].x = rectPoints[i].x * xCoeff;
rectPoints[i].y = rectPoints[i].y * yCoeff;
if
(
capture
!=
nullptr
&&
rectPoints
!=
nullptr
){
int
margin
=
20
;
// x and y relative to the captured frame, not the UI
int
mouseX
=
(
int
)(
(
float
)
eMouse
->
x
()
*
ratioX
);
int
mouseY
=
(
int
)(
(
float
)
eMouse
->
y
()
*
ratioY
);
int
marginX
=
(
int
)(
margin
*
ratioX
);
int
marginY
=
(
int
)(
margin
*
ratioY
);
for
(
uint
i
=
0
;
i
<
rectPoints
->
size
();
i
++
){
int
x
=
rectPoints
->
at
(
i
).
x
;
int
y
=
rectPoints
->
at
(
i
).
y
;
if
(
(
x
-
marginX
<=
mouseX
&&
mouseX
<=
x
+
marginX
)
&&
(
y
-
marginY
<=
mouseY
&&
mouseY
<=
y
+
marginY
)
)
{
return
(
int
)
i
;
}
}
}
}
return
-
1
;
}
}
*/
void
MaskEdit
::
UpdateSelectedCornerPosition
(
QMouseEvent
*
eMouse
){
if
(
capture
!=
nullptr
&&
rectPoints
!=
nullptr
){
if
(
selectedCornerIndex
!=
-
1
){
if
(
(
0
<=
eMouse
->
x
()
&&
eMouse
->
x
()
<
ui
->
lblFrame
->
width
())
&&
(
0
<=
eMouse
->
y
()
&&
eMouse
->
y
()
<
ui
->
lblFrame
->
height
())
)
{
int
mouseX
=
(
int
)(
(
float
)
eMouse
->
x
()
*
ratioX
);
int
mouseY
=
(
int
)(
(
float
)
eMouse
->
y
()
*
ratioY
);
rectPoints
->
at
(
selectedCornerIndex
).
x
=
mouseX
;
rectPoints
->
at
(
selectedCornerIndex
).
y
=
mouseY
;
update
();
}
}
}
}
This diff is collapsed.
Click to expand it.
app/SandboxSetup/maskedit.h
+
10
−
0
View file @
e371e2ea
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include
<QPen>
#include
<QPen>
#include
<QPainter>
#include
<QPainter>
#include
<QFrame>
#include
<QFrame>
#include
<QMouseEvent>
#include
<opencv2/opencv.hpp>
#include
<opencv2/opencv.hpp>
namespace
Ui
{
namespace
Ui
{
...
@@ -20,11 +21,20 @@ public:
...
@@ -20,11 +21,20 @@ public:
void
updateFrame
(
cv
::
Mat
*
frame
,
std
::
vector
<
cv
::
Point
>
*
points
);
void
updateFrame
(
cv
::
Mat
*
frame
,
std
::
vector
<
cv
::
Point
>
*
points
);
void
updateFrame
(
cv
::
Mat
*
frame
);
void
updateFrame
(
cv
::
Mat
*
frame
);
void
updateFrame
(
std
::
vector
<
cv
::
Point
>
*
points
);
void
updateFrame
(
std
::
vector
<
cv
::
Point
>
*
points
);
virtual
bool
eventFilter
(
QObject
*
object
,
QEvent
*
ev
)
override
;
private:
private:
Ui
::
MaskEdit
*
ui
;
Ui
::
MaskEdit
*
ui
;
cv
::
Mat
*
capture
=
nullptr
;
cv
::
Mat
*
capture
=
nullptr
;
std
::
vector
<
cv
::
Point
>
*
rectPoints
=
nullptr
;
std
::
vector
<
cv
::
Point
>
*
rectPoints
=
nullptr
;
int
selectedCornerIndex
=
-
1
;
// relative to the captured frame, not the UI
float
ratioX
=
1.0
f
;
float
ratioY
=
1.0
f
;
int
selectCorner
(
QMouseEvent
*
eMouse
);
void
UpdateSelectedCornerPosition
(
QMouseEvent
*
eMouse
);
protected:
protected:
void
paintEvent
(
QPaintEvent
*
event
);
void
paintEvent
(
QPaintEvent
*
event
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment