Prezentare fără titlu

Preview:

Citation preview

OpenCVImage processing

Installation 1. Clone the git repository git clone https://github.com/Itseez/opencv.git2. Copy “opencv2.framework” into your project3. Current stable version: 2.4

Usage1. Import opencv2 into the project, preferably into the .pch file#ifdef __cplusplus#import <opencv2/opencv.hpp>#endif2. In order to use the library, the implementation files should be compiled as c++ files. In XCode, this can be done by changing the extension of the file from .m to .mm

* All the implementation files that use the c++ compiled code, should also have .mm extension.

ModulesOpenCV has a modular structure, including several shared or static libraries:1. core - basic data structures2. imgproc - image processing module3. video - video analysis module3. calib3d - element of 3d reconstruction4. features2d - feature detectors5. objdetect - detection of objects and instances of predefined clases6. highgui - easy to use ui for capture7. gpu - gpu accelerated algorithms

API conceptsAll the OpenCV classes and functions are placed into the cv namespace

Insted of “using namespace cv”, explicit namespace specifiers should be used to resolve the name conflicts

cv::Mat a;

API conceptsAutomatic Memory Management- Data structures used by functions/methods have destructors that deallocate the underlying memory buffers when needed.Automatic Allocation of Output data- Output parameters are automatically allocated

cv::Mat edges;cv::cvtColor(frame, edges, CV_BGR2GRAY);

API concepts1. There is a limited fixed set of primitive data types the library can operate on (array elements should have one of the following types):- 8-bit unsigned integer- 8-bit signed integer- 16-bit unsigned integer- 16-bit signed integer- 32-bit signed integer- 32-bit floating-point number- 64-bit floating-point number- a tuple of several elements (all elements have the same type)2. Declaration:CV_(bit number)C(channels number). ex: CV_8UC1

Image processing1. In OpenCV all the image processing are usually carried out on the cv::Mat structure.2. In iOS we need UIImages3. CoreGraphics can be used to convert back and forth between Mat/UIImage

Image processingOnce we have the OpenCV data structure (Mat instead of a UIImage), functions can be applied on it based on the needs.Example:

cv::Mat mat_image;mat_image = [UIImage cvMatFromUIImage:image];cv::Mat blurred(mat_image);cv::medianBlur(mat_image, blurred, 9);cv::Canny(blurred, img_edge, thresh1, thresh2, 3);

Image processingcv::Canny(cv::Mat image, cv::Mat edges, double threshold1, double threshold2, int apertureSize)

cv::HoughLinesP(cv::Mat image, cv::vector<cv::Vec4i> lines, double rho, double theta, int threshold, double minLineLength, double maxLineGap)

ApplicationObjective: Find object contours in order to convert them into sketches

Iteration 1:

- Find lines using the hough probabilistic transformation- Filter the lines - Find edges based on the discovered lines- Find the relationship between lines and edges in order to define contours

Application1. Find lines using the hough probabilistic transformation

- Use the blur function in order to reduce the noisecv::blur(mat_sourceImage, mat_blur, cv::Size(3,3));- Use the canny edge detector in order to obtain a binary matrix containing the edgescv::Canny(img_blur, img_edges, minVal, maxVal, apertureSize);- Use hough probabilistic transformation to detect lines delitiming objectscv::HoughLinesP(img_edge, lines, rho, theta, threshold, minLineLength, maxLineGap)

Application2. Define line objects

A line object has the follwoing properties: - Start point, end point - Slope angle - Length - Bounding box

Application3. Filter the lines (horizontal and vertical)

- The lines found using HT are conditionally added into an array- When adding a new line into the array, the shortest angle between it and any other existing line is calculated : 1. If the absolute value of the angle is less than 10 && the line is horizontal, check the delta x between the lines and if it is below a minimum limit, merge the two lines (without adding the new line into the array)

2. If the absolute value of the angle is less than 10 && the line is vertical, check the delta y between the lines and if it is below a minimum limit, merge the two lines (without adding the new line into the array)

Application4. Define edge objects

An edge object has the follwoing properties: - Position - First line - Second line

Application5. Find edges based on the discovered lines

- Iterate through the lines- Check if the shortest angle between any two lines is +/- 10 equal to 90 degrees- Check the distance between the the closest points of the two lines- If the distance is below a minimum limit, the point should be considered an edge

Application6. Find the relationship between edges and lines in order to define contours

- To be done

Documentationhttp://docs.opencv.org - API reference

http://docs.opencv.org/trunk/doc/tutorials/ios/table_of_content_ios/table_of_content_ios.html#table-of-content-ios - iOS tutorials

Recommended