Difference between revisions of "OpenCV"
Line 114: | Line 114: | ||
**Int32 (int) | **Int32 (int) | ||
− | |||
*Зарежда на изображение от файл | *Зарежда на изображение от файл | ||
Image<Rgb, Byte> img1 = new Image<Rgb, Byte>("c:/xxx/lenna.jpg"); | Image<Rgb, Byte> img1 = new Image<Rgb, Byte>("c:/xxx/lenna.jpg"); |
Revision as of 12:40, 5 February 2015
Разработва се с цел изчислителна ефективност при обработка на изображения и за приложения работещи в реално време. Съдържа стотици алгоритми от компютърното зрение. Използва се от интерактивни художествени постановки до инспекция на мини,
Има интерфейси за:
- C++
- C
- Python
- Java
- .net with EMGU
Поддържа:
- Windows
- Linux
- Mac OS
- iOS
- Android
- Written in optimized C/C++,
- поддържа multi-core processing
- Enabled with OpenCL, it can take advantage of the hardware acceleration
- OpenCV 47+ хиляди общност.
- 9+ million сваляния. Usage ranges from interactive art, to mines inspection, stitching maps on the web or through advanced robotics.
OpenCV is released under a BSD license and hence it’s free for both academic and commercial use.
Структура
Модулна структура, всяка от които съдържа споделени и статични библиотеки.
- core - модул за дефиниране на основните структури данни, включително многомерния масив Mat и всички основни функции използвани от другите модули.
- imgproc - модул за цифрова обработка на изображения
- линейни и не линейни филтри
- геометрични трансформации (resize, affine and perspective warping, generic table-based remapping)
- цветови трансформации (RGB, HSV, grey ...)
- хистограми и др.
- video - модул за анализ на видео изпображения
- откриване на движение
- следене на обекти
- премахване на фон
- calib3d - алгоритми за 3D обработка
- single and stereo camera calibration,
- object pose estimation
- stereo correspondence algorithms
- elements of 3D reconstruction.
- features2d - намиране на специфични точки и области в статични изображения (salient feature detectors, descriptors, and descriptor matchers.)
- objdetect - откривана на обекти от предварително дефинирани класове (for example, faces, eyes, mugs, people, cars, and so on).
- highgui - интерфейс за видео заснемане, кодеци за изображения и видео (jpeg,mpeg), потребителски интерфей
- gpu - GPU оптимизирани алгоритми от различните модули на OpenCV.
- ... some other helper modules, such as FLANN and Google test wrappers, Python bindings, and others.
Концепция
Всички API - та са в cv namespace
Automatic Memory Management
Automatic Allocation of the Output Data
Saturation Arithmetics
I(x,y)=min(max(round(r),0),255)
Fixed Pixel Types. Limited Use of Templates 8-bit unsigned integer (uchar) 8-bit signed integer (schar) 16-bit unsigned integer (ushort) 16-bit signed integer (short) 32-bit signed integer (int) 32-bit floating-point number (float) 64-bit floating-point number (double) a tuple of several elements where all elements have the same type (one of the above). An array whose elements are such tuples, are called multi-channel arrays, as opposite to the single-channel arrays, whose elements are scalar values. The maximum possible number of channels is defined by the CV_CN_MAX constant, which is currently set to 512
.. InputArray and OutputArray¶ Many OpenCV functions process dense 2-dimensional or multi-dimensional numerical arrays. Usually, such functions take cpp:class:Mat as parameters, but in some cases it’s more convenient to use std::vector<> (for a point set, for example) or Matx<> (for 3x3 homography matrix and such). To avoid many duplicates in the API, special “proxy” classes have been introduced. The base “proxy” class is InputArray. It is used for passing read-only arrays on a function input. The derived from InputArray class OutputArray is used to specify an output array for a function. Normally, you should not care of those intermediate types (and you should not declare variables of those types explicitly) - it will all just work automatically. You can assume that instead of InputArray/OutputArray you can always use Mat, std::vector<>, Matx<>, Vec<> or Scalar. When a function has an optional input or output array, and you do not have or do not want one, pass cv::noArray().
Error Handling OpenCV uses exceptions to signal critical errors. When the input data has a correct format and belongs to the specified value range, but the algorithm cannot succeed for some reason (for example, the optimization algorithm did not converge), it returns a special error code (typically, just a boolean variable).
The exceptions can be instances of the cv::Exception class or its derivatives. In its turn, cv::Exception is a derivative of std::exception. So it can be gracefully handled in the code using other standard C++ library components.
The exception is typically thrown either using the CV_Error(errcode, description) macro, or its printf-like CV_Error_(errcode, printf-spec, (printf-args)) variant, or using the CV_Assert(condition) macro that checks the condition and throws an exception when it is not satisfied. For performance-critical code, there is CV_DbgAssert(condition) that is only retained in the Debug configuration. Due to the automatic memory management, all the intermediate buffers are automatically deallocated in case of a sudden error. You only need to add a try statement to catch exceptions, if needed:
try {
... // call OpenCV
} catch( cv::Exception& e ) {
const char* err_msg = e.what(); std::cout << "exception caught: " << err_msg << std::endl;
} Multi-threading and Re-enterability
типове данни
Image За дефиниране на черно бяло изображение ще използваме
Image<Gray, Byte> snimka = new Image<Gray, Byte>( width, height);
Изображение се дефинира с неговите основни параметри: цветове (Tcolor) и дълбочина (Tdepth)
- цветове - цветови канали и цветова схема
- Gray
- Bgr (Blue Green Red)
- Bgra (Blue Green Red Alpha)
- Hsv (Hue Saturation Value)
- Hls (Hue Lightness Saturation)
- Lab (CIE L*a*b*)
- Luv (CIE L*u*v*)
- Xyz (CIE XYZ.Rec 709 with D65 white point)
- Ycc (YCrCb JPEG)
- дълбочина - бита на канал
- Byte
- SByte
- Single (float)
- Double
- UInt16
- Int16
- Int32 (int)
- Зарежда на изображение от файл
Image<Rgb, Byte> img1 = new Image<Rgb, Byte>("c:/xxx/lenna.jpg");
- Създаване на празно избражение
Image<Bgr, Byte> img1 = new Image<Bgr, Byte>(480, 320);
- Създаване на празно избражение със син фон
Image<Bgr, Byte> img = new Image<Bgr, Byte>(256, 256, new Bgr(255, 0, 0));
new Bgr(255, 0, 0) - създава цвета
Конвертране
Image<Gray, Byte> gray = img1.Convert<Gray, Byte>();
Рисуване
Използване на Draw()
Image<Bgr, Byte> img = new Image<Bgr, Byte>(256, 256, new Bgr(255, 0, 0)); Point p = new Point(20, 20); Size r = new Size(20,20); Rectangle rec = new Rectangle( p, r); img.Draw(rec, new Bgr(255, 255, 0), 2); pictureBox1.Image = img.Bitmap;
Matrici
Depth as Generic Parameter A Matrix is defined by its generic parameters depth. To create a 32bit floating point matrix, in Emgu CV it is done by calling Matrix<Single> matrix = new Matrix<Single>(width, height); Matrix Depth The types of depth supported in Emgu CV 1.4.0.0 include Byte SByte Single (float) Double UInt16 Int16 Int32 (int)