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
396f7e1a
Commit
396f7e1a
authored
Jan 16, 2015
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3604 from asmorkalov:ocv_samples_package
parents
9cadc1e5
6628714f
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
172 additions
and
252 deletions
+172
-252
OpenCVPackaging.cmake
cmake/OpenCVPackaging.cmake
+1
-1
CMakeLists.txt
samples/CMakeLists.txt
+4
-1
CMakeLists.txt
samples/c/CMakeLists.txt
+2
-2
latentsvmdetect.cpp
samples/c/latentsvmdetect.cpp
+1
-23
CMakeLists.txt
samples/cpp/CMakeLists.txt
+2
-2
latentsvm_multidetect.cpp
samples/cpp/latentsvm_multidetect.cpp
+0
-8
CMakeLists.txt
samples/gpu/CMakeLists.txt
+31
-2
brox_optical_flow.cpp
samples/gpu/brox_optical_flow.cpp
+0
-1
cascadeclassifier_nvidia_api.cpp
samples/gpu/cascadeclassifier_nvidia_api.cpp
+3
-18
driver_api_multi.cpp
samples/gpu/driver_api_multi.cpp
+70
-82
driver_api_stereo_multi.cpp
samples/gpu/driver_api_stereo_multi.cpp
+23
-33
multi.cpp
samples/gpu/multi.cpp
+32
-52
opengl.cpp
samples/gpu/opengl.cpp
+0
-9
opticalflow_nvidia_api.cpp
samples/gpu/opticalflow_nvidia_api.cpp
+0
-14
CMakeLists.txt
samples/gpu/performance/CMakeLists.txt
+1
-1
pyrlk_optical_flow.cpp
samples/gpu/pyrlk_optical_flow.cpp
+0
-1
CMakeLists.txt
samples/ocl/CMakeLists.txt
+2
-2
No files found.
cmake/OpenCVPackaging.cmake
View file @
396f7e1a
...
...
@@ -64,7 +64,7 @@ set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://opencv.org")
#depencencies
set
(
CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE
)
set
(
CPACK_COMPONENT_samples_DEPENDS libs
)
set
(
CPACK_COMPONENT_samples_DEPENDS libs
dev
)
set
(
CPACK_COMPONENT_dev_DEPENDS libs
)
set
(
CPACK_COMPONENT_docs_DEPENDS libs
)
set
(
CPACK_COMPONENT_java_DEPENDS libs
)
...
...
samples/CMakeLists.txt
View file @
396f7e1a
...
...
@@ -19,6 +19,9 @@ if(ANDROID AND BUILD_ANDROID_EXAMPLES)
add_subdirectory
(
android
)
endif
()
install
(
FILES
"CMakeLists.txt"
DESTINATION
${
OPENCV_SAMPLES_SRC_INSTALL_PATH
}
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples
)
#
# END OF BUILD CASE 1: Build samples with library sources
...
...
@@ -60,7 +63,7 @@ endif()
add_subdirectory
(
c
)
add_subdirectory
(
cpp
)
add_subdirectory
(
ocl
)
# FIXIT: can't use cvconfig.h in samples:
add_subdirectory(gpu)
add_subdirectory
(
gpu
)
#
# END OF BUILD CASE 2: Build samples with library binaries
...
...
samples/c/CMakeLists.txt
View file @
396f7e1a
...
...
@@ -51,8 +51,8 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
endforeach
()
endif
()
if
(
INSTALL_C_EXAMPLES AND NOT WIN32
)
file
(
GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd
)
if
(
OCV_DEPENDENCIES_FOUND AND
INSTALL_C_EXAMPLES AND NOT WIN32
)
file
(
GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd
*.txt
)
install
(
FILES
${
C_SAMPLES
}
DESTINATION
${
OPENCV_SAMPLES_SRC_INSTALL_PATH
}
/c
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples
)
...
...
samples/c/latentsvmdetect.cpp
View file @
396f7e1a
...
...
@@ -2,13 +2,6 @@
#include "opencv2/highgui/highgui.hpp"
#include <stdio.h>
#ifdef HAVE_CVCONFIG_H
#include <cvconfig.h>
#endif
#ifdef HAVE_TBB
#include "tbb/task_scheduler_init.h"
#endif
using
namespace
cv
;
static
void
help
()
...
...
@@ -31,28 +24,13 @@ static void detect_and_draw_objects( IplImage* image, CvLatentSvmDetector* detec
CvSeq
*
detections
=
0
;
int
i
=
0
;
int64
start
=
0
,
finish
=
0
;
#ifdef HAVE_TBB
tbb
::
task_scheduler_init
init
(
tbb
::
task_scheduler_init
::
deferred
);
if
(
numThreads
>
0
)
{
init
.
initialize
(
numThreads
);
printf
(
"Number of threads %i
\n
"
,
numThreads
);
}
else
{
printf
(
"Number of threads is not correct for TBB version"
);
return
;
}
#endif
cv
::
setNumThreads
(
numThreads
);
start
=
cvGetTickCount
();
detections
=
cvLatentSvmDetectObjects
(
image
,
detector
,
storage
,
0.5
f
,
numThreads
);
finish
=
cvGetTickCount
();
printf
(
"detection time = %.3f
\n
"
,
(
float
)(
finish
-
start
)
/
(
float
)(
cvGetTickFrequency
()
*
1000000.0
));
#ifdef HAVE_TBB
init
.
terminate
();
#endif
for
(
i
=
0
;
i
<
detections
->
total
;
i
++
)
{
CvObjectDetection
detection
=
*
(
CvObjectDetection
*
)
cvGetSeqElem
(
detections
,
i
);
...
...
samples/cpp/CMakeLists.txt
View file @
396f7e1a
...
...
@@ -90,8 +90,8 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
endforeach
()
endif
()
if
(
INSTALL_C_EXAMPLES AND NOT WIN32
)
file
(
GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd
)
if
(
OCV_DEPENDENCIES_FOUND AND
INSTALL_C_EXAMPLES AND NOT WIN32
)
file
(
GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd
*.txt
)
install
(
FILES
${
C_SAMPLES
}
DESTINATION
${
OPENCV_SAMPLES_SRC_INSTALL_PATH
}
/cpp
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples
)
...
...
samples/cpp/latentsvm_multidetect.cpp
View file @
396f7e1a
...
...
@@ -9,14 +9,6 @@
#include <dirent.h>
#endif
#ifdef HAVE_CVCONFIG_H
#include <cvconfig.h>
#endif
#ifdef HAVE_TBB
#include "tbb/task_scheduler_init.h"
#endif
using
namespace
std
;
using
namespace
cv
;
...
...
samples/gpu/CMakeLists.txt
View file @
396f7e1a
...
...
@@ -69,8 +69,28 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
endif
()
ENDMACRO
()
# remove all matching elements from the list
MACRO
(
list_filterout lst regex
)
foreach
(
item
${${
lst
}}
)
if
(
item MATCHES
"
${
regex
}
"
)
list
(
REMOVE_ITEM
${
lst
}
"
${
item
}
"
)
endif
()
endforeach
()
ENDMACRO
()
file
(
GLOB all_samples RELATIVE
${
CMAKE_CURRENT_SOURCE_DIR
}
*.cpp
)
if
(
NOT HAVE_OPENGL
)
list
(
REMOVE_ITEM all_samples
"opengl.cpp"
)
endif
()
if
(
NOT HAVE_CUDA
)
list
(
REMOVE_ITEM all_samples
"opticalflow_nvidia_api.cpp"
)
list
(
REMOVE_ITEM all_samples
"cascadeclassifier_nvidia_api.cpp"
)
list
(
REMOVE_ITEM all_samples
"driver_api_multi.cpp"
)
list
(
REMOVE_ITEM all_samples
"driver_api_stereo_multi.cpp"
)
endif
()
foreach
(
sample_filename
${
all_samples
}
)
get_filename_component
(
sample
${
sample_filename
}
NAME_WE
)
file
(
GLOB sample_srcs RELATIVE
${
CMAKE_CURRENT_SOURCE_DIR
}
${
sample
}
.*
)
...
...
@@ -80,8 +100,17 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
include
(
"performance/CMakeLists.txt"
)
endif
()
if
(
INSTALL_C_EXAMPLES AND NOT WIN32
)
file
(
GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd
)
if
(
OCV_DEPENDENCIES_FOUND AND INSTALL_C_EXAMPLES AND NOT WIN32
)
file
(
GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd *.txt
)
if
(
NOT HAVE_OPENGL
)
list_filterout
(
install_list
".*opengl.cpp"
)
endif
()
if
(
NOT HAVE_CUDA
)
list_filterout
(
install_list
".*opticalflow_nvidia_api.cpp"
)
list_filterout
(
install_list
".*cascadeclassifier_nvidia_api.cpp"
)
list_filterout
(
install_list
".*driver_api_multi.cpp"
)
list_filterout
(
install_list
".*driver_api_stereo_multi.cpp"
)
endif
()
install
(
FILES
${
install_list
}
DESTINATION
${
OPENCV_SAMPLES_SRC_INSTALL_PATH
}
/gpu
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples
)
...
...
samples/gpu/brox_optical_flow.cpp
View file @
396f7e1a
...
...
@@ -3,7 +3,6 @@
#include <string>
#include <ctype.h>
#include "cvconfig.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"
...
...
samples/gpu/cascadeclassifier_nvidia_api.cpp
View file @
396f7e1a
...
...
@@ -2,39 +2,24 @@
#pragma warning( disable : 4201 4408 4127 4100)
#endif
#include "cvconfig.h"
#include <iostream>
#include <iomanip>
#include <cstdio>
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/highgui/highgui.hpp"
#ifdef HAVE_CUDA
#include "NCVHaarObjectDetection.hpp"
#endif
using
namespace
std
;
using
namespace
cv
;
#if !defined(HAVE_CUDA) || defined(__arm__)
int
main
(
int
,
const
char
**
)
{
#if !defined(HAVE_CUDA)
std
::
cout
<<
"CUDA support is required (CMake key 'WITH_CUDA' must be true)."
<<
std
::
endl
;
#endif
#if defined(__arm__)
int
main
()
{
std
::
cout
<<
"Unsupported for ARM CUDA library."
<<
std
::
endl
;
#endif
return
0
;
}
#else
const
Size2i
preferredVideoFrameSize
(
640
,
480
);
const
string
wndTitle
=
"NVIDIA Computer Vision :: Haar Classifiers Cascade"
;
...
...
@@ -386,4 +371,4 @@ int main(int argc, const char** argv)
return
0
;
}
#endif
//!defined(HAVE_CUDA)
#endif
samples/gpu/driver_api_multi.cpp
View file @
396f7e1a
...
...
@@ -7,56 +7,101 @@
#endif
#include <iostream>
#include "cvconfig.h"
#include "opencv2/core/core.hpp"
#include "opencv2/gpu/gpu.hpp"
#if !defined(HAVE_CUDA) || !defined(HAVE_TBB) || defined(__arm__)
#if defined(__arm__)
int
main
()
{
#if !defined(HAVE_CUDA)
std
::
cout
<<
"CUDA support is required (CMake key 'WITH_CUDA' must be true).
\n
"
;
#endif
#if !defined(HAVE_TBB)
std
::
cout
<<
"TBB support is required (CMake key 'WITH_TBB' must be true).
\n
"
;
#endif
#if defined(__arm__)
std
::
cout
<<
"Unsupported for ARM CUDA library."
<<
std
::
endl
;
#endif
return
0
;
}
#else
#include <cuda.h>
#include <cuda_runtime.h>
#include "opencv2/core/internal.hpp" // For TBB wrappers
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
::
gpu
;
struct
Worker
{
void
operator
()(
int
device_id
)
const
;
};
void
destroyContexts
();
#define safeCall(expr) safeCall_(expr, #expr, __FILE__, __LINE__)
inline
void
safeCall_
(
int
code
,
const
char
*
expr
,
const
char
*
file
,
int
line
)
{
if
(
code
!=
CUDA_SUCCESS
)
{
std
::
cout
<<
"CUDA driver API error: code "
<<
code
<<
", expr "
<<
expr
<<
", file "
<<
file
<<
", line "
<<
line
<<
endl
;
destroyContexts
();
<<
", file "
<<
file
<<
", line "
<<
line
<<
endl
;
exit
(
-
1
);
}
}
// Each GPU is associated with its own context
CUcontext
contexts
[
2
];
struct
Worker
:
public
ParallelLoopBody
{
Worker
(
int
num_devices
)
{
count
=
num_devices
;
contexts
=
new
CUcontext
[
num_devices
];
for
(
int
device_id
=
0
;
device_id
<
num_devices
;
device_id
++
)
{
CUdevice
device
;
safeCall
(
cuDeviceGet
(
&
device
,
device_id
));
safeCall
(
cuCtxCreate
(
&
contexts
[
device_id
],
0
,
device
));
}
}
virtual
void
operator
()
(
const
Range
&
range
)
const
{
for
(
int
device_id
=
range
.
start
;
device_id
!=
range
.
end
;
++
device_id
)
{
// Set the proper context
safeCall
(
cuCtxPushCurrent
(
contexts
[
device_id
]));
Mat
src
(
1000
,
1000
,
CV_32F
);
Mat
dst
;
RNG
rng
(
0
);
rng
.
fill
(
src
,
RNG
::
UNIFORM
,
0
,
1
);
// CPU works
transpose
(
src
,
dst
);
// GPU works
GpuMat
d_src
(
src
);
GpuMat
d_dst
;
transpose
(
d_src
,
d_dst
);
// Check results
bool
passed
=
norm
(
dst
-
Mat
(
d_dst
),
NORM_INF
)
<
1e-3
;
std
::
cout
<<
"GPU #"
<<
device_id
<<
" ("
<<
DeviceInfo
().
name
()
<<
"): "
<<
(
passed
?
"passed"
:
"FAILED"
)
<<
endl
;
// Deallocate data here, otherwise deallocation will be performed
// after context is extracted from the stack
d_src
.
release
();
d_dst
.
release
();
CUcontext
prev_context
;
safeCall
(
cuCtxPopCurrent
(
&
prev_context
));
}
}
~
Worker
()
{
if
((
contexts
!=
NULL
)
&&
count
!=
0
)
{
for
(
int
device_id
=
0
;
device_id
<
count
;
device_id
++
)
{
safeCall
(
cuCtxDestroy
(
contexts
[
device_id
]));
}
delete
[]
contexts
;
}
}
CUcontext
*
contexts
;
int
count
;
};
int
main
()
{
...
...
@@ -84,67 +129,10 @@ int main()
// Init CUDA Driver API
safeCall
(
cuInit
(
0
));
// Create context for GPU #0
CUdevice
device
;
safeCall
(
cuDeviceGet
(
&
device
,
0
));
safeCall
(
cuCtxCreate
(
&
contexts
[
0
],
0
,
device
));
CUcontext
prev_context
;
safeCall
(
cuCtxPopCurrent
(
&
prev_context
));
// Create context for GPU #1
safeCall
(
cuDeviceGet
(
&
device
,
1
));
safeCall
(
cuCtxCreate
(
&
contexts
[
1
],
0
,
device
));
safeCall
(
cuCtxPopCurrent
(
&
prev_context
));
// Execute calculation
parallel_for_
(
cv
::
Range
(
0
,
num_devices
),
Worker
(
num_devices
));
// Execute calculation in two threads using two GPUs
int
devices
[]
=
{
0
,
1
};
parallel_do
(
devices
,
devices
+
2
,
Worker
());
destroyContexts
();
return
0
;
}
void
Worker
::
operator
()(
int
device_id
)
const
{
// Set the proper context
safeCall
(
cuCtxPushCurrent
(
contexts
[
device_id
]));
Mat
src
(
1000
,
1000
,
CV_32F
);
Mat
dst
;
RNG
rng
(
0
);
rng
.
fill
(
src
,
RNG
::
UNIFORM
,
0
,
1
);
// CPU works
transpose
(
src
,
dst
);
// GPU works
GpuMat
d_src
(
src
);
GpuMat
d_dst
;
transpose
(
d_src
,
d_dst
);
// Check results
bool
passed
=
norm
(
dst
-
Mat
(
d_dst
),
NORM_INF
)
<
1e-3
;
std
::
cout
<<
"GPU #"
<<
device_id
<<
" ("
<<
DeviceInfo
().
name
()
<<
"): "
<<
(
passed
?
"passed"
:
"FAILED"
)
<<
endl
;
// Deallocate data here, otherwise deallocation will be performed
// after context is extracted from the stack
d_src
.
release
();
d_dst
.
release
();
CUcontext
prev_context
;
safeCall
(
cuCtxPopCurrent
(
&
prev_context
));
}
void
destroyContexts
()
{
safeCall
(
cuCtxDestroy
(
contexts
[
0
]));
safeCall
(
cuCtxDestroy
(
contexts
[
1
]));
}
#endif
samples/gpu/driver_api_stereo_multi.cpp
View file @
396f7e1a
...
...
@@ -8,30 +8,16 @@
#endif
#include <iostream>
#include "cvconfig.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"
#if !defined(HAVE_CUDA) || !defined(HAVE_TBB) || defined(__arm__)
#if defined(__arm__)
int
main
()
{
#if !defined(HAVE_CUDA)
std
::
cout
<<
"CUDA support is required (CMake key 'WITH_CUDA' must be true).
\n
"
;
#endif
#if !defined(HAVE_TBB)
std
::
cout
<<
"TBB support is required (CMake key 'WITH_TBB' must be true).
\n
"
;
#endif
#if defined(__arm__)
std
::
cout
<<
"Unsupported for ARM CUDA library."
<<
std
::
endl
;
#endif
return
0
;
}
#else
#include <cuda.h>
...
...
@@ -42,7 +28,6 @@ using namespace std;
using
namespace
cv
;
using
namespace
cv
::
gpu
;
struct
Worker
{
void
operator
()(
int
device_id
)
const
;
};
void
destroyContexts
();
#define safeCall(expr) safeCall_(expr, #expr, __FILE__, __LINE__)
...
...
@@ -77,6 +62,27 @@ GpuMat d_right[2];
StereoBM_GPU
*
bm
[
2
];
GpuMat
d_result
[
2
];
struct
Worker
:
public
ParallelLoopBody
{
virtual
void
operator
()
(
const
Range
&
range
)
const
{
for
(
int
device_id
=
range
.
start
;
device_id
!=
range
.
end
;
++
device_id
)
{
contextOn
(
device_id
);
bm
[
device_id
]
->
operator
()(
d_left
[
device_id
],
d_right
[
device_id
],
d_result
[
device_id
]);
std
::
cout
<<
"GPU #"
<<
device_id
<<
" ("
<<
DeviceInfo
().
name
()
<<
"): finished
\n
"
;
contextOff
();
}
}
};
static
void
printHelp
()
{
std
::
cout
<<
"Usage: driver_api_stereo_multi_gpu --left <left_image> --right <right_image>
\n
"
;
...
...
@@ -162,8 +168,7 @@ int main(int argc, char** argv)
contextOff
();
// Execute calculation in two threads using two GPUs
int
devices
[]
=
{
0
,
1
};
parallel_do
(
devices
,
devices
+
2
,
Worker
());
parallel_for_
(
cv
::
Range
(
0
,
2
),
Worker
());
// Release the first GPU resources
contextOn
(
0
);
...
...
@@ -188,21 +193,6 @@ int main(int argc, char** argv)
return
0
;
}
void
Worker
::
operator
()(
int
device_id
)
const
{
contextOn
(
device_id
);
bm
[
device_id
]
->
operator
()(
d_left
[
device_id
],
d_right
[
device_id
],
d_result
[
device_id
]);
std
::
cout
<<
"GPU #"
<<
device_id
<<
" ("
<<
DeviceInfo
().
name
()
<<
"): finished
\n
"
;
contextOff
();
}
void
destroyContexts
()
{
safeCall
(
cuCtxDestroy
(
contexts
[
0
]));
...
...
samples/gpu/multi.cpp
View file @
396f7e1a
...
...
@@ -7,34 +7,47 @@
#endif
#include <iostream>
#include "cvconfig.h"
#include "opencv2/core/core.hpp"
#include "opencv2/gpu/gpu.hpp"
#if !defined(HAVE_CUDA) || !defined(HAVE_TBB)
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
::
gpu
;
int
main
()
struct
Worker
:
public
ParallelLoopBody
{
#if !defined(HAVE_CUDA)
std
::
cout
<<
"CUDA support is required (CMake key 'WITH_CUDA' must be true).
\n
"
;
#endif
virtual
void
operator
()
(
const
Range
&
range
)
const
{
for
(
int
device_id
=
range
.
start
;
device_id
!=
range
.
end
;
++
device_id
)
{
setDevice
(
device_id
);
#if !defined(HAVE_TBB)
std
::
cout
<<
"TBB support is required (CMake key 'WITH_TBB' must be true).
\n
"
;
#endif
Mat
src
(
1000
,
1000
,
CV_32F
);
Mat
dst
;
return
0
;
}
RNG
rng
(
0
)
;
rng
.
fill
(
src
,
RNG
::
UNIFORM
,
0
,
1
);
#else
// CPU works
transpose
(
src
,
dst
);
#include "opencv2/core/internal.hpp" // For TBB wrappers
// GPU works
GpuMat
d_src
(
src
);
GpuMat
d_dst
;
transpose
(
d_src
,
d_dst
);
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
::
gpu
;
// Check results
bool
passed
=
norm
(
dst
-
Mat
(
d_dst
),
NORM_INF
)
<
1e-3
;
std
::
cout
<<
"GPU #"
<<
device_id
<<
" ("
<<
DeviceInfo
().
name
()
<<
"): "
<<
(
passed
?
"passed"
:
"FAILED"
)
<<
endl
;
struct
Worker
{
void
operator
()(
int
device_id
)
const
;
};
// Deallocate data here, otherwise deallocation will be performed
// after context is extracted from the stack
d_src
.
release
();
d_dst
.
release
();
}
}
};
int
main
()
{
...
...
@@ -58,41 +71,8 @@ int main()
}
}
// Execute calculation in two threads using two GPUs
int
devices
[]
=
{
0
,
1
};
parallel_do
(
devices
,
devices
+
2
,
Worker
());
// Execute calculation in several threads, 1 GPU per thread
parallel_for_
(
cv
::
Range
(
0
,
num_devices
),
Worker
());
return
0
;
}
void
Worker
::
operator
()(
int
device_id
)
const
{
setDevice
(
device_id
);
Mat
src
(
1000
,
1000
,
CV_32F
);
Mat
dst
;
RNG
rng
(
0
);
rng
.
fill
(
src
,
RNG
::
UNIFORM
,
0
,
1
);
// CPU works
transpose
(
src
,
dst
);
// GPU works
GpuMat
d_src
(
src
);
GpuMat
d_dst
;
transpose
(
d_src
,
d_dst
);
// Check results
bool
passed
=
norm
(
dst
-
Mat
(
d_dst
),
NORM_INF
)
<
1e-3
;
std
::
cout
<<
"GPU #"
<<
device_id
<<
" ("
<<
DeviceInfo
().
name
()
<<
"): "
<<
(
passed
?
"passed"
:
"FAILED"
)
<<
endl
;
// Deallocate data here, otherwise deallocation will be performed
// after context is extracted from the stack
d_src
.
release
();
d_dst
.
release
();
}
#endif
samples/gpu/opengl.cpp
View file @
396f7e1a
#include <iostream>
#include "cvconfig.h"
#ifndef HAVE_OPENGL
int
main
()
{
std
::
cerr
<<
"Library was built without OpenGL support"
<<
std
::
endl
;
return
-
1
;
}
#else
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN 1
...
...
samples/gpu/opticalflow_nvidia_api.cpp
View file @
396f7e1a
...
...
@@ -9,26 +9,14 @@
#include <ctime>
#include <ctype.h>
#include "cvconfig.h"
#include <iostream>
#include <iomanip>
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/highgui/highgui.hpp"
#ifdef HAVE_CUDA
#include "NPP_staging/NPP_staging.hpp"
#include "NCVBroxOpticalFlow.hpp"
#endif
#if !defined(HAVE_CUDA)
int
main
(
int
,
const
char
**
)
{
std
::
cout
<<
"Please compile the library with CUDA support"
<<
std
::
endl
;
return
-
1
;
}
#else
//using std::tr1::shared_ptr;
using
cv
::
Ptr
;
#define PARAM_LEFT "--left"
...
...
@@ -649,5 +637,3 @@ int main(int argc, char **argv)
return
0
;
}
#endif
samples/gpu/performance/CMakeLists.txt
View file @
396f7e1a
...
...
@@ -27,7 +27,7 @@ if(WIN32)
endif
()
if
(
INSTALL_C_EXAMPLES AND NOT WIN32
)
file
(
GLOB GPU_FILES performance/*.cpp performance/*.h
)
file
(
GLOB GPU_FILES performance/*.cpp performance/*.h
performance/CMakeLists.txt
)
install
(
FILES
${
GPU_FILES
}
DESTINATION
${
OPENCV_SAMPLES_SRC_INSTALL_PATH
}
/gpu/performance
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
...
...
samples/gpu/pyrlk_optical_flow.cpp
View file @
396f7e1a
#include <iostream>
#include <vector>
#include "cvconfig.h"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
...
...
samples/ocl/CMakeLists.txt
View file @
396f7e1a
...
...
@@ -51,8 +51,8 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
endforeach
()
endif
()
if
(
INSTALL_C_EXAMPLES AND NOT WIN32
)
file
(
GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd
)
if
(
OCV_DEPENDENCIES_FOUND AND
INSTALL_C_EXAMPLES AND NOT WIN32
)
file
(
GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd
*.txt
)
install
(
FILES
${
install_list
}
DESTINATION
${
OPENCV_SAMPLES_SRC_INSTALL_PATH
}
/ocl
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples
)
...
...
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