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
a8698388
Commit
a8698388
authored
Sep 19, 2011
by
Alexander Mordvintsev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RectSelector in common.py
parent
07efb17d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
2 deletions
+34
-2
common.py
samples/python2/common.py
+34
-2
No files found.
samples/python2/common.py
View file @
a8698388
...
...
@@ -114,4 +114,37 @@ def nothing(*arg, **kw):
pass
def
clock
():
return
cv2
.
getTickCount
()
/
cv2
.
getTickFrequency
()
\ No newline at end of file
return
cv2
.
getTickCount
()
/
cv2
.
getTickFrequency
()
class
RectSelector
:
def
__init__
(
self
,
win
,
callback
):
self
.
win
=
win
self
.
callback
=
callback
cv2
.
setMouseCallback
(
win
,
self
.
onmouse
)
self
.
drag_start
=
None
self
.
drag_rect
=
None
def
onmouse
(
self
,
event
,
x
,
y
,
flags
,
param
):
x
,
y
=
np
.
int16
([
x
,
y
])
# BUG
if
event
==
cv2
.
EVENT_LBUTTONDOWN
:
self
.
drag_start
=
(
x
,
y
)
if
self
.
drag_start
:
if
flags
&
cv2
.
EVENT_FLAG_LBUTTON
:
#h, w = self.frame.shape[:2]
xo
,
yo
=
self
.
drag_start
x0
,
y0
=
np
.
minimum
([
xo
,
yo
],
[
x
,
y
])
x1
,
y1
=
np
.
maximum
([
xo
,
yo
],
[
x
,
y
])
#x0, y0 = np.maximum(0, np.minimum([xo, yo], [x, y]))
#x1, y1 = np.minimum([w, h], np.maximum([xo, yo], [x, y]))
self
.
drag_rect
=
None
if
x1
-
x0
>
0
and
y1
-
y0
>
0
:
self
.
drag_rect
=
(
x0
,
y0
,
x1
,
y1
)
else
:
if
self
.
drag_rect
:
self
.
callback
(
self
.
drag_rect
)
self
.
drag_start
=
None
self
.
drag_rect
=
None
def
draw
(
self
,
vis
):
if
not
self
.
drag_rect
:
return
x0
,
y0
,
x1
,
y1
=
self
.
drag_rect
cv2
.
rectangle
(
vis
,
(
x0
,
y0
),
(
x1
,
y1
),
(
0
,
255
,
0
),
2
)
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