Sie sind auf Seite 1von 14

OpenCV 3.

0
and its Transparent API
OpenCV v3.0: moving towards
community-driven project
OpenCV 3.0 is scheduled for 2014Q1 (*)
Will not be compatible with OpenCV 2.x (users
code may require some adjustments)
Essentially similar to 2.x, but:
even more modular and extendible
refined and super-stable API
deprecated old API
better packaging
out-of-box GPU acceleration, a.k.a. transparent API
(*) may probably slip to Q2 if there is not enough resources
External Modules
Since 3.0 new modules could be developed
without putting them into the main OpenCV tree:
opencv/
modules/
core/
include/, doc/, src/, test/,
CMakeLists.txt
imgproc

my_extra_modules/
sfm/
include/, doc/, src/, test/,
CMakeLists.txt

$ cmake D OPENCV_EXTRA_MODULES_PATH=~/my_extra_modules
Experimental or
proprietary code
http://github.com/itseez/opencv_contrib is the official repository of such modules
External Modules
If it works out, we gonna see a lot of not
properly tested, diverse-style, sub-optimal
code; need to provide:
buildbot to check the contributed code
solid code guidelines
convenient acceleration API (like transparent API)
OpenCV 2.x
OpenCV 3.x
contributions
Core
OpenCV
3.x
New-style API
All the high-level vision algorithms (face detectors, optical flow estimators, stereo
matchers etc.) are declared as pure abstract classes (aka interfaces in Java)
Constructed using special factory function
Array/image parameters are declared as Input/OutputArray(s)
class StereoMatcher : public Algorithm // Algorithm is used as a base
{
public: // common methods for all stereo matchers
virtual void compute(InputArray left, InputArray right,
OutputArray disp) = 0;

};
class StereoBM : public StereoMatcher
{
public: // specific methods for particular algorithm
virtual void setUniquenessRatio(int ratio) = 0;

};
// factory function
Ptr<StereoBM> createStereoBM();
New-style API: Impact
Implementation may be changed arbitrary as long as
interface stays the same => binary compatibility can be
preserved for years!
Interface stability will be checked by our buildbot
automatically
Input/OutputArray(s) enable automatic CPU/GPU
dispatching (see slides on UMat)
With a different factory function one can provide
drop-out replacements for existing algorithms
More convenient packaging and
better out-of-the-box performance
Emphasis on binary packages.
Automated regular builds of github snapshots
One-size-fits-all: all the optimization is put in and is
being engaged if host hardware supports it
SSE2 optimization is built-in; Neon optimization to come
universal parallel_for implementation is already in.
OpenCL acceleration will always be built-in (starting
from 2.4.7)
Transparent API
same code can run on CPU or GPU no specialized
cv::Canny, ocl::Canny, etc; no recompilation is
needed
should be similar to the existing API
minimal or no changes in the existing code
CPU-only processing no changes should be required
includes the following key components:
new data structure UMat
simple and robust mechanism for async processing
convenient low-level API for custom algorithm
implementation (TBD in 3.x)
UMat
UMat is new type of array that wraps clmem when OpenCL is available
Replacing Mat with UMat is often the only change needed
int main(int argc, char** argv)
{
UMat img, gray;
imread(argv[1], 1, img);
imshow("original", img);

cvtColor(img, gray, COLOR_BGR2GRAY);
GaussianBlur(gray, gray,
Size(7, 7), 1.5);
Canny(gray, gray, 0, 50);
imshow("edges", gray);
waitKey();
return 0;
}
int main(int argc, char** argv)
{
Mat img, gray;
img = imread(argv[1], 1);
imshow("original", img);

cvtColor(img, gray, COLOR_BGR2GRAY);
GaussianBlur(gray, gray,
Size(7, 7), 1.5);
Canny(gray, gray, 0, 50);
imshow("edges", gray);
waitKey();
return 0;
}
Transparent API: under the hood
bool _ocl_cvtColor(InputArray src, OutputArray dst, int code) {
static ocl::ProgramSource oclsrc(//cvtcolor.cl source code );
UMat src_ocl = src.getUMat(), dst_ocl = dst.getUMat();
if (code == COLOR_BGR2GRAY) {
// get the kernel; kernel is compiled only once and cached
ocl::Kernel kernel(bgr2gray, oclsrc, <compile_flags>);
// pass 2 arrays to the kernel and run it
return kernel.args(src, dst).run(0, 0, false);
} else if(code == COLOR_BGR2YUV) { }
return false;
}
void _cpu_cvtColor(const Mat& src, Mat& dst, int code) { }
// transparent API dispatcher function
void cvtColor(InputArray src, OutputArray dst, int code) {
dst.create(src.size(), );
if (useOpenCL(src, dst) && _ocl_cvtColor(src, dst, code)) return;
// getMat() uses zero-copy if available; and with SVM its no op
Mat src_cpu = src.getMat();
Mat dst_cpu = dst.getMat();
_cpu_cvtColor(src_cpu, dst_cpu, code);
}
Semi-transparent API
Use alternative implementation and the factory function
When accuracy is not good enough
When the implementation is completely different
When there is no CPU version:
namespace cv { namespace VendorA {
Ptr<StereoBM> createStereoBMFast();
}}

Ptr<StereoBM> stereomatcher = <> ?


cv::createStereoBM() :
cv::VendorA::createStereoBMFast();

stereomatcher->compute(left, right, disp);


OpenCV+OpenCL execution model
One queue and one OpenCL device per CPU thread
OpenCL kernels are executed asynchronously
cv::cl::finish() puts the barrier in the current CPU thread;
.getMat() automatically calls it.

cv::ocl::Queue
cv::ocl::Device
cv::ocl::Queue cv::ocl::Queue
cv::ocl::Device

cv::ocl::Context
CPU threads
OpenCV QA
Contribution/patch workflow:
see OpenCV wiki
build.opencv.org: buildbot with 50+ builders
pullrequest.opencv.org: tests each pullrequest
github.com/itseez/opencv
OpenCV test suite
GoogleTest-based + set of Python scripts
Several hundred dedicated tests
Accuracy tests
Performance tests
python ../modules/ts/misc/summary.py core*.xml -f "add:.*C4" -u s
Geometric mean
Name of Test core core core
posix posix posix
x64 x64 x64
6693M 6695 6695
2011-09-08--13-13-41 2011-09-08--13-30-06 2011-09-08--13-30-06
vs
core
posix
x64
6693M
2011-09-08--13-13-41
core_arithm__add::Size_MatType::(127x61, 8UC4) 0.000 s 0.000 s 1.00
core_arithm__add::Size_MatType::(1280x720, 8UC4) 0.004 s 0.004 s 0.99
core_arithm__add::Size_MatType::(1920x1080, 8UC4) 0.009 s 0.009 s 1.02
core_arithm__add::Size_MatType::(640x480, 8UC4) 0.001 s 0.001 s 1.00

Das könnte Ihnen auch gefallen