Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
b9d6fc9d
Commit
b9d6fc9d
authored
Jul 19, 2019
by
John Smith
Committed by
Alexander Alekhin
Aug 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix cv::selectROI rectangle rendering issue
backport of commit:
95c65aff
parent
d2c64b56
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
12 deletions
+24
-12
roiSelector.cpp
modules/highgui/src/roiSelector.cpp
+24
-12
No files found.
modules/highgui/src/roiSelector.cpp
View file @
b9d6fc9d
...
@@ -106,10 +106,10 @@ class ROISelector
...
@@ -106,10 +106,10 @@ class ROISelector
bool
isDrawing
;
bool
isDrawing
;
Rect2d
box
;
Rect2d
box
;
Mat
image
;
Mat
image
;
Point2f
startPos
;
// parameters for drawing from the center
// parameters for drawing from the center
bool
drawFromCenter
;
bool
drawFromCenter
;
Point2f
center
;
// initializer list
// initializer list
handlerT
()
:
isDrawing
(
false
),
drawFromCenter
(
true
){};
handlerT
()
:
isDrawing
(
false
),
drawFromCenter
(
true
){};
...
@@ -136,19 +136,31 @@ class ROISelector
...
@@ -136,19 +136,31 @@ class ROISelector
{
{
if
(
selectorParams
.
drawFromCenter
)
if
(
selectorParams
.
drawFromCenter
)
{
{
selectorParams
.
box
.
width
=
2
*
(
x
-
selectorParams
.
center
.
x
);
// limit half extends to imageSize
selectorParams
.
box
.
height
=
2
*
(
y
-
selectorParams
.
center
.
y
);
float
halfWidth
=
std
::
min
(
std
::
min
(
selectorParams
.
box
.
x
=
std
::
min
(
std
::
abs
(
x
-
selectorParams
.
startPos
.
x
),
std
::
max
(
selectorParams
.
center
.
x
-
selectorParams
.
box
.
width
/
2.0
,
0.
),
(
double
)
imageSize
.
width
);
selectorParams
.
startPos
.
x
),
selectorParams
.
box
.
y
=
std
::
min
(
imageSize
.
width
-
selectorParams
.
startPos
.
x
);
std
::
max
(
selectorParams
.
center
.
y
-
selectorParams
.
box
.
height
/
2.0
,
0.
),
(
double
)
imageSize
.
height
);
float
halfHeight
=
std
::
min
(
std
::
min
(
std
::
abs
(
y
-
selectorParams
.
startPos
.
y
),
selectorParams
.
startPos
.
y
),
imageSize
.
height
-
selectorParams
.
startPos
.
y
);
selectorParams
.
box
.
width
=
halfWidth
*
2
;
selectorParams
.
box
.
height
=
halfHeight
*
2
;
selectorParams
.
box
.
x
=
selectorParams
.
startPos
.
x
-
halfWidth
;
selectorParams
.
box
.
y
=
selectorParams
.
startPos
.
y
-
halfHeight
;
}
}
else
else
{
{
selectorParams
.
box
.
width
=
std
::
max
(
// limit x and y to imageSize
std
::
min
(
x
-
selectorParams
.
box
.
x
,
(
double
)
imageSize
.
width
-
selectorParams
.
box
.
x
),
-
selectorParams
.
box
.
x
);
int
lx
=
std
::
min
(
std
::
max
(
x
,
0
),
imageSize
.
width
);
selectorParams
.
box
.
height
=
std
::
max
(
int
by
=
std
::
min
(
std
::
max
(
y
,
0
),
imageSize
.
height
);
std
::
min
(
y
-
selectorParams
.
box
.
y
,
(
double
)
imageSize
.
height
-
selectorParams
.
box
.
y
),
-
selectorParams
.
box
.
y
);
selectorParams
.
box
.
width
=
std
::
abs
(
lx
-
selectorParams
.
startPos
.
x
);
selectorParams
.
box
.
height
=
std
::
abs
(
by
-
selectorParams
.
startPos
.
y
);
selectorParams
.
box
.
x
=
std
::
min
((
float
)
lx
,
selectorParams
.
startPos
.
x
);
selectorParams
.
box
.
y
=
std
::
min
((
float
)
by
,
selectorParams
.
startPos
.
y
);
}
}
}
}
break
;
break
;
...
@@ -157,7 +169,7 @@ class ROISelector
...
@@ -157,7 +169,7 @@ class ROISelector
case
EVENT_LBUTTONDOWN
:
case
EVENT_LBUTTONDOWN
:
selectorParams
.
isDrawing
=
true
;
selectorParams
.
isDrawing
=
true
;
selectorParams
.
box
=
Rect2d
(
x
,
y
,
0
,
0
);
selectorParams
.
box
=
Rect2d
(
x
,
y
,
0
,
0
);
selectorParams
.
center
=
Point2f
((
float
)
x
,
(
float
)
y
);
selectorParams
.
startPos
=
Point2f
((
float
)
x
,
(
float
)
y
);
break
;
break
;
// cleaning up the selected bounding box
// cleaning up the selected bounding box
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment