Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
9d227641
O
Opencv
项目概览
Greenplum
/
Opencv
11 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9d227641
编写于
2月 05, 2021
作者:
A
Alexander Alekhin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19411 from crackwitz:highgui-pollkey
上级
2a2e4e78
26da4910
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
152 addition
and
72 deletion
+152
-72
modules/highgui/include/opencv2/highgui.hpp
modules/highgui/include/opencv2/highgui.hpp
+27
-15
modules/highgui/src/window.cpp
modules/highgui/src/window.cpp
+2
-0
modules/highgui/src/window_QT.cpp
modules/highgui/src/window_QT.cpp
+7
-0
modules/highgui/src/window_cocoa.mm
modules/highgui/src/window_cocoa.mm
+7
-0
modules/highgui/src/window_gtk.cpp
modules/highgui/src/window_gtk.cpp
+7
-0
modules/highgui/src/window_w32.cpp
modules/highgui/src/window_w32.cpp
+94
-57
modules/highgui/src/window_winrt.cpp
modules/highgui/src/window_winrt.cpp
+8
-0
未找到文件。
modules/highgui/include/opencv2/highgui.hpp
浏览文件 @
9d227641
...
@@ -348,23 +348,34 @@ The function waitKey waits for a key event infinitely (when \f$\texttt{delay}\le
...
@@ -348,23 +348,34 @@ The function waitKey waits for a key event infinitely (when \f$\texttt{delay}\le
milliseconds, when it is positive. Since the OS has a minimum time between switching threads, the
milliseconds, when it is positive. Since the OS has a minimum time between switching threads, the
function will not wait exactly delay ms, it will wait at least delay ms, depending on what else is
function will not wait exactly delay ms, it will wait at least delay ms, depending on what else is
running on your computer at that time. It returns the code of the pressed key or -1 if no key was
running on your computer at that time. It returns the code of the pressed key or -1 if no key was
pressed before the specified time had elapsed.
pressed before the specified time had elapsed. To check for a key press but not wait for it, use
#pollKey.
@note
@note The functions #waitKey and #pollKey are the only methods in HighGUI that can fetch and handle
GUI events, so one of them needs to be called periodically for normal event processing unless
This function is the only method in HighGUI that can fetch and handle events, so it needs to be
HighGUI is used within an environment that takes care of event processing.
called periodically for normal event processing unless HighGUI is used within an environment that
takes care of event processing.
@note
@note The function only works if there is at least one HighGUI window created and the window is
active. If there are several HighGUI windows, any of them can be active.
The function only works if there is at least one HighGUI window created and the window is active.
If there are several HighGUI windows, any of them can be active.
@param delay Delay in milliseconds. 0 is the special value that means "forever".
@param delay Delay in milliseconds. 0 is the special value that means "forever".
*/
*/
CV_EXPORTS_W
int
waitKey
(
int
delay
=
0
);
CV_EXPORTS_W
int
waitKey
(
int
delay
=
0
);
/** @brief Polls for a pressed key.
The function pollKey polls for a key event without waiting. It returns the code of the pressed key
or -1 if no key was pressed since the last invocation. To wait until a key was pressed, use #waitKey.
@note The functions #waitKey and #pollKey are the only methods in HighGUI that can fetch and handle
GUI events, so one of them needs to be called periodically for normal event processing unless
HighGUI is used within an environment that takes care of event processing.
@note The function only works if there is at least one HighGUI window created and the window is
active. If there are several HighGUI windows, any of them can be active.
*/
CV_EXPORTS_W
int
pollKey
();
/** @brief Displays an image in the specified window.
/** @brief Displays an image in the specified window.
The function imshow displays an image in the specified window. If the window was created with the
The function imshow displays an image in the specified window. If the window was created with the
...
@@ -384,11 +395,12 @@ If the window was not created before this function, it is assumed creating a win
...
@@ -384,11 +395,12 @@ If the window was not created before this function, it is assumed creating a win
If you need to show an image that is bigger than the screen resolution, you will need to call namedWindow("", WINDOW_NORMAL) before the imshow.
If you need to show an image that is bigger than the screen resolution, you will need to call namedWindow("", WINDOW_NORMAL) before the imshow.
@note This function should be followed by cv::waitKey function which displays the image for specified
@note This function should be followed by a call to cv::waitKey or cv::pollKey to perform GUI
milliseconds. Otherwise, it won't display the image. For example, **waitKey(0)** will display the window
housekeeping tasks that are necessary to actually show the given image and make the window respond
infinitely until any keypress (it is suitable for image display). **waitKey(25)** will display a frame
to mouse and keyboard events. Otherwise, it won't display the image and the window might lock up.
for 25 ms, after which display will be automatically closed. (If you put it in a loop to read
For example, **waitKey(0)** will display the window infinitely until any keypress (it is suitable
videos, it will display the video frame-by-frame)
for image display). **waitKey(25)** will display a frame and wait approximately 25 ms for a key
press (suitable for displaying a video frame-by-frame). To remove the window, use cv::destroyWindow.
@note
@note
...
...
modules/highgui/src/window.cpp
浏览文件 @
9d227641
...
@@ -297,6 +297,8 @@ int cv::waitKey(int delay)
...
@@ -297,6 +297,8 @@ int cv::waitKey(int delay)
return
(
code
!=
-
1
)
?
(
code
&
0xff
)
:
-
1
;
return
(
code
!=
-
1
)
?
(
code
&
0xff
)
:
-
1
;
}
}
// NOTE: cv::pollKey has no C API equivalent. it is implemented in each backend source file.
int
cv
::
createTrackbar
(
const
String
&
trackbarName
,
const
String
&
winName
,
int
cv
::
createTrackbar
(
const
String
&
trackbarName
,
const
String
&
winName
,
int
*
value
,
int
count
,
TrackbarCallback
callback
,
int
*
value
,
int
count
,
TrackbarCallback
callback
,
void
*
userdata
)
void
*
userdata
)
...
...
modules/highgui/src/window_QT.cpp
浏览文件 @
9d227641
...
@@ -382,6 +382,13 @@ CV_IMPL int cvWaitKey(int delay)
...
@@ -382,6 +382,13 @@ CV_IMPL int cvWaitKey(int delay)
}
}
int
cv
::
pollKey
()
{
CV_TRACE_FUNCTION
();
// fallback. please implement a proper polling function
return
cvWaitKey
(
1
);
}
//Yannick Verdie
//Yannick Verdie
//This function is experimental and some functions (such as cvSet/getWindowProperty will not work)
//This function is experimental and some functions (such as cvSet/getWindowProperty will not work)
//We recommend not using this function for now
//We recommend not using this function for now
...
...
modules/highgui/src/window_cocoa.mm
浏览文件 @
9d227641
...
@@ -632,6 +632,13 @@ CV_IMPL int cvWaitKey (int maxWait)
...
@@ -632,6 +632,13 @@ CV_IMPL int cvWaitKey (int maxWait)
return
returnCode
;
return
returnCode
;
}
}
int
cv
::
pollKey
()
{
CV_TRACE_FUNCTION
();
// fallback. please implement a proper polling function
return
cvWaitKey
(
1
);
}
CvRect
cvGetWindowRect_COCOA
(
const
char
*
name
)
CvRect
cvGetWindowRect_COCOA
(
const
char
*
name
)
{
{
CvRect
result
=
cvRect
(
-
1
,
-
1
,
-
1
,
-
1
);
CvRect
result
=
cvRect
(
-
1
,
-
1
,
-
1
,
-
1
);
...
...
modules/highgui/src/window_gtk.cpp
浏览文件 @
9d227641
...
@@ -1950,6 +1950,13 @@ CV_IMPL int cvWaitKey( int delay )
...
@@ -1950,6 +1950,13 @@ CV_IMPL int cvWaitKey( int delay )
return
last_key
;
return
last_key
;
}
}
int
cv
::
pollKey
()
{
CV_TRACE_FUNCTION
();
// fallback. please implement a proper polling function
return
cvWaitKey
(
1
);
}
#endif // HAVE_GTK
#endif // HAVE_GTK
#endif // _WIN32
#endif // _WIN32
...
...
modules/highgui/src/window_w32.cpp
浏览文件 @
9d227641
...
@@ -2064,6 +2064,97 @@ static void showSaveDialog(CvWindow* window)
...
@@ -2064,6 +2064,97 @@ static void showSaveDialog(CvWindow* window)
}
}
}
}
/*
* message received. check if it belongs to our windows (frame, hwnd).
* returns true (and value in keyCode) if a key was pressed.
* otherwise returns false (indication to continue event loop).
*/
static
bool
handleMessage
(
MSG
&
message
,
int
&
keyCode
)
{
// whether we have to call translate and dispatch yet
// otherwise the message was handled specifically
bool
is_processed
=
false
;
for
(
CvWindow
*
window
=
hg_windows
;
window
!=
0
&&
is_processed
==
0
;
window
=
window
->
next
)
{
if
(
!
(
window
->
hwnd
==
message
.
hwnd
||
window
->
frame
==
message
.
hwnd
))
continue
;
is_processed
=
true
;
switch
(
message
.
message
)
{
case
WM_DESTROY
:
case
WM_CHAR
:
DispatchMessage
(
&
message
);
keyCode
=
(
int
)
message
.
wParam
;
return
true
;
case
WM_SYSKEYDOWN
:
if
(
message
.
wParam
==
VK_F10
)
{
is_processed
=
true
;
keyCode
=
(
int
)(
message
.
wParam
<<
16
);
return
true
;
}
break
;
case
WM_KEYDOWN
:
TranslateMessage
(
&
message
);
if
((
message
.
wParam
>=
VK_F1
&&
message
.
wParam
<=
VK_F24
)
||
message
.
wParam
==
VK_HOME
||
message
.
wParam
==
VK_END
||
message
.
wParam
==
VK_UP
||
message
.
wParam
==
VK_DOWN
||
message
.
wParam
==
VK_LEFT
||
message
.
wParam
==
VK_RIGHT
||
message
.
wParam
==
VK_INSERT
||
message
.
wParam
==
VK_DELETE
||
message
.
wParam
==
VK_PRIOR
||
message
.
wParam
==
VK_NEXT
)
{
DispatchMessage
(
&
message
);
is_processed
=
true
;
keyCode
=
(
int
)(
message
.
wParam
<<
16
);
return
true
;
}
// Intercept Ctrl+C for copy to clipboard
if
(
'C'
==
message
.
wParam
&&
(
::
GetKeyState
(
VK_CONTROL
)
>>
15
))
::
SendMessage
(
message
.
hwnd
,
WM_COPY
,
0
,
0
);
// Intercept Ctrl+S for "save as" dialog
if
(
'S'
==
message
.
wParam
&&
(
::
GetKeyState
(
VK_CONTROL
)
>>
15
))
showSaveDialog
(
window
);
default:
DispatchMessage
(
&
message
);
is_processed
=
true
;
break
;
}
}
if
(
!
is_processed
)
{
TranslateMessage
(
&
message
);
DispatchMessage
(
&
message
);
}
return
false
;
// no value to return, keep processing
}
/*
* process until queue is empty but don't wait.
*/
int
cv
::
pollKey
()
{
CV_TRACE_FUNCTION
();
for
(;;)
{
MSG
message
;
if
(
PeekMessage
(
&
message
,
0
,
0
,
0
,
PM_REMOVE
)
==
FALSE
)
return
-
1
;
int
keyCode
=
-
1
;
if
(
handleMessage
(
message
,
keyCode
))
return
keyCode
;
}
}
CV_IMPL
int
CV_IMPL
int
cvWaitKey
(
int
delay
)
cvWaitKey
(
int
delay
)
{
{
...
@@ -2072,9 +2163,7 @@ cvWaitKey( int delay )
...
@@ -2072,9 +2163,7 @@ cvWaitKey( int delay )
for
(;;)
for
(;;)
{
{
CvWindow
*
window
;
MSG
message
;
MSG
message
;
int
is_processed
=
0
;
if
(
(
delay
<=
0
)
&&
hg_windows
)
if
(
(
delay
<=
0
)
&&
hg_windows
)
GetMessage
(
&
message
,
0
,
0
,
0
);
GetMessage
(
&
message
,
0
,
0
,
0
);
...
@@ -2087,61 +2176,9 @@ cvWaitKey( int delay )
...
@@ -2087,61 +2176,9 @@ cvWaitKey( int delay )
continue
;
continue
;
}
}
for
(
window
=
hg_windows
;
window
!=
0
&&
is_processed
==
0
;
window
=
window
->
next
)
int
keyCode
=
-
1
;
{
if
(
handleMessage
(
message
,
keyCode
))
if
(
window
->
hwnd
==
message
.
hwnd
||
window
->
frame
==
message
.
hwnd
)
return
keyCode
;
{
is_processed
=
1
;
switch
(
message
.
message
)
{
case
WM_DESTROY
:
case
WM_CHAR
:
DispatchMessage
(
&
message
);
return
(
int
)
message
.
wParam
;
case
WM_SYSKEYDOWN
:
if
(
message
.
wParam
==
VK_F10
)
{
is_processed
=
1
;
return
(
int
)(
message
.
wParam
<<
16
);
}
break
;
case
WM_KEYDOWN
:
TranslateMessage
(
&
message
);
if
(
(
message
.
wParam
>=
VK_F1
&&
message
.
wParam
<=
VK_F24
)
||
message
.
wParam
==
VK_HOME
||
message
.
wParam
==
VK_END
||
message
.
wParam
==
VK_UP
||
message
.
wParam
==
VK_DOWN
||
message
.
wParam
==
VK_LEFT
||
message
.
wParam
==
VK_RIGHT
||
message
.
wParam
==
VK_INSERT
||
message
.
wParam
==
VK_DELETE
||
message
.
wParam
==
VK_PRIOR
||
message
.
wParam
==
VK_NEXT
)
{
DispatchMessage
(
&
message
);
is_processed
=
1
;
return
(
int
)(
message
.
wParam
<<
16
);
}
// Intercept Ctrl+C for copy to clipboard
if
(
'C'
==
message
.
wParam
&&
(
::
GetKeyState
(
VK_CONTROL
)
>>
15
))
::
SendMessage
(
message
.
hwnd
,
WM_COPY
,
0
,
0
);
// Intercept Ctrl+S for "save as" dialog
if
(
'S'
==
message
.
wParam
&&
(
::
GetKeyState
(
VK_CONTROL
)
>>
15
))
showSaveDialog
(
window
);
default:
DispatchMessage
(
&
message
);
is_processed
=
1
;
break
;
}
}
}
if
(
!
is_processed
)
{
TranslateMessage
(
&
message
);
DispatchMessage
(
&
message
);
}
}
}
}
}
...
...
modules/highgui/src/window_winrt.cpp
浏览文件 @
9d227641
...
@@ -205,6 +205,14 @@ CV_IMPL int cvGetTrackbarPos(const char* trackbar_name, const char* window_name)
...
@@ -205,6 +205,14 @@ CV_IMPL int cvGetTrackbarPos(const char* trackbar_name, const char* window_name)
/********************************** Not YET implemented API ****************************************************/
/********************************** Not YET implemented API ****************************************************/
int
cv
::
pollKey
()
{
CV_TRACE_FUNCTION
();
CV_WINRT_NO_GUI_ERROR
(
"cvPollKey"
);
// TODO: implement appropriate logic here
}
CV_IMPL
int
cvWaitKey
(
int
delay
)
CV_IMPL
int
cvWaitKey
(
int
delay
)
{
{
CV_WINRT_NO_GUI_ERROR
(
"cvWaitKey"
);
CV_WINRT_NO_GUI_ERROR
(
"cvWaitKey"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录