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
2a4fb155
Commit
2a4fb155
authored
Nov 28, 2011
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added OpenGL support to Gtk realization of highgui
parent
fb2fad52
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1039 additions
and
479 deletions
+1039
-479
CMakeLists.txt
CMakeLists.txt
+75
-63
precomp.hpp
modules/highgui/src/precomp.hpp
+7
-2
window.cpp
modules/highgui/src/window.cpp
+56
-50
window_gtk.cpp
modules/highgui/src/window_gtk.cpp
+876
-346
point_cloud.cpp
samples/cpp/point_cloud.cpp
+23
-15
highgui_gpu.cpp
samples/gpu/highgui_gpu.cpp
+2
-3
No files found.
CMakeLists.txt
View file @
2a4fb155
...
...
@@ -37,9 +37,9 @@ endif(NOT CMAKE_TOOLCHAIN_FILE)
# Top level OpenCV project
# --------------------------------------------------------------
if
(
NOT IOS
)
cmake_minimum_required
(
VERSION 2.6.3
)
cmake_minimum_required
(
VERSION 2.6.3
)
else
()
cmake_minimum_required
(
VERSION 2.8
)
cmake_minimum_required
(
VERSION 2.8
)
endif
()
project
(
OpenCV
)
...
...
@@ -77,9 +77,9 @@ endif()
# Default: dynamic libraries
# ----------------------------------------------------------------------------
if
(
NOT IOS
)
set
(
BUILD_SHARED_LIBS ON CACHE BOOL
"Build shared libraries (.dll/.so) instead of static ones (.lib/.a)"
)
set
(
BUILD_SHARED_LIBS ON CACHE BOOL
"Build shared libraries (.dll/.so) instead of static ones (.lib/.a)"
)
else
()
set
(
BUILD_SHARED_LIBS OFF CACHE BOOL
"Build shared libraries (.dll/.so) instead of static ones (.lib/.a)"
)
set
(
BUILD_SHARED_LIBS OFF CACHE BOOL
"Build shared libraries (.dll/.so) instead of static ones (.lib/.a)"
)
endif
()
# ----------------------------------------------------------------------------
# Include debug info into debug libs?
...
...
@@ -164,7 +164,7 @@ endif()
if
(
WIN32 AND NOT BUILD_SHARED_LIBS
)
option
(
BUILD_WITH_STATIC_CRT
"Enables use of staticaly linked CRT"
ON
)
endif
()
if
(
MSVC
)
if
(
BUILD_WITH_STATIC_CRT
)
foreach
(
flag_var
...
...
@@ -179,7 +179,7 @@ if(MSVC)
string
(
REGEX REPLACE
"/MDd"
"/MTd"
${
flag_var
}
"
${${
flag_var
}}
"
)
endif
()
endforeach
(
flag_var
)
set
(
CMAKE_EXE_LINKER_FLAGS
"
${
CMAKE_EXE_LINKER_FLAGS
}
/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcrtd.lib"
)
set
(
CMAKE_EXE_LINKER_FLAGS_DEBUG
"
${
CMAKE_EXE_LINKER_FLAGS_DEBUG
}
/NODEFAULTLIB:libcmt.lib"
)
set
(
CMAKE_EXE_LINKER_FLAGS_RELEASE
"
${
CMAKE_EXE_LINKER_FLAGS_RELEASE
}
/NODEFAULTLIB:libcmtd.lib"
)
...
...
@@ -266,11 +266,11 @@ if(CMAKE_COMPILER_IS_GNUCXX)
execute_process
(
COMMAND
${
CMAKE_CXX_COMPILER
}
--version
OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process
(
COMMAND
${
CMAKE_CXX_COMPILER
}
-v
ERROR_VARIABLE CMAKE_OPENCV_GCC_INFO_FULL
OUTPUT_STRIP_TRAILING_WHITESPACE
)
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Typical output in CMAKE_OPENCV_GCC_VERSION_FULL: "c+//0 (whatever) 4.2.3 (...)"
# Look for the version number
string
(
REGEX MATCH
"[0-9]+.[0-9]+.[0-9]+"
CMAKE_GCC_REGEX_VERSION
"
${
CMAKE_OPENCV_GCC_VERSION_FULL
}
"
)
...
...
@@ -335,9 +335,9 @@ endif()
# Build tests:
# ===================================================
if
(
NOT IOS
)
set
(
BUILD_TESTS ON CACHE BOOL
"Build tests"
)
set
(
BUILD_TESTS ON CACHE BOOL
"Build tests"
)
else
()
set
(
BUILD_TESTS OFF CACHE BOOL
"Build tests"
)
set
(
BUILD_TESTS OFF CACHE BOOL
"Build tests"
)
endif
()
set
(
BUILD_PERF_TESTS ON CACHE BOOL
"Build performance tests"
)
...
...
@@ -442,7 +442,7 @@ if(APPLE)
endif
()
if
(
IOS
)
set
(
WITH_AVFOUNDATION ON CACHE BOOL
"Use AVFoundation for Video I/O"
)
set
(
WITH_AVFOUNDATION ON CACHE BOOL
"Use AVFoundation for Video I/O"
)
endif
()
set
(
WITH_TBB OFF CACHE BOOL
"Include Intel TBB support"
)
...
...
@@ -507,6 +507,17 @@ if(UNIX)
if
(
WITH_GTK
)
CHECK_MODULE
(
gtk+-2.0 HAVE_GTK
)
CHECK_MODULE
(
gthread-2.0 HAVE_GTHREAD
)
if
(
WITH_OPENGL
)
CHECK_MODULE
(
gtkglext-1.0 HAVE_GTKGLEXT
)
if
(
HAVE_GTKGLEXT
)
find_package
(
OpenGL QUIET
)
if
(
OPENGL_FOUND
)
set
(
HAVE_OPENGL 1
)
set
(
OPENCV_LINKER_LIBS
${
OPENCV_LINKER_LIBS
}
${
OPENGL_LIBRARIES
}
)
include_directories
(
${
OPENGL_INCLUDE_DIR
}
)
endif
()
endif
()
endif
()
else
()
set
(
HAVE_GTK FALSE
)
set
(
HAVE_GTHREAD FALSE
)
...
...
@@ -575,7 +586,7 @@ if(UNIX)
set
(
HAVE_DC1394 FALSE
)
endif
()
if
(
NOT APPLE
)
if
(
NOT APPLE
)
CHECK_INCLUDE_FILE
(
alloca.h HAVE_ALLOCA_H
)
CHECK_FUNCTION_EXISTS
(
alloca HAVE_ALLOCA
)
CHECK_INCLUDE_FILE
(
unistd.h HAVE_UNISTD_H
)
...
...
@@ -608,8 +619,8 @@ if(UNIX)
endif
()
endif
()
if
(
UNIX OR WIN32
)
if
(
NOT OPENCV_BUILD_3RDPARTY_LIBS
)
message
(
STATUS
"NOT OPENCV_BUILD_3RDPARTY_LIBS **************************************************"
)
if
(
NOT OPENCV_BUILD_3RDPARTY_LIBS
)
message
(
STATUS
"NOT OPENCV_BUILD_3RDPARTY_LIBS **************************************************"
)
include
(
FindZLIB
)
if
(
WITH_PNG
)
include
(
FindPNG
)
...
...
@@ -631,9 +642,9 @@ if (UNIX OR WIN32)
set
(
JASPER_FOUND FALSE
)
endif
()
if
(
WITH_JPEG
)
include
(
FindJPEG
)
include
(
FindJPEG
)
else
()
set
(
JPEG_FOUND FALSE
)
set
(
JPEG_FOUND FALSE
)
endif
()
endif
()
endif
()
...
...
@@ -758,7 +769,7 @@ if (BUILD_JAVA_SUPPORT)
if
(
ANDROID
)
file
(
TO_CMAKE_PATH
"$ENV{ANDROID_SDK}"
ANDROID_SDK_ENV_PATH
)
#find android SDK
find_host_program
(
ANDROID_EXECUTABLE
NAMES android.bat android
...
...
@@ -912,13 +923,13 @@ if (WITH_TBB)
include_directories
(
${
TBB_INCLUDE_DIRS
}
)
endif
()
link_directories
(
${
TBB_LIBRARY_DIRS
}
)
set
(
OPENCV_LINKER_LIBS
${
OPENCV_LINKER_LIBS
}
${
TBB_LIBRARIES
}
)
set
(
OPENCV_LINKER_LIBS
${
OPENCV_LINKER_LIBS
}
${
TBB_LIBRARIES
}
)
endif
()
endif
()
endif
()
if
(
NOT HAVE_TBB
)
set
(
TBB_DEFAULT_INCLUDE_DIRS
"/opt/intel/tbb"
"/usr/local/include"
"/usr/include"
"C:/Program Files/Intel/TBB"
"C:/Program Files (x86)/Intel/TBB"
"C:/Program Files (x86)/TBB"
"
${
CMAKE_INSTALL_PREFIX
}
/include"
)
find_path
(
TBB_INCLUDE_DIR
"tbb/tbb.h"
PATHS
${
TBB_DEFAULT_INCLUDE_DIRS
}
DOC
"The path to TBB headers"
)
if
(
TBB_INCLUDE_DIR
)
if
(
UNIX
)
...
...
@@ -938,8 +949,8 @@ if (WITH_TBB)
link_directories
(
"
${
TBB_LIB_DIR
}
"
)
set
(
OPENCV_LINKER_LIBS
${
OPENCV_LINKER_LIBS
}
tbb
)
else
()
get_filename_component
(
_TBB_LIB_PATH
"
${
TBB_INCLUDE_DIR
}
/../lib"
ABSOLUTE
)
get_filename_component
(
_TBB_LIB_PATH
"
${
TBB_INCLUDE_DIR
}
/../lib"
ABSOLUTE
)
if
(
${
CMAKE_SYSTEM_PROCESSOR
}
MATCHES amd64*|x86_64* OR MSVC64
)
set
(
_TBB_LIB_PATH
"
${
_TBB_LIB_PATH
}
/intel64"
)
elseif
(
${
CMAKE_SYSTEM_PROCESSOR
}
MATCHES x86*|i386*|i686*
)
...
...
@@ -949,7 +960,7 @@ if (WITH_TBB)
if
(
MSVC80
)
set
(
_TBB_LIB_PATH
"
${
_TBB_LIB_PATH
}
/vc8"
)
elseif
(
MSVC90
)
set
(
_TBB_LIB_PATH
"
${
_TBB_LIB_PATH
}
/vc9"
)
set
(
_TBB_LIB_PATH
"
${
_TBB_LIB_PATH
}
/vc9"
)
elseif
(
MSVC10
)
set
(
_TBB_LIB_PATH
"
${
_TBB_LIB_PATH
}
/vc10"
)
endif
()
...
...
@@ -975,7 +986,7 @@ if (NOT HAVE_TBB AND WITH_THREADING_FRAMEWORK)
if
(
THREADING_FRAMEWORK_HEADER AND THREADING_FRAMEWORK_SOURCE
)
set
(
HAVE_THREADING_FRAMEWORK 1
)
endif
()
if
(
TEGRA_DIR
)
if
(
TEGRA_DIR
)
set
(
HAVE_THREADING_FRAMEWORK 1
)
endif
()
endif
()
...
...
@@ -999,7 +1010,7 @@ endif()
if
(
WITH_CUDA
)
find_package
(
CUDA 4.0
)
if
(
CUDA_FOUND
)
set
(
HAVE_CUDA 1
)
...
...
@@ -1015,25 +1026,25 @@ if(WITH_CUDA)
set
(
CUDA_ARCH_BIN
"1.1 1.2 1.3 2.0 2.1(2.0)"
CACHE STRING
"Specify 'real' GPU architectures to build binaries for, BIN(PTX) format is supported"
)
set
(
CUDA_ARCH_PTX
"2.0"
CACHE STRING
"Specify 'virtual' PTX architectures to build PTX intermediate code for"
)
string
(
REGEX REPLACE
"
\\
."
""
ARCH_BIN_NO_POINTS
"
${
CUDA_ARCH_BIN
}
"
)
string
(
REGEX REPLACE
"
\\
."
""
ARCH_PTX_NO_POINTS
"
${
CUDA_ARCH_PTX
}
"
)
# Ckeck if user specified 1.0 compute capability: we don't support it
string
(
REGEX MATCH
"1.0"
HAS_ARCH_10
"
${
CUDA_ARCH_BIN
}
${
CUDA_ARCH_PTX
}
"
)
set
(
CUDA_ARCH_BIN_OR_PTX_10 0
)
if
(
NOT
${
HAS_ARCH_10
}
STREQUAL
""
)
set
(
CUDA_ARCH_BIN_OR_PTX_10 1
)
endif
()
# NVCC flags to be set
set
(
NVCC_FLAGS_EXTRA
""
)
set
(
NVCC_FLAGS_EXTRA
""
)
# These vars will be passed into the templates
set
(
OPENCV_CUDA_ARCH_BIN
""
)
set
(
OPENCV_CUDA_ARCH_PTX
""
)
set
(
OPENCV_CUDA_ARCH_FEATURES
""
)
set
(
OPENCV_CUDA_ARCH_BIN
""
)
set
(
OPENCV_CUDA_ARCH_PTX
""
)
set
(
OPENCV_CUDA_ARCH_FEATURES
""
)
# Tell NVCC to add binaries for the specified GPUs
string
(
REGEX MATCHALL
"[0-9()]+"
ARCH_LIST
"
${
ARCH_BIN_NO_POINTS
}
"
)
foreach
(
ARCH IN LISTS ARCH_LIST
)
...
...
@@ -1043,13 +1054,13 @@ if(WITH_CUDA)
set
(
OPENCV_CUDA_ARCH_BIN
"
${
OPENCV_CUDA_ARCH_BIN
}
${
CMAKE_MATCH_1
}
"
)
set
(
OPENCV_CUDA_ARCH_FEATURES
"
${
OPENCV_CUDA_ARCH_FEATURES
}
${
CMAKE_MATCH_2
}
"
)
else
()
# User didn't explicitly specify PTX for the concrete BIN, we assume PTX=BIN
# User didn't explicitly specify PTX for the concrete BIN, we assume PTX=BIN
set
(
NVCC_FLAGS_EXTRA
${
NVCC_FLAGS_EXTRA
}
-gencode arch=compute_
${
ARCH
}
,code=sm_
${
ARCH
}
)
set
(
OPENCV_CUDA_ARCH_BIN
"
${
OPENCV_CUDA_ARCH_BIN
}
${
ARCH
}
"
)
set
(
OPENCV_CUDA_ARCH_FEATURES
"
${
OPENCV_CUDA_ARCH_FEATURES
}
${
ARCH
}
"
)
endif
()
endforeach
()
# Tell NVCC to add PTX intermediate code for the specified architectures
string
(
REGEX MATCHALL
"[0-9]+"
ARCH_LIST
"
${
ARCH_PTX_NO_POINTS
}
"
)
foreach
(
ARCH IN LISTS ARCH_LIST
)
...
...
@@ -1057,16 +1068,16 @@ if(WITH_CUDA)
set
(
OPENCV_CUDA_ARCH_PTX
"
${
OPENCV_CUDA_ARCH_PTX
}
${
ARCH
}
"
)
set
(
OPENCV_CUDA_ARCH_FEATURES
"
${
OPENCV_CUDA_ARCH_FEATURES
}
${
ARCH
}
"
)
endforeach
()
# These vars will be processed in other scripts
set
(
CUDA_NVCC_FLAGS
${
CUDA_NVCC_FLAGS
}
${
NVCC_FLAGS_EXTRA
}
)
set
(
CUDA_NVCC_FLAGS
${
CUDA_NVCC_FLAGS
}
${
NVCC_FLAGS_EXTRA
}
)
set
(
OpenCV_CUDA_CC
"
${
NVCC_FLAGS_EXTRA
}
"
)
message
(
STATUS
"CUDA NVCC target flags:
${
CUDA_NVCC_FLAGS
}
"
)
else
()
unset
(
CUDA_ARCH_BIN CACHE
)
unset
(
CUDA_ARCH_PTX CACHE
)
endif
()
unset
(
CUDA_ARCH_PTX CACHE
)
endif
()
endif
()
...
...
@@ -1080,7 +1091,7 @@ endif()
############################### XIMEA ################################
set
(
HAVE_XIMEA FALSE
)
if
(
WITH_XIMEA
)
include
(
OpenCVFindXimea.cmake
)
endif
()
...
...
@@ -1112,7 +1123,7 @@ if(WIN32)
if
(
WITH_VIDEOINPUT
)
set
(
HAVE_VIDEOINPUT 1
)
endif
()
if
(
MSVC
)
set
(
HIGHGUI_LIBRARIES
${
HIGHGUI_LIBRARIES
}
vfw32
)
endif
()
...
...
@@ -1122,13 +1133,13 @@ if(WIN32)
set
(
HIGHGUI_LIBRARIES
${
HIGHGUI_LIBRARIES
}
msvfw32 avifil32 avicap32 winmm
)
else
()
set
(
HIGHGUI_LIBRARIES
${
HIGHGUI_LIBRARIES
}
vfw32 winmm
)
endif
()
endif
()
endif
()
if
(
WITH_OPENGL AND NOT HAVE_QT_OPENGL
)
if
(
WITH_OPENGL AND NOT HAVE_QT_OPENGL
)
find_package
(
OpenGL QUIET
)
if
(
OPENGL_FOUND
)
if
(
OPENGL_FOUND
)
set
(
HAVE_OPENGL 1
)
set
(
OPENCV_LINKER_LIBS
${
OPENCV_LINKER_LIBS
}
${
OPENGL_LIBRARIES
}
)
include_directories
(
${
OPENGL_INCLUDE_DIR
}
)
...
...
@@ -1140,7 +1151,7 @@ endif()
if
(
ANDROID AND ANDROID_NATIVE_API_LEVEL GREATER 7
)
option
(
WITH_ANDROID_CAMERA
"Build with native Android camera support"
TRUE
)
SET
(
ANDROID_SOURCE_TREE
"ANDROID_SOURCE_TREE-NOTFOUND"
CACHE PATH
SET
(
ANDROID_SOURCE_TREE
"ANDROID_SOURCE_TREE-NOTFOUND"
CACHE PATH
"Path to Android source tree.
Set this variable to path to your Android sources to compile
libnative_camera_rx.x.x.so for your Android"
)
...
...
@@ -1264,14 +1275,14 @@ if(CMAKE_COMPILER_IS_GNUCXX)
if
(
ENABLE_SSE3
)
set
(
EXTRA_C_FLAGS_RELEASE
"
${
EXTRA_C_FLAGS_RELEASE
}
-msse3"
)
endif
()
if
(
${
CMAKE_OPENCV_GCC_VERSION_NUM
}
GREATER 402
)
set
(
HAVE_GCC43_OR_NEWER 1
)
endif
()
if
(
${
CMAKE_OPENCV_GCC_VERSION_NUM
}
GREATER 401
)
set
(
HAVE_GCC42_OR_NEWER 1
)
endif
()
if
(
HAVE_GCC42_OR_NEWER OR APPLE
)
if
(
ENABLE_SSSE3
)
set
(
EXTRA_C_FLAGS_RELEASE
"
${
EXTRA_C_FLAGS_RELEASE
}
-mssse3"
)
...
...
@@ -1456,8 +1467,8 @@ if(WIN32)
exec_program
(
mkdir ARGS
"-p
\"
${
CMAKE_BINARY_DIR
}
/win-install/
\"
"
OUTPUT_VARIABLE RET_VAL
)
configure_file
(
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/OpenCVConfig.cmake.in"
"
${
CMAKE_BINARY_DIR
}
/win-install/OpenCVConfig.cmake"
IMMEDIATE @ONLY
)
# Install the OpenCVConfig.cmake file which has the right paths pointing to the install directory
install
(
FILES
"
${
CMAKE_BINARY_DIR
}
/win-install/OpenCVConfig.cmake"
DESTINATION
"
${
CMAKE_INSTALL_PREFIX
}
/"
)
# Install the OpenCVConfig.cmake file which has the right paths pointing to the install directory
install
(
FILES
"
${
CMAKE_BINARY_DIR
}
/win-install/OpenCVConfig.cmake"
DESTINATION
"
${
CMAKE_INSTALL_PREFIX
}
/"
)
endif
()
# --------------------------------------------------------------------------------------------
...
...
@@ -1600,13 +1611,13 @@ endif()
#-----------------------------------
if
(
BUILD_PERF_TESTS AND PYTHON_EXECUTABLE
)
if
(
CMAKE_VERSION VERSION_GREATER
"2.8.2"
)
add_custom_target
(
perf
add_custom_target
(
perf
${
PYTHON_EXECUTABLE
}
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/modules/ts/misc/run.py"
--configuration $<CONFIGURATION>
"
${
CMAKE_BINARY_DIR
}
"
WORKING_DIRECTORY
"
${
CMAKE_BINARY_DIR
}
"
DEPENDS
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/modules/ts/misc/run.py"
)
else
()
add_custom_target
(
perf
add_custom_target
(
perf
${
PYTHON_EXECUTABLE
}
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/modules/ts/misc/run.py"
"
${
CMAKE_BINARY_DIR
}
"
WORKING_DIRECTORY
"
${
CMAKE_BINARY_DIR
}
"
DEPENDS
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/modules/ts/misc/run.py"
...
...
@@ -1634,7 +1645,7 @@ macro(status text)
SET
(
status_cond
)
SET
(
status_then
)
SET
(
status_else
)
SET
(
status_current_name
"cond"
)
foreach
(
arg
${
ARGN
}
)
if
(
arg STREQUAL
"THEN"
)
...
...
@@ -1725,7 +1736,8 @@ else()
endif
()
else
()
status
(
" GTK+ 2.x:"
HAVE_GTK THEN YES ELSE NO
)
status
(
" GThread:"
HAVE_GTHREAD THEN YES ELSE NO
)
status
(
" GThread :"
HAVE_GTHREAD THEN YES ELSE NO
)
status
(
" GtkGlExt:"
HAVE_GTKGLEXT THEN YES ELSE NO
)
endif
()
endif
()
endif
()
...
...
@@ -1773,11 +1785,11 @@ if(UNIX AND NOT APPLE)
endif
()
endif
()
elseif
(
APPLE
)
if
(
NOT IOS
)
status
(
" Video I/O:"
WITH_QUICKTIME THEN QuickTime ELSE QTKit
)
else
()
status
(
" Video I/O: AVFoundation"
)
endif
()
if
(
NOT IOS
)
status
(
" Video I/O:"
WITH_QUICKTIME THEN QuickTime ELSE QTKit
)
else
()
status
(
" Video I/O: AVFoundation"
)
endif
()
elseif
(
WIN32
)
status
(
" Video I/O:"
HAVE_VIDEOINPUT THEN DirectShow ELSE NO
)
endif
()
...
...
modules/highgui/src/precomp.hpp
View file @
2a4fb155
...
...
@@ -98,7 +98,7 @@ struct CvCapture
virtual
bool
setProperty
(
int
,
double
)
{
return
0
;
}
virtual
bool
grabFrame
()
{
return
true
;
}
virtual
IplImage
*
retrieveFrame
(
int
)
{
return
0
;
}
virtual
int
getCaptureDomain
()
{
return
CV_CAP_ANY
;
}
// Return the type of the capture object: CV_CAP_VFW, etc...
virtual
int
getCaptureDomain
()
{
return
CV_CAP_ANY
;
}
// Return the type of the capture object: CV_CAP_VFW, etc...
};
/*************************** CvVideoWriter structure ****************************/
...
...
@@ -176,7 +176,7 @@ CvCapture * cvCreateCameraCapture_PvAPI (const int index);
CvVideoWriter
*
cvCreateVideoWriter_GStreamer
(
const
char
*
filename
,
int
fourcc
,
double
fps
,
CvSize
frameSize
,
int
is_color
);
//Yannick Verdie 2010
//Yannick Verdie 2010
void
cvSetModeWindow_W32
(
const
char
*
name
,
double
prop_value
);
void
cvSetModeWindow_GTK
(
const
char
*
name
,
double
prop_value
);
void
cvSetModeWindow_CARBON
(
const
char
*
name
,
double
prop_value
);
...
...
@@ -186,8 +186,13 @@ double cvGetModeWindow_GTK(const char* name);
double
cvGetModeWindow_CARBON
(
const
char
*
name
);
double
cvGetPropWindowAutoSize_W32
(
const
char
*
name
);
double
cvGetPropWindowAutoSize_GTK
(
const
char
*
name
);
double
cvGetRatioWindow_W32
(
const
char
*
name
);
double
cvGetRatioWindow_GTK
(
const
char
*
name
);
double
cvGetOpenGlProp_W32
(
const
char
*
name
);
double
cvGetOpenGlProp_GTK
(
const
char
*
name
);
//for QT
#if defined (HAVE_QT)
...
...
modules/highgui/src/window.cpp
View file @
2a4fb155
...
...
@@ -49,13 +49,13 @@ CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_valu
{
//change between fullscreen or not.
case
CV_WND_PROP_FULLSCREEN
:
if
(
!
name
||
(
prop_value
!=
CV_WINDOW_NORMAL
&&
prop_value
!=
CV_WINDOW_FULLSCREEN
))
//bad argument
break
;
#if defined (HAVE_QT)
cvSetModeWindow_QT
(
name
,
prop_value
);
#elif defined WIN32 || defined _WIN32
#elif defined WIN32 || defined _WIN32
cvSetModeWindow_W32
(
name
,
prop_value
);
#elif defined (HAVE_GTK)
cvSetModeWindow_GTK
(
name
,
prop_value
);
...
...
@@ -63,19 +63,19 @@ CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_valu
cvSetModeWindow_CARBON
(
name
,
prop_value
);
#endif
break
;
case
CV_WND_PROP_AUTOSIZE
:
#if defined (HAVE_QT)
cvSetPropWindow_QT
(
name
,
prop_value
);
#endif
break
;
case
CV_WND_PROP_ASPECTRATIO
:
#if defined (HAVE_QT)
cvSetRatioWindow_QT
(
name
,
prop_value
);
#endif
break
;
default:
;
}
}
...
...
@@ -83,16 +83,16 @@ CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_valu
/* return -1 if error */
CV_IMPL
double
cvGetWindowProperty
(
const
char
*
name
,
int
prop_id
)
{
if
(
!
name
)
if
(
!
name
)
return
-
1
;
switch
(
prop_id
)
{
case
CV_WND_PROP_FULLSCREEN
:
case
CV_WND_PROP_FULLSCREEN
:
#if defined (HAVE_QT)
return
cvGetModeWindow_QT
(
name
);
#elif defined WIN32 || defined _WIN32
#elif defined WIN32 || defined _WIN32
return
cvGetModeWindow_W32
(
name
);
#elif defined (HAVE_GTK)
return
cvGetModeWindow_GTK
(
name
);
...
...
@@ -102,39 +102,45 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id)
return
-
1
;
#endif
break
;
case
CV_WND_PROP_AUTOSIZE
:
#if defined (HAVE_QT)
return
cvGetPropWindow_QT
(
name
);
#elif defined WIN32 || defined _WIN32
#elif defined WIN32 || defined _WIN32
return
cvGetPropWindowAutoSize_W32
(
name
);
#elif defined (HAVE_GTK)
return
cvGetPropWindowAutoSize_GTK
(
name
);
#else
return
-
1
;
#endif
#endif
break
;
case
CV_WND_PROP_ASPECTRATIO
:
#if defined (HAVE_QT)
return
cvGetRatioWindow_QT
(
name
);
#elif defined WIN32 || defined _WIN32
#elif defined WIN32 || defined _WIN32
return
cvGetRatioWindow_W32
(
name
);
#elif defined (HAVE_GTK)
return
cvGetRatioWindow_GTK
(
name
);
#else
return
-
1
;
#endif
#endif
break
;
case
CV_WND_PROP_OPENGL
:
#if defined (HAVE_QT)
#elif defined WIN32 || defined _WIN32
#elif defined WIN32 || defined _WIN32
return
cvGetOpenGlProp_W32
(
name
);
#elif defined (HAVE_GTK)
return
cvGetOpenGlProp_GTK
(
name
);
#else
return
-
1
;
#endif
#endif
break
;
default:
return
-
1
;
}
...
...
@@ -198,12 +204,12 @@ int cv::getTrackbarPos( const string& trackbarName, const string& winName )
{
return
cvGetTrackbarPos
(
trackbarName
.
c_str
(),
winName
.
c_str
());
}
void
cv
::
setMouseCallback
(
const
string
&
windowName
,
MouseCallback
onMouse
,
void
*
param
)
{
cvSetMouseCallback
(
windowName
.
c_str
(),
onMouse
,
param
);
}
int
cv
::
startWindowThread
()
{
return
cvStartWindowThread
();
...
...
@@ -363,13 +369,13 @@ namespace
addGlObj
(
glObj
);
icvSetOpenGlCleanCallback
(
winname
.
c_str
(),
glCleanCallback
,
glObj
);
}
}
setOpenGlDrawCallback
(
winname
,
glDrawTextureCallback
,
glObj
);
updateWindow
(
winname
);
}
}
}
#endif // HAVE_OPENGL
...
...
@@ -397,7 +403,7 @@ void cv::imshow( const string& winname, InputArray _img )
void
cv
::
imshow
(
const
string
&
winname
,
const
gpu
::
GlBuffer
&
buf
)
{
#ifndef HAVE_OPENGL
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
#else
imshowImpl
(
winname
,
buf
);
#endif
...
...
@@ -406,7 +412,7 @@ void cv::imshow(const string& winname, const gpu::GlBuffer& buf)
void
cv
::
imshow
(
const
string
&
winname
,
const
gpu
::
GpuMat
&
d_mat
)
{
#ifndef HAVE_OPENGL
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
#else
setOpenGlContext
(
winname
);
gpu
::
GlBuffer
buf
(
d_mat
,
gpu
::
GlBuffer
::
TEXTURE_BUFFER
);
...
...
@@ -417,7 +423,7 @@ void cv::imshow(const string& winname, const gpu::GpuMat& d_mat)
void
cv
::
imshow
(
const
string
&
winname
,
const
gpu
::
GlTexture
&
tex
)
{
#ifndef HAVE_OPENGL
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
#else
namedWindow
(
winname
,
WINDOW_OPENGL
|
WINDOW_AUTOSIZE
);
...
...
@@ -462,9 +468,9 @@ void cv::imshow(const string& winname, const gpu::GlTexture& tex)
}
void
cv
::
pointCloudShow
(
const
string
&
winname
,
const
gpu
::
GlCamera
&
camera
,
const
gpu
::
GlArrays
&
arr
)
{
{
#ifndef HAVE_OPENGL
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
#else
namedWindow
(
winname
,
WINDOW_OPENGL
);
...
...
@@ -565,27 +571,27 @@ namespace
#endif // HAVE_OPENGL
void
cv
::
pointCloudShow
(
const
string
&
winname
,
const
gpu
::
GlCamera
&
camera
,
const
gpu
::
GlBuffer
&
points
,
const
gpu
::
GlBuffer
&
colors
)
{
{
#ifndef HAVE_OPENGL
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
#else
pointCloudShowImpl
(
winname
,
camera
,
points
,
colors
);
#endif
}
void
cv
::
pointCloudShow
(
const
string
&
winname
,
const
gpu
::
GlCamera
&
camera
,
const
gpu
::
GpuMat
&
points
,
const
gpu
::
GpuMat
&
colors
)
{
{
#ifndef HAVE_OPENGL
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
#else
pointCloudShowImpl
(
winname
,
camera
,
points
,
colors
);
#endif
}
void
cv
::
pointCloudShow
(
const
string
&
winname
,
const
gpu
::
GlCamera
&
camera
,
InputArray
points
,
InputArray
colors
)
{
{
#ifndef HAVE_OPENGL
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
#else
pointCloudShowImpl
(
winname
,
camera
,
points
,
colors
);
#endif
...
...
@@ -596,23 +602,23 @@ void cv::pointCloudShow(const string& winname, const gpu::GlCamera& camera, Inpu
#ifndef HAVE_QT
CV_IMPL
void
cvCreateOpenGLCallback
(
const
char
*
,
CvOpenGLCallback
,
void
*
,
double
,
double
,
double
)
{
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
}
#endif
CV_IMPL
void
cvSetOpenGlContext
(
const
char
*
)
{
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
}
CV_IMPL
void
cvUpdateWindow
(
const
char
*
)
{
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
}
void
icvSetOpenGlCleanCallback
(
const
char
*
,
CvOpenGlCleanCallback
,
void
*
)
{
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
CV_Error
(
CV_OpenGlNotSupported
,
"The library is compiled without OpenGL support"
);
}
#endif // !HAVE_OPENGL
...
...
@@ -676,7 +682,7 @@ int cv::createButton(const string& button_name, ButtonCallback on_change, void*
#else
// No windowing system present at compile time ;-(
//
//
// We will build place holders that don't break the API but give an error
// at runtime. This way people can choose to replace an installed HighGUI
// version with a more capable one without a need to recompile dependent
...
...
@@ -695,7 +701,7 @@ CV_IMPL int cvNamedWindow( const char*, int )
{
CV_NO_GUI_ERROR
(
"cvNamedWindow"
);
return
-
1
;
}
}
CV_IMPL
void
cvDestroyWindow
(
const
char
*
)
{
...
...
@@ -763,7 +769,7 @@ CV_IMPL void* cvGetWindowHandle( const char* )
CV_NO_GUI_ERROR
(
"cvGetWindowHandle"
);
return
0
;
}
CV_IMPL
const
char
*
cvGetWindowName
(
void
*
)
{
CV_NO_GUI_ERROR
(
"cvGetWindowName"
);
...
...
@@ -799,39 +805,39 @@ CV_IMPL void cvAddText( const CvArr*, const char*, CvPoint org, CvFont* font)
CV_IMPL
void
cvDisplayStatusBar
(
const
char
*
name
,
const
char
*
arg2
,
int
arg3
)
{
CV_NO_GUI_ERROR
(
"cvDisplayStatusBar"
);
}
}
CV_IMPL
void
cvDisplayOverlay
(
const
char
*
name
,
const
char
*
text
,
int
delayms
)
{
CV_NO_GUI_ERROR
(
"cvNamedWindow"
);
}
}
CV_IMPL
int
cvStartLoop
(
int
(
*
pt2Func
)(
int
argc
,
char
*
argv
[]),
int
argc
,
char
*
argv
[])
{
CV_NO_GUI_ERROR
(
"cvStartLoop"
);
return
-
1
;
}
}
CV_IMPL
void
cvStopLoop
()
{
CV_NO_GUI_ERROR
(
"cvStopLoop"
);
}
}
CV_IMPL
void
cvSaveWindowParameters
(
const
char
*
name
)
{
CV_NO_GUI_ERROR
(
"cvSaveWindowParameters"
);
}
}
CV_IMPL
void
cvLoadWindowParameterss
(
const
char
*
name
)
{
CV_NO_GUI_ERROR
(
"cvLoadWindowParameters"
);
}
}
CV_IMPL
int
cvCreateButton
(
const
char
*
,
void
(
*
)(
int
,
void
*
),
void
*
,
int
,
int
)
{
CV_NO_GUI_ERROR
(
"cvCreateButton"
);
return
-
1
;
}
}
#endif
...
...
modules/highgui/src/window_gtk.cpp
View file @
2a4fb155
...
...
@@ -49,6 +49,12 @@
#include "gdk/gdkkeysyms.h"
#include <stdio.h>
#ifdef HAVE_OPENGL
#include <gtk/gtkgl.h>
#include <GL/gl.h>
#include <GL/glu.h>
#endif
/*#if _MSC_VER >= 1200
#pragma warning( disable: 4505 )
#pragma comment(lib,"gtk-win32-2.0.lib")
...
...
@@ -73,10 +79,10 @@ typedef struct _CvImageWidget CvImageWidget;
typedef
struct
_CvImageWidgetClass
CvImageWidgetClass
;
struct
_CvImageWidget
{
GtkWidget
widget
;
CvMat
*
original_image
;
CvMat
*
scaled_image
;
int
flags
;
GtkWidget
widget
;
CvMat
*
original_image
;
CvMat
*
scaled_image
;
int
flags
;
};
struct
_CvImageWidgetClass
...
...
@@ -107,31 +113,31 @@ static GtkWidgetClass * parent_class = NULL;
#define CV_WINDOW_NO_IMAGE 2
void
cvImageWidgetSetImage
(
CvImageWidget
*
widget
,
const
CvArr
*
arr
){
CvMat
*
mat
,
stub
;
int
origin
=
0
;
//printf("cvImageWidgetSetImage\n");
if
(
CV_IS_IMAGE_HDR
(
arr
))
origin
=
((
IplImage
*
)
arr
)
->
origin
;
mat
=
cvGetMat
(
arr
,
&
stub
);
if
(
widget
->
original_image
&&
!
CV_ARE_SIZES_EQ
(
mat
,
widget
->
original_image
)){
cvReleaseMat
(
&
widget
->
original_image
);
}
if
(
!
widget
->
original_image
){
widget
->
original_image
=
cvCreateMat
(
mat
->
rows
,
mat
->
cols
,
CV_8UC3
);
gtk_widget_queue_resize
(
GTK_WIDGET
(
widget
)
);
}
cvConvertImage
(
mat
,
widget
->
original_image
,
(
origin
!=
0
?
CV_CVTIMG_FLIP
:
0
)
+
CV_CVTIMG_SWAP_RB
);
if
(
widget
->
scaled_image
){
cvResize
(
widget
->
original_image
,
widget
->
scaled_image
,
CV_INTER_AREA
);
}
// window does not refresh without this
gtk_widget_queue_draw
(
GTK_WIDGET
(
widget
)
);
CvMat
*
mat
,
stub
;
int
origin
=
0
;
//printf("cvImageWidgetSetImage\n");
if
(
CV_IS_IMAGE_HDR
(
arr
))
origin
=
((
IplImage
*
)
arr
)
->
origin
;
mat
=
cvGetMat
(
arr
,
&
stub
);
if
(
widget
->
original_image
&&
!
CV_ARE_SIZES_EQ
(
mat
,
widget
->
original_image
)){
cvReleaseMat
(
&
widget
->
original_image
);
}
if
(
!
widget
->
original_image
){
widget
->
original_image
=
cvCreateMat
(
mat
->
rows
,
mat
->
cols
,
CV_8UC3
);
gtk_widget_queue_resize
(
GTK_WIDGET
(
widget
)
);
}
cvConvertImage
(
mat
,
widget
->
original_image
,
(
origin
!=
0
?
CV_CVTIMG_FLIP
:
0
)
+
CV_CVTIMG_SWAP_RB
);
if
(
widget
->
scaled_image
){
cvResize
(
widget
->
original_image
,
widget
->
scaled_image
,
CV_INTER_AREA
);
}
// window does not refresh without this
gtk_widget_queue_draw
(
GTK_WIDGET
(
widget
)
);
}
GtkWidget
*
...
...
@@ -196,61 +202,61 @@ static void
cvImageWidget_size_request
(
GtkWidget
*
widget
,
GtkRequisition
*
requisition
)
{
CvImageWidget
*
image_widget
=
CV_IMAGE_WIDGET
(
widget
);
//printf("cvImageWidget_size_request ");
// the case the first time cvShowImage called or when AUTOSIZE
if
(
image_widget
->
original_image
&&
((
image_widget
->
flags
&
CV_WINDOW_AUTOSIZE
)
||
(
image_widget
->
flags
&
CV_WINDOW_NO_IMAGE
)))
{
//printf("original ");
requisition
->
width
=
image_widget
->
original_image
->
cols
;
requisition
->
height
=
image_widget
->
original_image
->
rows
;
}
// default case
else
if
(
image_widget
->
scaled_image
){
//printf("scaled ");
requisition
->
width
=
image_widget
->
scaled_image
->
cols
;
requisition
->
height
=
image_widget
->
scaled_image
->
rows
;
}
// the case before cvShowImage called
else
{
//printf("default ");
requisition
->
width
=
320
;
requisition
->
height
=
240
;
}
//printf("%d %d\n",requisition->width, requisition->height);
CvImageWidget
*
image_widget
=
CV_IMAGE_WIDGET
(
widget
);
//printf("cvImageWidget_size_request ");
// the case the first time cvShowImage called or when AUTOSIZE
if
(
image_widget
->
original_image
&&
((
image_widget
->
flags
&
CV_WINDOW_AUTOSIZE
)
||
(
image_widget
->
flags
&
CV_WINDOW_NO_IMAGE
)))
{
//printf("original ");
requisition
->
width
=
image_widget
->
original_image
->
cols
;
requisition
->
height
=
image_widget
->
original_image
->
rows
;
}
// default case
else
if
(
image_widget
->
scaled_image
){
//printf("scaled ");
requisition
->
width
=
image_widget
->
scaled_image
->
cols
;
requisition
->
height
=
image_widget
->
scaled_image
->
rows
;
}
// the case before cvShowImage called
else
{
//printf("default ");
requisition
->
width
=
320
;
requisition
->
height
=
240
;
}
//printf("%d %d\n",requisition->width, requisition->height);
}
static
void
cvImageWidget_set_size
(
GtkWidget
*
widget
,
int
max_width
,
int
max_height
){
CvImageWidget
*
image_widget
=
CV_IMAGE_WIDGET
(
widget
);
CvImageWidget
*
image_widget
=
CV_IMAGE_WIDGET
(
widget
);
//printf("cvImageWidget_set_size %d %d\n", max_width, max_height);
//printf("cvImageWidget_set_size %d %d\n", max_width, max_height);
// don't allow to set the size
if
(
image_widget
->
flags
&
CV_WINDOW_AUTOSIZE
)
return
;
if
(
!
image_widget
->
original_image
)
return
;
// don't allow to set the size
if
(
image_widget
->
flags
&
CV_WINDOW_AUTOSIZE
)
return
;
if
(
!
image_widget
->
original_image
)
return
;
CvSize
scaled_image_size
=
cvImageWidget_calc_size
(
image_widget
->
original_image
->
cols
,
image_widget
->
original_image
->
rows
,
max_width
,
max_height
);
CvSize
scaled_image_size
=
cvImageWidget_calc_size
(
image_widget
->
original_image
->
cols
,
image_widget
->
original_image
->
rows
,
max_width
,
max_height
);
if
(
image_widget
->
scaled_image
&&
(
image_widget
->
scaled_image
->
cols
!=
scaled_image_size
.
width
||
image_widget
->
scaled_image
->
rows
!=
scaled_image_size
.
height
))
{
cvReleaseMat
(
&
image_widget
->
scaled_image
);
}
if
(
!
image_widget
->
scaled_image
){
image_widget
->
scaled_image
=
cvCreateMat
(
scaled_image_size
.
height
,
scaled_image_size
.
width
,
CV_8UC3
);
if
(
image_widget
->
scaled_image
&&
(
image_widget
->
scaled_image
->
cols
!=
scaled_image_size
.
width
||
image_widget
->
scaled_image
->
rows
!=
scaled_image_size
.
height
))
{
cvReleaseMat
(
&
image_widget
->
scaled_image
);
}
if
(
!
image_widget
->
scaled_image
){
image_widget
->
scaled_image
=
cvCreateMat
(
scaled_image_size
.
height
,
scaled_image_size
.
width
,
CV_8UC3
);
}
assert
(
image_widget
->
scaled_image
);
}
assert
(
image_widget
->
scaled_image
);
}
static
void
cvImageWidget_size_allocate
(
GtkWidget
*
widget
,
cvImageWidget_size_allocate
(
GtkWidget
*
widget
,
GtkAllocation
*
allocation
)
{
CvImageWidget
*
image_widget
;
...
...
@@ -265,82 +271,43 @@ cvImageWidget_size_allocate (GtkWidget *widget,
if
(
(
image_widget
->
flags
&
CV_WINDOW_AUTOSIZE
)
==
0
&&
image_widget
->
original_image
){
// (re) allocated scaled image
if
(
image_widget
->
flags
&
CV_WINDOW_NO_IMAGE
){
cvImageWidget_set_size
(
widget
,
image_widget
->
original_image
->
cols
,
image_widget
->
original_image
->
rows
);
}
else
{
cvImageWidget_set_size
(
widget
,
allocation
->
width
,
allocation
->
height
);
}
cvResize
(
image_widget
->
original_image
,
image_widget
->
scaled_image
,
CV_INTER_AREA
);
// (re) allocated scaled image
if
(
image_widget
->
flags
&
CV_WINDOW_NO_IMAGE
){
cvImageWidget_set_size
(
widget
,
image_widget
->
original_image
->
cols
,
image_widget
->
original_image
->
rows
);
}
else
{
cvImageWidget_set_size
(
widget
,
allocation
->
width
,
allocation
->
height
);
}
cvResize
(
image_widget
->
original_image
,
image_widget
->
scaled_image
,
CV_INTER_AREA
);
}
if
(
GTK_WIDGET_REALIZED
(
widget
))
{
image_widget
=
CV_IMAGE_WIDGET
(
widget
);
if
(
image_widget
->
original_image
&&
((
image_widget
->
flags
&
CV_WINDOW_AUTOSIZE
)
||
(
image_widget
->
flags
&
CV_WINDOW_NO_IMAGE
))
)
{
widget
->
allocation
.
width
=
image_widget
->
original_image
->
cols
;
widget
->
allocation
.
height
=
image_widget
->
original_image
->
rows
;
gdk_window_move_resize
(
widget
->
window
,
allocation
->
x
,
allocation
->
y
,
image_widget
->
original_image
->
cols
,
image_widget
->
original_image
->
rows
);
if
(
image_widget
->
flags
&
CV_WINDOW_NO_IMAGE
){
image_widget
->
flags
&=
~
CV_WINDOW_NO_IMAGE
;
gtk_widget_queue_resize
(
GTK_WIDGET
(
widget
)
);
}
}
else
{
gdk_window_move_resize
(
widget
->
window
,
allocation
->
x
,
allocation
->
y
,
allocation
->
width
,
allocation
->
height
);
}
if
(
image_widget
->
original_image
&&
((
image_widget
->
flags
&
CV_WINDOW_AUTOSIZE
)
||
(
image_widget
->
flags
&
CV_WINDOW_NO_IMAGE
))
)
{
widget
->
allocation
.
width
=
image_widget
->
original_image
->
cols
;
widget
->
allocation
.
height
=
image_widget
->
original_image
->
rows
;
gdk_window_move_resize
(
widget
->
window
,
allocation
->
x
,
allocation
->
y
,
image_widget
->
original_image
->
cols
,
image_widget
->
original_image
->
rows
);
if
(
image_widget
->
flags
&
CV_WINDOW_NO_IMAGE
){
image_widget
->
flags
&=
~
CV_WINDOW_NO_IMAGE
;
gtk_widget_queue_resize
(
GTK_WIDGET
(
widget
)
);
}
}
else
{
gdk_window_move_resize
(
widget
->
window
,
allocation
->
x
,
allocation
->
y
,
allocation
->
width
,
allocation
->
height
);
}
}
}
static
gboolean
cvImageWidget_expose
(
GtkWidget
*
widget
,
GdkEventExpose
*
event
)
{
CvImageWidget
*
image_widget
;
g_return_val_if_fail
(
widget
!=
NULL
,
FALSE
);
g_return_val_if_fail
(
CV_IS_IMAGE_WIDGET
(
widget
),
FALSE
);
g_return_val_if_fail
(
event
!=
NULL
,
FALSE
);
if
(
event
->
count
>
0
)
return
FALSE
;
image_widget
=
CV_IMAGE_WIDGET
(
widget
);
gdk_window_clear_area
(
widget
->
window
,
0
,
0
,
widget
->
allocation
.
width
,
widget
->
allocation
.
height
);
if
(
image_widget
->
scaled_image
){
// center image in available region
int
x0
=
(
widget
->
allocation
.
width
-
image_widget
->
scaled_image
->
cols
)
/
2
;
int
y0
=
(
widget
->
allocation
.
height
-
image_widget
->
scaled_image
->
rows
)
/
2
;
gdk_draw_rgb_image
(
widget
->
window
,
widget
->
style
->
fg_gc
[
GTK_STATE_NORMAL
],
x0
,
y0
,
MIN
(
image_widget
->
scaled_image
->
cols
,
widget
->
allocation
.
width
),
MIN
(
image_widget
->
scaled_image
->
rows
,
widget
->
allocation
.
height
),
GDK_RGB_DITHER_MAX
,
image_widget
->
scaled_image
->
data
.
ptr
,
image_widget
->
scaled_image
->
step
);
}
else
if
(
image_widget
->
original_image
){
gdk_draw_rgb_image
(
widget
->
window
,
widget
->
style
->
fg_gc
[
GTK_STATE_NORMAL
],
0
,
0
,
MIN
(
image_widget
->
original_image
->
cols
,
widget
->
allocation
.
width
),
MIN
(
image_widget
->
original_image
->
rows
,
widget
->
allocation
.
height
),
GDK_RGB_DITHER_MAX
,
image_widget
->
original_image
->
data
.
ptr
,
image_widget
->
original_image
->
step
);
}
return
TRUE
;
}
static
void
cvImageWidget_destroy
(
GtkObject
*
object
)
{
...
...
@@ -371,7 +338,6 @@ static void cvImageWidget_class_init (CvImageWidgetClass * klass)
object_class
->
destroy
=
cvImageWidget_destroy
;
widget_class
->
realize
=
cvImageWidget_realize
;
widget_class
->
expose_event
=
cvImageWidget_expose
;
widget_class
->
size_request
=
cvImageWidget_size_request
;
widget_class
->
size_allocate
=
cvImageWidget_size_allocate
;
widget_class
->
button_press_event
=
NULL
;
...
...
@@ -382,9 +348,9 @@ static void cvImageWidget_class_init (CvImageWidgetClass * klass)
static
void
cvImageWidget_init
(
CvImageWidget
*
image_widget
)
{
image_widget
->
original_image
=
0
;
image_widget
->
scaled_image
=
0
;
image_widget
->
flags
=
0
;
image_widget
->
original_image
=
0
;
image_widget
->
scaled_image
=
0
;
image_widget
->
flags
=
0
;
}
GtkType
cvImageWidget_get_type
(
void
){
...
...
@@ -444,7 +410,7 @@ typedef struct CvWindow
int
last_key
;
int
flags
;
int
status
;
//0 normal, 1 fullscreen (YV)
int
status
;
//0 normal, 1 fullscreen (YV)
CvMouseCallback
on_mouse
;
void
*
on_mouse_param
;
...
...
@@ -456,6 +422,16 @@ typedef struct CvWindow
CvTrackbar
*
first
;
}
toolbar
;
#ifdef HAVE_OPENGL
bool
useGl
;
CvOpenGLCallback
glDrawCallback
;
void
*
glDrawData
;
CvOpenGlCleanCallback
glCleanCallback
;
void
*
glCleanData
;
#endif
}
CvWindow
;
...
...
@@ -488,6 +464,11 @@ CV_IMPL int cvInitSystem( int argc, char** argv )
hg_windows
=
0
;
gtk_init
(
&
argc
,
&
argv
);
#ifdef HAVE_OPENGL
gtk_gl_init
(
&
argc
,
&
argv
);
#endif
wasInitialized
=
1
;
}
...
...
@@ -496,25 +477,25 @@ CV_IMPL int cvInitSystem( int argc, char** argv )
CV_IMPL
int
cvStartWindowThread
(){
#ifdef HAVE_GTHREAD
cvInitSystem
(
0
,
NULL
);
cvInitSystem
(
0
,
NULL
);
if
(
!
thread_started
)
{
if
(
!
g_thread_supported
())
{
/* the GThread system wasn't inited, so init it */
g_thread_init
(
NULL
);
}
if
(
!
g_thread_supported
())
{
/* the GThread system wasn't inited, so init it */
g_thread_init
(
NULL
);
}
// this mutex protects the window resources
window_mutex
=
g_mutex_new
();
// this mutex protects the window resources
window_mutex
=
g_mutex_new
();
// protects the 'last key pressed' variable
last_key_mutex
=
g_mutex_new
();
// protects the 'last key pressed' variable
last_key_mutex
=
g_mutex_new
();
// conditional that indicates a key has been pressed
cond_have_key
=
g_cond_new
();
// conditional that indicates a key has been pressed
cond_have_key
=
g_cond_new
();
// this is the window update thread
window_thread
=
g_thread_create
((
GThreadFunc
)
icvWindowThreadLoop
,
NULL
,
TRUE
,
NULL
);
// this is the window update thread
window_thread
=
g_thread_create
((
GThreadFunc
)
icvWindowThreadLoop
,
NULL
,
TRUE
,
NULL
);
}
thread_started
=
window_thread
!=
NULL
;
return
thread_started
;
...
...
@@ -525,17 +506,17 @@ CV_IMPL int cvStartWindowThread(){
#ifdef HAVE_GTHREAD
gpointer
icvWindowThreadLoop
(){
while
(
1
){
g_mutex_lock
(
window_mutex
);
gtk_main_iteration_do
(
FALSE
);
g_mutex_unlock
(
window_mutex
);
while
(
1
){
g_mutex_lock
(
window_mutex
);
gtk_main_iteration_do
(
FALSE
);
g_mutex_unlock
(
window_mutex
);
// little sleep
g_usleep
(
500
);
// little sleep
g_usleep
(
500
);
g_thread_yield
();
}
return
NULL
;
g_thread_yield
();
}
return
NULL
;
}
#define CV_LOCK_MUTEX() \
...
...
@@ -571,34 +552,34 @@ static CvWindow* icvWindowByWidget( GtkWidget* widget )
double
cvGetModeWindow_GTK
(
const
char
*
name
)
//YV
{
double
result
=
-
1
;
CV_FUNCNAME
(
"cvGetModeWindow_GTK"
);
double
result
=
-
1
;
CV_FUNCNAME
(
"cvGetModeWindow_GTK"
);
__BEGIN__
;
CvWindow
*
window
;
if
(
!
name
)
if
(
!
name
)
CV_ERROR
(
CV_StsNullPtr
,
"NULL name string"
);
window
=
icvFindWindowByName
(
name
);
if
(
!
window
)
if
(
!
window
)
CV_ERROR
(
CV_StsNullPtr
,
"NULL window"
);
CV_LOCK_MUTEX
();
CV_LOCK_MUTEX
();
result
=
window
->
status
;
CV_UNLOCK_MUTEX
();
CV_UNLOCK_MUTEX
();
__END__
;
return
result
;
return
result
;
}
void
cvSetModeWindow_GTK
(
const
char
*
name
,
double
prop_value
)
//Yannick Verdie
{
CV_FUNCNAME
(
"cvSetModeWindow_GTK"
);
CV_FUNCNAME
(
"cvSetModeWindow_GTK"
);
__BEGIN__
;
...
...
@@ -611,30 +592,417 @@ void cvSetModeWindow_GTK( const char* name, double prop_value)//Yannick Verdie
if
(
!
window
)
CV_ERROR
(
CV_StsNullPtr
,
"NULL window"
);
if
(
window
->
flags
&
CV_WINDOW_AUTOSIZE
)
//if the flag CV_WINDOW_AUTOSIZE is set
if
(
window
->
flags
&
CV_WINDOW_AUTOSIZE
)
//if the flag CV_WINDOW_AUTOSIZE is set
EXIT
;
//so easy to do fullscreen here, Linux rocks !
if
(
window
->
status
==
CV_WINDOW_FULLSCREEN
&&
prop_value
==
CV_WINDOW_NORMAL
)
{
CV_LOCK_MUTEX
();
gtk_window_unfullscreen
(
GTK_WINDOW
(
window
->
frame
));
window
->
status
=
CV_WINDOW_NORMAL
;
CV_UNLOCK_MUTEX
();
EXIT
;
}
if
(
window
->
status
==
CV_WINDOW_NORMAL
&&
prop_value
==
CV_WINDOW_FULLSCREEN
)
{
CV_LOCK_MUTEX
();
gtk_window_fullscreen
(
GTK_WINDOW
(
window
->
frame
));
window
->
status
=
CV_WINDOW_FULLSCREEN
;
CV_UNLOCK_MUTEX
();
EXIT
;
}
__END__
;
}
double
cvGetPropWindowAutoSize_GTK
(
const
char
*
name
)
{
double
result
=
-
1
;
CV_FUNCNAME
(
"cvGetPropWindowAutoSize_GTK"
);
//so easy to do fullscreen here, Linux rocks !
if
(
window
->
status
==
CV_WINDOW_FULLSCREEN
&&
prop_value
==
CV_WINDOW_NORMAL
)
{
CV_LOCK_MUTEX
();
gtk_window_unfullscreen
(
GTK_WINDOW
(
window
->
frame
));
window
->
status
=
CV_WINDOW_NORMAL
;
CV_UNLOCK_MUTEX
();
EXIT
;
}
if
(
window
->
status
==
CV_WINDOW_NORMAL
&&
prop_value
==
CV_WINDOW_FULLSCREEN
)
{
CV_LOCK_MUTEX
();
gtk_window_fullscreen
(
GTK_WINDOW
(
window
->
frame
));
window
->
status
=
CV_WINDOW_FULLSCREEN
;
CV_UNLOCK_MUTEX
();
EXIT
;
}
__BEGIN__
;
CvWindow
*
window
;
if
(
!
name
)
CV_ERROR
(
CV_StsNullPtr
,
"NULL name string"
);
window
=
icvFindWindowByName
(
name
);
if
(
!
window
)
EXIT
;
// keep silence here
result
=
window
->
flags
&
CV_WINDOW_AUTOSIZE
;
__END__
;
return
result
;
}
double
cvGetRatioWindow_GTK
(
const
char
*
name
)
{
double
result
=
-
1
;
CV_FUNCNAME
(
"cvGetRatioWindow_GTK"
);
__BEGIN__
;
CvWindow
*
window
;
if
(
!
name
)
CV_ERROR
(
CV_StsNullPtr
,
"NULL name string"
);
window
=
icvFindWindowByName
(
name
);
if
(
!
window
)
EXIT
;
// keep silence here
result
=
static_cast
<
double
>
(
window
->
widget
->
allocation
.
width
)
/
window
->
widget
->
allocation
.
height
;
__END__
;
return
result
;
}
double
cvGetOpenGlProp_GTK
(
const
char
*
name
)
{
double
result
=
-
1
;
#ifdef HAVE_OPENGL
CV_FUNCNAME
(
"cvGetOpenGlProp_GTK"
);
__BEGIN__
;
CvWindow
*
window
;
if
(
!
name
)
CV_ERROR
(
CV_StsNullPtr
,
"NULL name string"
);
window
=
icvFindWindowByName
(
name
);
if
(
!
window
)
EXIT
;
// keep silence here
result
=
window
->
useGl
;
__END__
;
#endif
return
result
;
}
// OpenGL support
#ifdef HAVE_OPENGL
namespace
{
class
GlFuncTab_GTK
:
public
cv
::
gpu
::
GlFuncTab
{
public
:
PFNGLGENBUFFERSPROC
glGenBuffersExt
;
PFNGLDELETEBUFFERSPROC
glDeleteBuffersExt
;
PFNGLBUFFERDATAPROC
glBufferDataExt
;
PFNGLBUFFERSUBDATAPROC
glBufferSubDataExt
;
PFNGLBINDBUFFERPROC
glBindBufferExt
;
PFNGLMAPBUFFERPROC
glMapBufferExt
;
PFNGLUNMAPBUFFERPROC
glUnmapBufferExt
;
bool
initialized
;
GlFuncTab_GTK
()
{
glGenBuffersExt
=
0
;
glDeleteBuffersExt
=
0
;
glBufferDataExt
=
0
;
glBufferSubDataExt
=
0
;
glBindBufferExt
=
0
;
glMapBufferExt
=
0
;
glUnmapBufferExt
=
0
;
initialized
=
false
;
}
void
genBuffers
(
int
n
,
unsigned
int
*
buffers
)
const
{
CV_FUNCNAME
(
"genBuffers"
);
__BEGIN__
;
if
(
!
glGenBuffersExt
)
CV_ERROR
(
CV_OpenGlApiCallError
,
"Current OpenGL implementation doesn't support required extension"
);
glGenBuffersExt
(
n
,
buffers
);
CV_CheckGlError
();
__END__
;
}
void
deleteBuffers
(
int
n
,
const
unsigned
int
*
buffers
)
const
{
CV_FUNCNAME
(
"deleteBuffers"
);
__BEGIN__
;
if
(
!
glDeleteBuffersExt
)
CV_ERROR
(
CV_OpenGlApiCallError
,
"Current OpenGL implementation doesn't support required extension"
);
glDeleteBuffersExt
(
n
,
buffers
);
CV_CheckGlError
();
__END__
;
}
void
bufferData
(
unsigned
int
target
,
ptrdiff_t
size
,
const
void
*
data
,
unsigned
int
usage
)
const
{
CV_FUNCNAME
(
"bufferData"
);
__BEGIN__
;
if
(
!
glBufferDataExt
)
CV_ERROR
(
CV_OpenGlApiCallError
,
"Current OpenGL implementation doesn't support required extension"
);
glBufferDataExt
(
target
,
size
,
data
,
usage
);
CV_CheckGlError
();
__END__
;
}
void
bufferSubData
(
unsigned
int
target
,
ptrdiff_t
offset
,
ptrdiff_t
size
,
const
void
*
data
)
const
{
CV_FUNCNAME
(
"bufferSubData"
);
__BEGIN__
;
if
(
!
glBufferSubDataExt
)
CV_ERROR
(
CV_OpenGlApiCallError
,
"Current OpenGL implementation doesn't support required extension"
);
glBufferSubDataExt
(
target
,
offset
,
size
,
data
);
CV_CheckGlError
();
__END__
;
}
void
bindBuffer
(
unsigned
int
target
,
unsigned
int
buffer
)
const
{
CV_FUNCNAME
(
"bindBuffer"
);
__BEGIN__
;
if
(
!
glBindBufferExt
)
CV_ERROR
(
CV_OpenGlApiCallError
,
"Current OpenGL implementation doesn't support required extension"
);
glBindBufferExt
(
target
,
buffer
);
CV_CheckGlError
();
__END__
;
}
void
*
mapBuffer
(
unsigned
int
target
,
unsigned
int
access
)
const
{
CV_FUNCNAME
(
"mapBuffer"
);
void
*
res
=
0
;
__BEGIN__
;
if
(
!
glMapBufferExt
)
CV_ERROR
(
CV_OpenGlApiCallError
,
"Current OpenGL implementation doesn't support required extension"
);
res
=
glMapBufferExt
(
target
,
access
);
CV_CheckGlError
();
__END__
;
return
res
;
}
void
unmapBuffer
(
unsigned
int
target
)
const
{
CV_FUNCNAME
(
"unmapBuffer"
);
__BEGIN__
;
if
(
!
glUnmapBufferExt
)
CV_ERROR
(
CV_OpenGlApiCallError
,
"Current OpenGL implementation doesn't support required extension"
);
glUnmapBufferExt
(
target
);
CV_CheckGlError
();
__END__
;
}
bool
isGlContextInitialized
()
const
{
return
initialized
;
}
};
void
initGl
()
{
static
GlFuncTab_GTK
glFuncTab
;
static
bool
first
=
true
;
if
(
first
)
{
// Load extensions
GdkGLProc
func
;
func
=
gdk_gl_get_proc_address
(
"glGenBuffers"
);
glFuncTab
.
glGenBuffersExt
=
(
PFNGLGENBUFFERSPROC
)
func
;
func
=
gdk_gl_get_proc_address
(
"glDeleteBuffers"
);
glFuncTab
.
glDeleteBuffersExt
=
(
PFNGLDELETEBUFFERSPROC
)
func
;
func
=
gdk_gl_get_proc_address
(
"glBufferData"
);
glFuncTab
.
glBufferDataExt
=
(
PFNGLBUFFERDATAPROC
)
func
;
func
=
gdk_gl_get_proc_address
(
"glBufferSubData"
);
glFuncTab
.
glBufferSubDataExt
=
(
PFNGLBUFFERSUBDATAPROC
)
func
;
func
=
gdk_gl_get_proc_address
(
"glBindBuffer"
);
glFuncTab
.
glBindBufferExt
=
(
PFNGLBINDBUFFERPROC
)
func
;
func
=
gdk_gl_get_proc_address
(
"glMapBuffer"
);
glFuncTab
.
glMapBufferExt
=
(
PFNGLMAPBUFFERPROC
)
func
;
func
=
gdk_gl_get_proc_address
(
"glUnmapBuffer"
);
glFuncTab
.
glUnmapBufferExt
=
(
PFNGLUNMAPBUFFERPROC
)
func
;
glFuncTab
.
initialized
=
true
;
cv
::
gpu
::
setGlFuncTab
(
&
glFuncTab
);
first
=
false
;
}
}
void
createGlContext
(
CvWindow
*
window
)
{
GdkGLConfig
*
glconfig
;
CV_FUNCNAME
(
"createGlContext"
);
__BEGIN__
;
window
->
useGl
=
false
;
// Try double-buffered visual
glconfig
=
gdk_gl_config_new_by_mode
((
GdkGLConfigMode
)(
GDK_GL_MODE_RGB
|
GDK_GL_MODE_DEPTH
|
GDK_GL_MODE_DOUBLE
));
if
(
!
glconfig
)
CV_ERROR
(
CV_OpenGlApiCallError
,
"Can't Create A GL Device Context"
);
// Set OpenGL-capability to the widget
if
(
!
gtk_widget_set_gl_capability
(
window
->
widget
,
glconfig
,
NULL
,
TRUE
,
GDK_GL_RGBA_TYPE
))
CV_ERROR
(
CV_OpenGlApiCallError
,
"Can't Create A GL Device Context"
);
initGl
();
window
->
useGl
=
true
;
__END__
;
}
void
releaseGlContext
(
CvWindow
*
window
)
{
CV_FUNCNAME
(
"releaseGlContext"
);
__BEGIN__
;
window
->
useGl
=
false
;
__END__
;
}
void
drawGl
(
CvWindow
*
window
)
{
CV_FUNCNAME
(
"drawGl"
);
__BEGIN__
;
GdkGLContext
*
glcontext
=
gtk_widget_get_gl_context
(
window
->
widget
);
GdkGLDrawable
*
gldrawable
=
gtk_widget_get_gl_drawable
(
window
->
widget
);
if
(
!
gdk_gl_drawable_gl_begin
(
gldrawable
,
glcontext
))
CV_ERROR
(
CV_OpenGlApiCallError
,
"Can't Activate The GL Rendering Context"
);
glViewport
(
0
,
0
,
window
->
widget
->
allocation
.
width
,
window
->
widget
->
allocation
.
height
);
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
if
(
window
->
glDrawCallback
)
window
->
glDrawCallback
(
window
->
glDrawData
);
CV_CheckGlError
();
if
(
gdk_gl_drawable_is_double_buffered
(
gldrawable
))
gdk_gl_drawable_swap_buffers
(
gldrawable
);
else
glFlush
();
gdk_gl_drawable_gl_end
(
gldrawable
);
__END__
;
}
}
#endif // HAVE_OPENGL
static
gboolean
cvImageWidget_expose
(
GtkWidget
*
widget
,
GdkEventExpose
*
event
,
gpointer
data
)
{
#ifdef HAVE_OPENGL
CvWindow
*
window
=
(
CvWindow
*
)
data
;
if
(
window
->
useGl
)
{
drawGl
(
window
);
return
TRUE
;
}
#endif
CvImageWidget
*
image_widget
;
g_return_val_if_fail
(
widget
!=
NULL
,
FALSE
);
g_return_val_if_fail
(
CV_IS_IMAGE_WIDGET
(
widget
),
FALSE
);
g_return_val_if_fail
(
event
!=
NULL
,
FALSE
);
if
(
event
->
count
>
0
)
return
FALSE
;
image_widget
=
CV_IMAGE_WIDGET
(
widget
);
gdk_window_clear_area
(
widget
->
window
,
0
,
0
,
widget
->
allocation
.
width
,
widget
->
allocation
.
height
);
if
(
image_widget
->
scaled_image
){
// center image in available region
int
x0
=
(
widget
->
allocation
.
width
-
image_widget
->
scaled_image
->
cols
)
/
2
;
int
y0
=
(
widget
->
allocation
.
height
-
image_widget
->
scaled_image
->
rows
)
/
2
;
gdk_draw_rgb_image
(
widget
->
window
,
widget
->
style
->
fg_gc
[
GTK_STATE_NORMAL
],
x0
,
y0
,
MIN
(
image_widget
->
scaled_image
->
cols
,
widget
->
allocation
.
width
),
MIN
(
image_widget
->
scaled_image
->
rows
,
widget
->
allocation
.
height
),
GDK_RGB_DITHER_MAX
,
image_widget
->
scaled_image
->
data
.
ptr
,
image_widget
->
scaled_image
->
step
);
}
else
if
(
image_widget
->
original_image
){
gdk_draw_rgb_image
(
widget
->
window
,
widget
->
style
->
fg_gc
[
GTK_STATE_NORMAL
],
0
,
0
,
MIN
(
image_widget
->
original_image
->
cols
,
widget
->
allocation
.
width
),
MIN
(
image_widget
->
original_image
->
rows
,
widget
->
allocation
.
height
),
GDK_RGB_DITHER_MAX
,
image_widget
->
original_image
->
data
.
ptr
,
image_widget
->
original_image
->
step
);
}
return
TRUE
;
}
CV_IMPL
int
cvNamedWindow
(
const
char
*
name
,
int
flags
)
...
...
@@ -673,7 +1041,7 @@ CV_IMPL int cvNamedWindow( const char* name, int flags )
window
->
prev
=
0
;
window
->
status
=
CV_WINDOW_NORMAL
;
//YV
CV_LOCK_MUTEX
();
CV_LOCK_MUTEX
();
window
->
frame
=
gtk_window_new
(
GTK_WINDOW_TOPLEVEL
);
...
...
@@ -683,9 +1051,18 @@ CV_IMPL int cvNamedWindow( const char* name, int flags )
gtk_widget_show
(
window
->
widget
);
gtk_container_add
(
GTK_CONTAINER
(
window
->
frame
),
window
->
paned
);
gtk_widget_show
(
window
->
paned
);
//
// configure event handlers
// TODO -- move this to CvImageWidget ?
#ifndef HAVE_OPENGL
if
(
flags
&
CV_WINDOW_OPENGL
)
CV_ERROR
(
CV_OpenGlNotSupported
,
"Library was built without OpenGL support"
);
#else
if
(
flags
&
CV_WINDOW_OPENGL
)
createGlContext
(
window
);
#endif
//
// configure event handlers
// TODO -- move this to CvImageWidget ?
gtk_signal_connect
(
GTK_OBJECT
(
window
->
frame
),
"key-press-event"
,
GTK_SIGNAL_FUNC
(
icvOnKeyPress
),
window
);
gtk_signal_connect
(
GTK_OBJECT
(
window
->
widget
),
"button-press-event"
,
...
...
@@ -696,9 +1073,10 @@ CV_IMPL int cvNamedWindow( const char* name, int flags )
GTK_SIGNAL_FUNC
(
icvOnMouse
),
window
);
gtk_signal_connect
(
GTK_OBJECT
(
window
->
frame
),
"delete-event"
,
GTK_SIGNAL_FUNC
(
icvOnClose
),
window
);
gtk_signal_connect
(
GTK_OBJECT
(
window
->
widget
),
"expose-event"
,
GTK_SIGNAL_FUNC
(
cvImageWidget_expose
),
window
);
gtk_widget_add_events
(
window
->
widget
,
GDK_EXPOSURE_MASK
|
GDK_BUTTON_RELEASE_MASK
|
GDK_BUTTON_PRESS_MASK
|
GDK_POINTER_MOTION_MASK
)
;
gtk_widget_add_events
(
window
->
widget
,
GDK_BUTTON_RELEASE_MASK
|
GDK_BUTTON_PRESS_MASK
|
GDK_POINTER_MOTION_MASK
)
;
gtk_widget_show
(
window
->
frame
);
gtk_window_set_title
(
GTK_WINDOW
(
window
->
frame
),
name
);
...
...
@@ -710,16 +1088,21 @@ CV_IMPL int cvNamedWindow( const char* name, int flags )
gtk_window_set_resizable
(
GTK_WINDOW
(
window
->
frame
),
(
flags
&
CV_WINDOW_AUTOSIZE
)
==
0
);
// allow window to be resized
if
(
(
flags
&
CV_WINDOW_AUTOSIZE
)
==
0
){
GdkGeometry
geometry
;
geometry
.
min_width
=
50
;
geometry
.
min_height
=
50
;
gtk_window_set_geometry_hints
(
GTK_WINDOW
(
window
->
frame
),
GTK_WIDGET
(
window
->
widget
),
&
geometry
,
(
GdkWindowHints
)
(
GDK_HINT_MIN_SIZE
));
}
// allow window to be resized
if
(
(
flags
&
CV_WINDOW_AUTOSIZE
)
==
0
){
GdkGeometry
geometry
;
geometry
.
min_width
=
50
;
geometry
.
min_height
=
50
;
gtk_window_set_geometry_hints
(
GTK_WINDOW
(
window
->
frame
),
GTK_WIDGET
(
window
->
widget
),
&
geometry
,
(
GdkWindowHints
)
(
GDK_HINT_MIN_SIZE
));
}
CV_UNLOCK_MUTEX
();
CV_UNLOCK_MUTEX
();
#ifdef HAVE_OPENGL
if
(
window
->
useGl
)
cvSetOpenGlContext
(
name
);
#endif
result
=
1
;
__END__
;
...
...
@@ -728,10 +1111,144 @@ CV_IMPL int cvNamedWindow( const char* name, int flags )
}
#ifdef HAVE_OPENGL
CV_IMPL
void
cvSetOpenGlContext
(
const
char
*
name
)
{
CvWindow
*
window
;
GdkGLContext
*
glcontext
;
GdkGLDrawable
*
gldrawable
;
CV_FUNCNAME
(
"cvSetOpenGlContext"
);
__BEGIN__
;
if
(
!
name
)
CV_ERROR
(
CV_StsNullPtr
,
"NULL name string"
);
window
=
icvFindWindowByName
(
name
);
if
(
!
window
)
CV_ERROR
(
CV_StsNullPtr
,
"NULL window"
);
if
(
!
window
->
useGl
)
CV_ERROR
(
CV_OpenGlNotSupported
,
"Window doesn't support OpenGL"
);
glcontext
=
gtk_widget_get_gl_context
(
window
->
widget
);
gldrawable
=
gtk_widget_get_gl_drawable
(
window
->
widget
);
if
(
!
gdk_gl_drawable_make_current
(
gldrawable
,
glcontext
))
CV_ERROR
(
CV_OpenGlApiCallError
,
"Can't Activate The GL Rendering Context"
);
__END__
;
}
CV_IMPL
void
cvUpdateWindow
(
const
char
*
name
)
{
CV_FUNCNAME
(
"cvUpdateWindow"
);
__BEGIN__
;
CvWindow
*
window
;
if
(
!
name
)
CV_ERROR
(
CV_StsNullPtr
,
"NULL name string"
);
window
=
icvFindWindowByName
(
name
);
if
(
!
window
)
EXIT
;
// window does not refresh without this
gtk_widget_queue_draw
(
GTK_WIDGET
(
window
->
widget
)
);
__END__
;
}
CV_IMPL
void
cvCreateOpenGLCallback
(
const
char
*
name
,
CvOpenGLCallback
callback
,
void
*
userdata
,
double
,
double
,
double
)
{
CvWindow
*
window
;
CV_FUNCNAME
(
"cvCreateOpenGLCallback"
);
__BEGIN__
;
if
(
!
name
)
CV_ERROR
(
CV_StsNullPtr
,
"NULL name string"
);
window
=
icvFindWindowByName
(
name
);
if
(
!
window
)
EXIT
;
if
(
!
window
->
useGl
)
CV_ERROR
(
CV_OpenGlNotSupported
,
"Window was created without OpenGL context"
);
window
->
glDrawCallback
=
callback
;
window
->
glDrawData
=
userdata
;
__END__
;
}
void
icvSetOpenGlCleanCallback
(
const
char
*
name
,
CvOpenGlCleanCallback
callback
,
void
*
userdata
)
{
CvWindow
*
window
;
GdkGLContext
*
glcontext
;
GdkGLDrawable
*
gldrawable
;
CV_FUNCNAME
(
"icvSetOpenGlCleanCallback"
);
__BEGIN__
;
if
(
!
name
)
CV_ERROR
(
CV_StsNullPtr
,
"NULL name string"
);
window
=
icvFindWindowByName
(
name
);
if
(
!
window
)
EXIT
;
if
(
!
window
->
useGl
)
CV_ERROR
(
CV_OpenGlNotSupported
,
"Window doesn't support OpenGL"
);
glcontext
=
gtk_widget_get_gl_context
(
window
->
widget
);
gldrawable
=
gtk_widget_get_gl_drawable
(
window
->
widget
);
gdk_gl_drawable_make_current
(
gldrawable
,
glcontext
);
if
(
window
->
glCleanCallback
)
window
->
glCleanCallback
(
window
->
glCleanData
);
window
->
glCleanCallback
=
callback
;
window
->
glCleanData
=
userdata
;
__END__
;
}
#endif // HAVE_OPENGL
static
void
icvDeleteWindow
(
CvWindow
*
window
)
{
CvTrackbar
*
trackbar
;
#ifdef HAVE_OPENGL
if
(
window
->
useGl
)
{
GdkGLContext
*
glcontext
=
gtk_widget_get_gl_context
(
window
->
widget
);
GdkGLDrawable
*
gldrawable
=
gtk_widget_get_gl_drawable
(
window
->
widget
);
gdk_gl_drawable_make_current
(
gldrawable
,
glcontext
);
if
(
window
->
glCleanCallback
)
{
window
->
glCleanCallback
(
window
->
glCleanData
);
window
->
glCleanCallback
=
0
;
window
->
glCleanData
=
0
;
}
releaseGlContext
(
window
);
}
#endif
if
(
window
->
prev
)
window
->
prev
->
next
=
window
->
next
;
else
...
...
@@ -742,7 +1259,7 @@ static void icvDeleteWindow( CvWindow* window )
window
->
prev
=
window
->
next
=
0
;
gtk_widget_destroy
(
window
->
frame
);
gtk_widget_destroy
(
window
->
frame
);
for
(
trackbar
=
window
->
toolbar
.
first
;
trackbar
!=
0
;
)
{
...
...
@@ -753,11 +1270,11 @@ static void icvDeleteWindow( CvWindow* window )
cvFree
(
&
window
);
#ifdef HAVE_GTHREAD
// if last window, send key press signal
// to jump out of any waiting cvWaitKey's
if
(
hg_windows
==
0
&&
thread_started
){
g_cond_broadcast
(
cond_have_key
);
}
// if last window, send key press signal
// to jump out of any waiting cvWaitKey's
if
(
hg_windows
==
0
&&
thread_started
){
g_cond_broadcast
(
cond_have_key
);
}
#endif
}
...
...
@@ -777,14 +1294,14 @@ CV_IMPL void cvDestroyWindow( const char* name )
if
(
!
window
)
EXIT
;
// note that it is possible for the update thread to run this function
// if there is a call to cvShowImage in a mouse callback
// (this would produce a deadlock on window_mutex)
CV_LOCK_MUTEX
();
// note that it is possible for the update thread to run this function
// if there is a call to cvShowImage in a mouse callback
// (this would produce a deadlock on window_mutex)
CV_LOCK_MUTEX
();
icvDeleteWindow
(
window
);
icvDeleteWindow
(
window
);
CV_UNLOCK_MUTEX
();
CV_UNLOCK_MUTEX
();
__END__
;
}
...
...
@@ -793,26 +1310,26 @@ CV_IMPL void cvDestroyWindow( const char* name )
CV_IMPL
void
cvDestroyAllWindows
(
void
)
{
CV_LOCK_MUTEX
();
CV_LOCK_MUTEX
();
while
(
hg_windows
)
{
CvWindow
*
window
=
hg_windows
;
icvDeleteWindow
(
window
);
}
CV_UNLOCK_MUTEX
();
CV_UNLOCK_MUTEX
();
}
CvSize
icvCalcOptimalWindowSize
(
CvWindow
*
window
,
CvSize
new_image_size
){
CvSize
window_size
;
GtkWidget
*
toplevel
=
gtk_widget_get_toplevel
(
window
->
frame
);
gdk_drawable_get_size
(
GDK_DRAWABLE
(
toplevel
->
window
),
&
window_size
.
width
,
&
window_size
.
height
);
CvSize
window_size
;
GtkWidget
*
toplevel
=
gtk_widget_get_toplevel
(
window
->
frame
);
gdk_drawable_get_size
(
GDK_DRAWABLE
(
toplevel
->
window
),
&
window_size
.
width
,
&
window_size
.
height
);
window_size
.
width
=
window_size
.
width
+
new_image_size
.
width
-
window
->
widget
->
allocation
.
width
;
window_size
.
height
=
window_size
.
height
+
new_image_size
.
height
-
window
->
widget
->
allocation
.
height
;
window_size
.
width
=
window_size
.
width
+
new_image_size
.
width
-
window
->
widget
->
allocation
.
width
;
window_size
.
height
=
window_size
.
height
+
new_image_size
.
height
-
window
->
widget
->
allocation
.
height
;
return
window_size
;
return
window_size
;
}
CV_IMPL
void
...
...
@@ -827,20 +1344,33 @@ cvShowImage( const char* name, const CvArr* arr )
if
(
!
name
)
CV_ERROR
(
CV_StsNullPtr
,
"NULL name"
);
CV_LOCK_MUTEX
();
CV_LOCK_MUTEX
();
window
=
icvFindWindowByName
(
name
);
if
(
!
window
)
{
cvNamedWindow
(
name
,
1
);
window
=
icvFindWindowByName
(
name
);
}
if
(
window
&&
arr
){
CvImageWidget
*
image_widget
=
CV_IMAGE_WIDGET
(
window
->
widget
);
cvImageWidgetSetImage
(
image_widget
,
arr
);
}
CV_UNLOCK_MUTEX
();
if
(
!
window
)
{
cvNamedWindow
(
name
,
1
);
window
=
icvFindWindowByName
(
name
);
}
if
(
window
&&
arr
)
{
#ifdef HAVE_OPENGL
if
(
window
->
useGl
)
{
CvMat
stub
;
CvMat
*
mat
=
cvGetMat
(
arr
,
&
stub
);
cv
::
Mat
im
(
mat
);
cv
::
imshow
(
name
,
im
);
return
;
}
#endif
CvImageWidget
*
image_widget
=
CV_IMAGE_WIDGET
(
window
->
widget
);
cvImageWidgetSetImage
(
image_widget
,
arr
);
}
CV_UNLOCK_MUTEX
();
__END__
;
}
...
...
@@ -852,7 +1382,7 @@ CV_IMPL void cvResizeWindow(const char* name, int width, int height )
__BEGIN__
;
CvWindow
*
window
;
CvImageWidget
*
image_widget
;
CvImageWidget
*
image_widget
;
if
(
!
name
)
CV_ERROR
(
CV_StsNullPtr
,
"NULL name"
);
...
...
@@ -861,20 +1391,20 @@ CV_IMPL void cvResizeWindow(const char* name, int width, int height )
if
(
!
window
)
EXIT
;
image_widget
=
CV_IMAGE_WIDGET
(
window
->
widget
);
if
(
image_widget
->
flags
&
CV_WINDOW_AUTOSIZE
)
EXIT
;
image_widget
=
CV_IMAGE_WIDGET
(
window
->
widget
);
//
if(image_widget->flags & CV_WINDOW_AUTOSIZE)
//
EXIT;
CV_LOCK_MUTEX
();
CV_LOCK_MUTEX
();
gtk_window_set_resizable
(
GTK_WINDOW
(
window
->
frame
),
1
);
gtk_window_set_resizable
(
GTK_WINDOW
(
window
->
frame
),
1
);
gtk_window_resize
(
GTK_WINDOW
(
window
->
frame
),
width
,
height
);
// disable initial resize since presumably user wants to keep
// this window size
image_widget
->
flags
&=
~
CV_WINDOW_NO_IMAGE
;
// disable initial resize since presumably user wants to keep
// this window size
image_widget
->
flags
&=
~
CV_WINDOW_NO_IMAGE
;
CV_UNLOCK_MUTEX
();
CV_UNLOCK_MUTEX
();
__END__
;
}
...
...
@@ -895,11 +1425,11 @@ CV_IMPL void cvMoveWindow( const char* name, int x, int y )
if
(
!
window
)
EXIT
;
CV_LOCK_MUTEX
();
CV_LOCK_MUTEX
();
gtk_window_move
(
GTK_WINDOW
(
window
->
frame
),
x
,
y
);
CV_UNLOCK_MUTEX
();
CV_UNLOCK_MUTEX
();
__END__
;
}
...
...
@@ -943,7 +1473,7 @@ icvCreateTrackbar( const char* trackbar_name, const char* window_name,
trackbar
=
icvFindTrackbarByName
(
window
,
trackbar_name
);
CV_LOCK_MUTEX
();
CV_LOCK_MUTEX
();
if
(
!
trackbar
)
{
...
...
@@ -973,7 +1503,7 @@ icvCreateTrackbar( const char* trackbar_name, const char* window_name,
gtk_box_pack_start
(
GTK_BOX
(
window
->
paned
),
hscale_box
,
FALSE
,
FALSE
,
5
);
gtk_widget_show
(
hscale_box
);
}
}
if
(
val
)
{
...
...
@@ -994,12 +1524,12 @@ icvCreateTrackbar( const char* trackbar_name, const char* window_name,
gtk_signal_connect
(
GTK_OBJECT
(
trackbar
->
widget
),
"value-changed"
,
GTK_SIGNAL_FUNC
(
icvOnTrackbar
),
trackbar
);
// queue a widget resize to trigger a window resize to
// compensate for the addition of trackbars
gtk_widget_queue_resize
(
GTK_WIDGET
(
window
->
widget
)
);
// queue a widget resize to trigger a window resize to
// compensate for the addition of trackbars
gtk_widget_queue_resize
(
GTK_WIDGET
(
window
->
widget
)
);
CV_UNLOCK_MUTEX
();
CV_UNLOCK_MUTEX
();
result
=
1
;
...
...
@@ -1103,11 +1633,11 @@ CV_IMPL void cvSetTrackbarPos( const char* trackbar_name, const char* window_nam
pos
=
trackbar
->
maxval
;
}
CV_LOCK_MUTEX
();
CV_LOCK_MUTEX
();
gtk_range_set_value
(
GTK_RANGE
(
trackbar
->
widget
),
pos
);
CV_UNLOCK_MUTEX
();
CV_UNLOCK_MUTEX
();
__END__
;
}
...
...
@@ -1174,7 +1704,7 @@ static gboolean icvOnKeyPress( GtkWidget * /*widget*/,
break
;
case
GDK_Tab
:
code
=
'\t'
;
break
;
break
;
default
:
code
=
event
->
keyval
;
}
...
...
@@ -1182,17 +1712,17 @@ static gboolean icvOnKeyPress( GtkWidget * /*widget*/,
code
|=
event
->
state
<<
16
;
#ifdef HAVE_GTHREAD
if
(
thread_started
)
g_mutex_lock
(
last_key_mutex
);
if
(
thread_started
)
g_mutex_lock
(
last_key_mutex
);
#endif
last_key
=
code
;
last_key
=
code
;
#ifdef HAVE_GTHREAD
if
(
thread_started
){
// signal any waiting threads
g_cond_broadcast
(
cond_have_key
);
g_mutex_unlock
(
last_key_mutex
);
}
if
(
thread_started
){
// signal any waiting threads
g_cond_broadcast
(
cond_have_key
);
g_mutex_unlock
(
last_key_mutex
);
}
#endif
return
FALSE
;
...
...
@@ -1222,25 +1752,25 @@ static gboolean icvOnClose( GtkWidget* widget, GdkEvent* /*event*/, gpointer use
CvWindow
*
window
=
(
CvWindow
*
)
user_data
;
if
(
window
->
signature
==
CV_WINDOW_MAGIC_VAL
&&
window
->
frame
==
widget
)
{
{
icvDeleteWindow
(
window
);
}
}
return
TRUE
;
}
static
gboolean
icvOnMouse
(
GtkWidget
*
widget
,
GdkEvent
*
event
,
gpointer
user_data
)
{
// TODO move this logic to CvImageWidget
// TODO move this logic to CvImageWidget
CvWindow
*
window
=
(
CvWindow
*
)
user_data
;
CvPoint2D32f
pt32f
=
{
-
1.
,
-
1.
};
CvPoint2D32f
pt32f
=
{
-
1.
,
-
1.
};
CvPoint
pt
=
{
-
1
,
-
1
};
int
cv_event
=
-
1
,
state
=
0
;
CvImageWidget
*
image_widget
=
CV_IMAGE_WIDGET
(
widget
);
CvImageWidget
*
image_widget
=
CV_IMAGE_WIDGET
(
widget
);
if
(
window
->
signature
!=
CV_WINDOW_MAGIC_VAL
||
window
->
widget
!=
widget
||
!
window
->
widget
||
!
window
->
on_mouse
||
!
image_widget
->
original_image
)
!
window
->
on_mouse
/*|| !image_widget->original_image*/
)
return
FALSE
;
if
(
event
->
type
==
GDK_MOTION_NOTIFY
)
...
...
@@ -1283,37 +1813,37 @@ static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_da
}
if
(
cv_event
>=
0
){
// scale point if image is scaled
if
(
(
image_widget
->
flags
&
CV_WINDOW_AUTOSIZE
)
==
0
&&
image_widget
->
original_image
&&
image_widget
->
scaled_image
){
// image origin is not necessarily at (0,0)
int
x0
=
(
widget
->
allocation
.
width
-
image_widget
->
scaled_image
->
cols
)
/
2
;
int
y0
=
(
widget
->
allocation
.
height
-
image_widget
->
scaled_image
->
rows
)
/
2
;
pt
.
x
=
cvRound
(
((
pt32f
.
x
-
x0
)
*
image_widget
->
original_image
->
cols
)
/
image_widget
->
scaled_image
->
cols
);
pt
.
y
=
cvRound
(
((
pt32f
.
y
-
y0
)
*
image_widget
->
original_image
->
rows
)
/
image_widget
->
scaled_image
->
rows
);
}
else
{
pt
=
cvPointFrom32f
(
pt32f
);
}
if
((
unsigned
)
pt
.
x
<
(
unsigned
)(
image_widget
->
original_image
->
width
)
&&
(
unsigned
)
pt
.
y
<
(
unsigned
)(
image_widget
->
original_image
->
height
)
)
{
int
flags
=
(
state
&
GDK_SHIFT_MASK
?
CV_EVENT_FLAG_SHIFTKEY
:
0
)
|
(
state
&
GDK_CONTROL_MASK
?
CV_EVENT_FLAG_CTRLKEY
:
0
)
|
(
state
&
(
GDK_MOD1_MASK
|
GDK_MOD2_MASK
)
?
CV_EVENT_FLAG_ALTKEY
:
0
)
|
(
state
&
GDK_BUTTON1_MASK
?
CV_EVENT_FLAG_LBUTTON
:
0
)
|
(
state
&
GDK_BUTTON2_MASK
?
CV_EVENT_FLAG_MBUTTON
:
0
)
|
(
state
&
GDK_BUTTON3_MASK
?
CV_EVENT_FLAG_RBUTTON
:
0
);
window
->
on_mouse
(
cv_event
,
pt
.
x
,
pt
.
y
,
flags
,
window
->
on_mouse_param
);
}
}
return
FALSE
;
}
// scale point if image is scaled
if
(
(
image_widget
->
flags
&
CV_WINDOW_AUTOSIZE
)
==
0
&&
image_widget
->
original_image
&&
image_widget
->
scaled_image
){
// image origin is not necessarily at (0,0)
int
x0
=
(
widget
->
allocation
.
width
-
image_widget
->
scaled_image
->
cols
)
/
2
;
int
y0
=
(
widget
->
allocation
.
height
-
image_widget
->
scaled_image
->
rows
)
/
2
;
pt
.
x
=
cvRound
(
((
pt32f
.
x
-
x0
)
*
image_widget
->
original_image
->
cols
)
/
image_widget
->
scaled_image
->
cols
);
pt
.
y
=
cvRound
(
((
pt32f
.
y
-
y0
)
*
image_widget
->
original_image
->
rows
)
/
image_widget
->
scaled_image
->
rows
);
}
else
{
pt
=
cvPointFrom32f
(
pt32f
);
}
//
if((unsigned)pt.x < (unsigned)(image_widget->original_image->width) &&
//
(unsigned)pt.y < (unsigned)(image_widget->original_image->height) )
{
int
flags
=
(
state
&
GDK_SHIFT_MASK
?
CV_EVENT_FLAG_SHIFTKEY
:
0
)
|
(
state
&
GDK_CONTROL_MASK
?
CV_EVENT_FLAG_CTRLKEY
:
0
)
|
(
state
&
(
GDK_MOD1_MASK
|
GDK_MOD2_MASK
)
?
CV_EVENT_FLAG_ALTKEY
:
0
)
|
(
state
&
GDK_BUTTON1_MASK
?
CV_EVENT_FLAG_LBUTTON
:
0
)
|
(
state
&
GDK_BUTTON2_MASK
?
CV_EVENT_FLAG_MBUTTON
:
0
)
|
(
state
&
GDK_BUTTON3_MASK
?
CV_EVENT_FLAG_RBUTTON
:
0
);
window
->
on_mouse
(
cv_event
,
pt
.
x
,
pt
.
y
,
flags
,
window
->
on_mouse_param
);
}
}
return
FALSE
;
}
static
gboolean
icvAlarm
(
gpointer
user_data
)
...
...
@@ -1326,44 +1856,44 @@ static gboolean icvAlarm( gpointer user_data )
CV_IMPL
int
cvWaitKey
(
int
delay
)
{
#ifdef HAVE_GTHREAD
if
(
thread_started
&&
g_thread_self
()
!=
window_thread
){
gboolean
expired
;
int
my_last_key
;
// wait for signal or timeout if delay > 0
if
(
delay
>
0
){
GTimeVal
timer
;
g_get_current_time
(
&
timer
);
g_time_val_add
(
&
timer
,
delay
*
1000
);
expired
=
!
g_cond_timed_wait
(
cond_have_key
,
last_key_mutex
,
&
timer
);
}
else
{
g_cond_wait
(
cond_have_key
,
last_key_mutex
);
expired
=
false
;
}
my_last_key
=
last_key
;
g_mutex_unlock
(
last_key_mutex
);
if
(
expired
||
hg_windows
==
0
){
return
-
1
;
}
return
my_last_key
;
}
else
{
if
(
thread_started
&&
g_thread_self
()
!=
window_thread
){
gboolean
expired
;
int
my_last_key
;
// wait for signal or timeout if delay > 0
if
(
delay
>
0
){
GTimeVal
timer
;
g_get_current_time
(
&
timer
);
g_time_val_add
(
&
timer
,
delay
*
1000
);
expired
=
!
g_cond_timed_wait
(
cond_have_key
,
last_key_mutex
,
&
timer
);
}
else
{
g_cond_wait
(
cond_have_key
,
last_key_mutex
);
expired
=
false
;
}
my_last_key
=
last_key
;
g_mutex_unlock
(
last_key_mutex
);
if
(
expired
||
hg_windows
==
0
){
return
-
1
;
}
return
my_last_key
;
}
else
{
#endif
int
expired
=
0
;
guint
timer
=
0
;
if
(
delay
>
0
)
timer
=
g_timeout_add
(
delay
,
icvAlarm
,
&
expired
);
last_key
=
-
1
;
while
(
gtk_main_iteration_do
(
TRUE
)
&&
last_key
<
0
&&
!
expired
&&
hg_windows
!=
0
)
;
if
(
delay
>
0
&&
!
expired
)
g_source_remove
(
timer
);
int
expired
=
0
;
guint
timer
=
0
;
if
(
delay
>
0
)
timer
=
g_timeout_add
(
delay
,
icvAlarm
,
&
expired
);
last_key
=
-
1
;
while
(
gtk_main_iteration_do
(
TRUE
)
&&
last_key
<
0
&&
!
expired
&&
hg_windows
!=
0
)
;
if
(
delay
>
0
&&
!
expired
)
g_source_remove
(
timer
);
#ifdef HAVE_GTHREAD
}
}
#endif
return
last_key
;
return
last_key
;
}
...
...
samples/cpp/point_cloud.cpp
View file @
2a4fb155
...
...
@@ -76,7 +76,7 @@ int main(int argc, const char* argv[])
CommandLineParser
cmd
(
argc
,
argv
,
keys
);
if
(
cmd
.
get
<
bool
>
(
"help"
))
if
(
cmd
.
get
<
bool
>
(
"help"
))
{
cout
<<
"Avaible options:"
<<
endl
;
cmd
.
printParams
();
...
...
@@ -119,13 +119,13 @@ int main(int argc, const char* argv[])
{
cout
<<
"Can't load image "
<<
right
<<
endl
;
return
-
1
;
}
}
Mat
Q
=
Mat
::
eye
(
4
,
4
,
CV_32F
);
if
(
!
intrinsic
.
empty
()
&&
!
extrinsic
.
empty
())
{
FileStorage
fs
;
// reading intrinsic parameters
fs
.
open
(
intrinsic
,
CV_STORAGE_READ
);
if
(
!
fs
.
isOpened
())
...
...
@@ -133,13 +133,13 @@ int main(int argc, const char* argv[])
cout
<<
"Failed to open file "
<<
intrinsic
<<
endl
;
return
-
1
;
}
Mat
M1
,
D1
,
M2
,
D2
;
fs
[
"M1"
]
>>
M1
;
fs
[
"D1"
]
>>
D1
;
fs
[
"M2"
]
>>
M2
;
fs
[
"D2"
]
>>
D2
;
// reading extrinsic parameters
fs
.
open
(
extrinsic
,
CV_STORAGE_READ
);
if
(
!
fs
.
isOpened
())
...
...
@@ -147,7 +147,7 @@ int main(int argc, const char* argv[])
cout
<<
"Failed to open file "
<<
extrinsic
<<
endl
;
return
-
1
;
}
Mat
R
,
T
,
R1
,
P1
,
R2
,
P2
;
fs
[
"R"
]
>>
R
;
fs
[
"T"
]
>>
T
;
...
...
@@ -156,15 +156,15 @@ int main(int argc, const char* argv[])
Rect
roi1
,
roi2
;
stereoRectify
(
M1
,
D1
,
M2
,
D2
,
img_size
,
R
,
T
,
R1
,
R2
,
P1
,
P2
,
Q
,
CALIB_ZERO_DISPARITY
,
-
1
,
img_size
,
&
roi1
,
&
roi2
);
Mat
map11
,
map12
,
map21
,
map22
;
initUndistortRectifyMap
(
M1
,
D1
,
R1
,
P1
,
img_size
,
CV_16SC2
,
map11
,
map12
);
initUndistortRectifyMap
(
M2
,
D2
,
R2
,
P2
,
img_size
,
CV_16SC2
,
map21
,
map22
);
Mat
img1r
,
img2r
;
remap
(
imgLeftColor
,
img1r
,
map11
,
map12
,
INTER_LINEAR
);
remap
(
imgRightColor
,
img2r
,
map21
,
map22
,
INTER_LINEAR
);
imgLeftColor
=
img1r
(
roi1
);
imgRightColor
=
img2r
(
roi2
);
}
...
...
@@ -194,7 +194,7 @@ int main(int argc, const char* argv[])
int
mouse
[
2
]
=
{
0
,
0
};
setMouseCallback
(
"OpenGL Sample"
,
mouseCallback
,
mouse
);
GlArrays
pointCloud
;
pointCloud
.
setVertexArray
(
points
);
...
...
@@ -202,7 +202,7 @@ int main(int argc, const char* argv[])
GlCamera
camera
;
camera
.
setScale
(
Point3d
(
scale
,
scale
,
scale
));
double
yaw
=
0.0
;
double
pitch
=
0.0
;
...
...
@@ -214,17 +214,25 @@ int main(int argc, const char* argv[])
while
(
true
)
{
int
key
=
waitKey
(
1
);
if
(
key
>=
0
)
key
=
key
&
0xff
;
if
(
key
==
27
)
break
;
break
;
double
aspect
=
getWindowProperty
(
"OpenGL Sample"
,
WND_PROP_ASPECT_RATIO
);
const
double
posStep
=
0.1
;
#ifdef _WIN32
const
double
mouseStep
=
0.001
;
#else
const
double
mouseStep
=
0.000001
;
#endif
const
int
mouseClamp
=
300
;
camera
.
setPerspectiveProjection
(
30.0
+
fov
/
100.0
*
40.0
,
aspect
,
0.1
,
1000.0
);
camera
.
setPerspectiveProjection
(
30.0
+
fov
/
100.0
*
40.0
,
aspect
,
0.1
,
1000.0
);
int
mouse_dx
=
clamp
(
mouse
[
0
],
-
mouseClamp
,
mouseClamp
);
int
mouse_dy
=
clamp
(
mouse
[
1
],
-
mouseClamp
,
mouseClamp
);
...
...
samples/gpu/highgui_gpu.cpp
View file @
2a4fb155
...
...
@@ -64,7 +64,7 @@ int main(int argc, char* argv[])
GpuMat
d_img
;
if
(
haveCuda
)
d_img
.
upload
(
img
);
cout
<<
"=== First call
\n\n
"
;
{
...
...
@@ -123,4 +123,4 @@ int main(int argc, char* argv[])
}
return
0
;
}
\ No newline at end of file
}
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