From 36a04ef8dee10ce76a21ff54ab062121d672c55d Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 28 Nov 2014 16:21:28 +0300 Subject: [PATCH] Doxygen tutorials: cpp done --- doc/opencv.bib | 8 + .../camera_calibration.markdown | 20 +- .../real_time_pose/real_time_pose.markdown | 1352 +++++++++-------- .../core/adding_images/adding_images.markdown | 8 +- .../basic_geometric_drawing.markdown | 10 +- .../basic_linear_transform.markdown | 14 +- .../discrete_fourier_transform.markdown | 32 +- .../file_input_output_with_xml_yml.markdown | 20 +- .../how_to_scan_images.markdown | 56 +- .../tutorial_how_matrix_stored_1.png | Bin 0 -> 1953 bytes .../tutorial_how_matrix_stored_2.png | Bin 0 -> 3905 bytes .../how_to_use_ippa_conversion.markdown | 20 +- .../interoperability_with_OpenCV_1.markdown | 41 +- .../mat_mask_operations.markdown | 2 +- .../mat_the_basic_image_container.markdown | 163 +- .../random_generator_and_text.markdown | 42 +- .../akaze_matching/akaze_matching.markdown | 158 +- .../akaze_matching/akaze_matching.rst | 11 +- .../akaze_tracking/akaze_tracking.markdown | 126 +- .../feature_description.markdown | 2 +- .../feature_detection.markdown | 8 +- .../feature_flann_matcher.markdown | 8 +- .../feature_homography.markdown | 4 +- .../corner_subpixeles.markdown | 4 +- .../generic_corner_detector.markdown | 4 +- .../good_features_to_track.markdown | 2 +- .../harris_detector/harris_detector.markdown | 4 +- .../table_of_content_general.markdown | 8 - .../gpu_basics_similarity.markdown | 43 +- .../{flood-zone.jpg => gdal_flood-zone.jpg} | Bin .../{heat-map.jpg => gdal_heat-map.jpg} | Bin .../images/{output.jpg => gdal_output.jpg} | Bin .../raster-gdal/raster_io_gdal.markdown | 7 +- .../highgui/raster-gdal/raster_io_gdal.rst | 6 +- .../highgui/trackbar/trackbar.markdown | 14 +- .../video_input_psnr_ssim.markdown | 15 +- .../highgui/video-write/video_write.markdown | 14 +- .../erosion_dilatation.markdown | 16 +- ...sian_median_blur_bilateral_filter.markdown | 23 +- .../back_projection/back_projection.markdown | 124 +- .../histogram_calculation.markdown | 28 +- .../histogram_comparison.markdown | 63 +- .../histogram_equalization.markdown | 30 +- .../template_matching.markdown | 152 +- .../canny_detector/canny_detector.markdown | 63 +- .../copyMakeBorder/copyMakeBorder.markdown | 102 +- .../imgtrans/filter_2d/filter_2d.markdown | 32 +- .../hough_circle/hough_circle.markdown | 79 +- .../imgtrans/hough_lines/hough_lines.markdown | 118 +- .../laplace_operator.markdown | 92 +- .../imgproc/imgtrans/remap/remap.markdown | 139 +- .../sobel_derivatives.markdown | 57 +- .../imgtrans/warp_affine/warp_affine.markdown | 145 +- ...r.jpg => Morphology_2_Tutorial_Result.jpg} | Bin .../opening_closing_hats.markdown | 45 +- .../opening_closing_hats.rst | 2 +- .../imgproc/pyramids/pyramids.markdown | 12 +- .../bounding_rects_circles.markdown | 90 +- .../bounding_rotated_ellipses.markdown | 92 +- .../find_contours/find_contours.markdown | 75 +- .../shapedescriptors/moments/moments.markdown | 97 +- .../point_polygon_test.markdown | 85 +- .../imgproc/threshold/threshold.markdown | 116 +- .../android_binary_package/O4A_SDK.markdown | 53 +- .../android_dev_intro.markdown | 294 ++-- .../dev_with_OCV_on_Android.markdown | 62 +- .../clojure_dev_intro.markdown | 35 +- .../arm_crosscompile_with_cmake.markdown | 14 +- .../desktop_java/java_dev_intro.markdown | 18 +- .../display_image/display_image.markdown | 49 +- .../ios_install/ios_install.markdown | 4 +- .../java_eclipse/java_eclipse.markdown | 24 +- .../linux_eclipse/linux_eclipse.markdown | 70 +- .../linux_gcc_cmake/linux_gcc_cmake.markdown | 10 +- .../linux_install/linux_install.markdown | 20 +- .../load_save_image/load_save_image.markdown | 14 +- .../windows_install/windows_install.markdown | 64 +- .../windows_visual_studio_Opencv.markdown | 32 +- ...windows_visual_studio_image_watch.markdown | 28 +- doc/tutorials/ios/hello/hello.markdown | 49 +- .../image_manipulation.markdown | 18 +- .../video_processing.markdown | 8 +- .../introduction_to_svm.markdown | 30 +- .../non_linear_svms/non_linear_svms.markdown | 32 +- .../cascade_classifier.markdown | 8 +- .../photo/hdr_imaging/hdr_imaging.markdown | 145 +- doc/tutorials/tutorials.markdown | 5 - .../background_subtraction.markdown | 224 +-- .../creating_widgets.markdown | 133 +- .../viz/launching_viz/launching_viz.markdown | 92 +- .../transformations/transformations.markdown | 155 +- .../viz/widget_pose/widget_pose.markdown | 134 +- 92 files changed, 2189 insertions(+), 3738 deletions(-) create mode 100644 doc/tutorials/core/how_to_scan_images/tutorial_how_matrix_stored_1.png create mode 100644 doc/tutorials/core/how_to_scan_images/tutorial_how_matrix_stored_2.png delete mode 100644 doc/tutorials/general/table_of_content_general/table_of_content_general.markdown rename doc/tutorials/highgui/raster-gdal/images/{flood-zone.jpg => gdal_flood-zone.jpg} (100%) rename doc/tutorials/highgui/raster-gdal/images/{heat-map.jpg => gdal_heat-map.jpg} (100%) rename doc/tutorials/highgui/raster-gdal/images/{output.jpg => gdal_output.jpg} (100%) rename doc/tutorials/imgproc/opening_closing_hats/images/{Morphology_2_Tutorial_Cover.jpg => Morphology_2_Tutorial_Result.jpg} (100%) diff --git a/doc/opencv.bib b/doc/opencv.bib index 09206587a2..52e5dc1b2d 100644 --- a/doc/opencv.bib +++ b/doc/opencv.bib @@ -824,3 +824,11 @@ journal = {Machine learning}, volume = {10} } +@inproceedings{vacavant2013benchmark, + title={A benchmark dataset for outdoor foreground/background extraction}, + author={Vacavant, Antoine and Chateau, Thierry and Wilhelm, Alexis and Lequi{\`e}vre, Laurent}, + booktitle={Computer Vision-ACCV 2012 Workshops}, + pages={291--300}, + year={2013}, + organization={Springer} +} diff --git a/doc/tutorials/calib3d/camera_calibration/camera_calibration.markdown b/doc/tutorials/calib3d/camera_calibration/camera_calibration.markdown index ded33145f8..0f1eaf90c6 100644 --- a/doc/tutorials/calib3d/camera_calibration/camera_calibration.markdown +++ b/doc/tutorials/calib3d/camera_calibration/camera_calibration.markdown @@ -96,7 +96,7 @@ on how to do this you can find in the @ref tutorial_file_input_output_with_xml_y Explanation ----------- -1. **Read the settings.** +-# **Read the settings.** @code{.cpp} Settings s; const string inputSettingsFile = argc > 1 ? argv[1] : "default.xml"; @@ -119,7 +119,7 @@ Explanation additional post-processing function that checks validity of the input. Only if all inputs are good then *goodInput* variable will be true. -2. **Get next input, if it fails or we have enough of them - calibrate**. After this we have a big +-# **Get next input, if it fails or we have enough of them - calibrate**. After this we have a big loop where we do the following operations: get the next image from the image list, camera or video file. If this fails or we have enough images then we run the calibration process. In case of image we step out of the loop and otherwise the remaining frames will be undistorted (if the @@ -151,7 +151,7 @@ Explanation @endcode For some cameras we may need to flip the input image. Here we do this too. -3. **Find the pattern in the current input**. The formation of the equations I mentioned above aims +-# **Find the pattern in the current input**. The formation of the equations I mentioned above aims to finding major patterns in the input: in case of the chessboard this are corners of the squares and for the circles, well, the circles themselves. The position of these will form the result which will be written into the *pointBuf* vector. @@ -212,7 +212,7 @@ Explanation drawChessboardCorners( view, s.boardSize, Mat(pointBuf), found ); } @endcode -4. **Show state and result to the user, plus command line control of the application**. This part +-# **Show state and result to the user, plus command line control of the application**. This part shows text output on the image. @code{.cpp} //----------------------------- Output Text ------------------------------------------------ @@ -263,7 +263,7 @@ Explanation imagePoints.clear(); } @endcode -5. **Show the distortion removal for the images too**. When you work with an image list it is not +-# **Show the distortion removal for the images too**. When you work with an image list it is not possible to remove the distortion inside the loop. Therefore, you must do this after the loop. Taking advantage of this now I'll expand the @ref cv::undistort function, which is in fact first calls @ref cv::initUndistortRectifyMap to find transformation matrices and then performs @@ -291,6 +291,7 @@ Explanation } } @endcode + The calibration and save ------------------------ @@ -419,6 +420,7 @@ double rms = calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, return std::sqrt(totalErr/totalPoints); // calculate the arithmetical mean } @endcode + Results ------- @@ -444,21 +446,21 @@ images/CameraCalibration/VID5/xx8.jpg Then passed `images/CameraCalibration/VID5/VID5.XML` as an input in the configuration file. Here's a chessboard pattern found during the runtime of the application: -![image](images/fileListImage.jpg) +![](images/fileListImage.jpg) After applying the distortion removal we get: -![image](images/fileListImageUnDist.jpg) +![](images/fileListImageUnDist.jpg) The same works for [this asymmetrical circle pattern ](acircles_pattern.png) by setting the input width to 4 and height to 11. This time I've used a live camera feed by specifying its ID ("1") for the input. Here's, how a detected pattern should look: -![image](images/asymetricalPattern.jpg) +![](images/asymetricalPattern.jpg) In both cases in the specified output XML/YAML file you'll find the camera and distortion coefficients matrices: -@code{.cpp} +@code{.xml} 3 3 diff --git a/doc/tutorials/calib3d/real_time_pose/real_time_pose.markdown b/doc/tutorials/calib3d/real_time_pose/real_time_pose.markdown index ba7d6e095c..ee54e4d38a 100644 --- a/doc/tutorials/calib3d/real_time_pose/real_time_pose.markdown +++ b/doc/tutorials/calib3d/real_time_pose/real_time_pose.markdown @@ -39,7 +39,7 @@ DLT. The most common simplification is to assume known calibration parameters which is the so-called Perspective-*n*-Point problem: -![image](images/pnp.jpg) +![](images/pnp.jpg) **Problem Formulation:** Given a set of correspondences between 3D points \f$p_i\f$ expressed in a world reference frame, and their 2D projections \f$u_i\f$ onto the image, we seek to retrieve the pose (\f$R\f$ @@ -61,703 +61,709 @@ You can find the source code of this tutorial in the The tutorial consists of two main programs: -1. **Model registration** +-# **Model registration** + + This applicaton is exclusive to whom don't have a 3D textured model of the object to be detected. + You can use this program to create your own textured 3D model. This program only works for planar + objects, then if you want to model an object with complex shape you should use a sophisticated + software to create it. + + The application needs an input image of the object to be registered and its 3D mesh. We have also + to provide the intrinsic parameters of the camera with which the input image was taken. All the + files need to be specified using the absolute path or the relative one from your application’s + working directory. If none files are specified the program will try to open the provided default + parameters. + + The application starts up extracting the ORB features and descriptors from the input image and + then uses the mesh along with the [Möller–Trumbore intersection + algorithm](http://http://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm/) + to compute the 3D coordinates of the found features. Finally, the 3D points and the descriptors + are stored in different lists in a file with YAML format which each row is a different point. The + technical background on how to store the files can be found in the @ref tutorial_file_input_output_with_xml_yml + tutorial. + + ![](images/registration.png) + +-# **Model detection** + + The aim of this application is estimate in real time the object pose given its 3D textured model. + + The application starts up loading the 3D textured model in YAML file format with the same + structure explained in the model registration program. From the scene, the ORB features and + descriptors are detected and extracted. Then, is used @ref cv::FlannBasedMatcher with + @ref cv::flann::GenericIndex to do the matching between the scene descriptors and the model descriptors. + Using the found matches along with @ref cv::solvePnPRansac function the `R` and `t` of + the camera are computed. Finally, a KalmanFilter is applied in order to reject bad poses. + + In the case that you compiled OpenCV with the samples, you can find it in opencv/build/bin/cpp-tutorial-pnp_detection\`. + Then you can run the application and change some parameters: + @code{.cpp} + This program shows how to detect an object given its 3D textured model. You can choose to use a recorded video or the webcam. + Usage: + ./cpp-tutorial-pnp_detection -help + Keys: + 'esc' - to quit. + -------------------------------------------------------------------------- + + Usage: cpp-tutorial-pnp_detection [params] + + -c, --confidence (value:0.95) + RANSAC confidence + -e, --error (value:2.0) + RANSAC reprojection errror + -f, --fast (value:true) + use of robust fast match + -h, --help (value:true) + print this message + --in, --inliers (value:30) + minimum inliers for Kalman update + --it, --iterations (value:500) + RANSAC maximum iterations count + -k, --keypoints (value:2000) + number of keypoints to detect + --mesh + path to ply mesh + --method, --pnp (value:0) + PnP method: (0) ITERATIVE - (1) EPNP - (2) P3P - (3) DLS + --model + path to yml model + -r, --ratio (value:0.7) + threshold for ratio test + -v, --video + path to recorded video + @endcode + For example, you can run the application changing the pnp method: + @code{.cpp} + ./cpp-tutorial-pnp_detection --method=2 + @endcode -This applicaton is exclusive to whom don't have a 3D textured model of the object to be detected. -You can use this program to create your own textured 3D model. This program only works for planar -objects, then if you want to model an object with complex shape you should use a sophisticated -software to create it. - -The application needs an input image of the object to be registered and its 3D mesh. We have also -to provide the intrinsic parameters of the camera with which the input image was taken. All the -files need to be specified using the absolute path or the relative one from your application’s -working directory. If none files are specified the program will try to open the provided default -parameters. - -The application starts up extracting the ORB features and descriptors from the input image and -then uses the mesh along with the [Möller–Trumbore intersection -algorithm](http://http://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm/) -to compute the 3D coordinates of the found features. Finally, the 3D points and the descriptors -are stored in different lists in a file with YAML format which each row is a different point. The -technical background on how to store the files can be found in the @ref tutorial_file_input_output_with_xml_yml -tutorial. - -![image](images/registration.png) - -2. **Model detection** - -The aim of this application is estimate in real time the object pose given its 3D textured model. - -The application starts up loading the 3D textured model in YAML file format with the same -structure explained in the model registration program. From the scene, the ORB features and -descriptors are detected and extracted. Then, is used @ref cv::FlannBasedMatcher with -@ref cv::flann::GenericIndex to do the matching between the scene descriptors and the model descriptors. -Using the found matches along with @ref cv::solvePnPRansac function the `R` and `t` of -the camera are computed. Finally, a KalmanFilter is applied in order to reject bad poses. - -In the case that you compiled OpenCV with the samples, you can find it in opencv/build/bin/cpp-tutorial-pnp_detection\`. -Then you can run the application and change some parameters: -@code{.cpp} -This program shows how to detect an object given its 3D textured model. You can choose to use a recorded video or the webcam. -Usage: - ./cpp-tutorial-pnp_detection -help -Keys: - 'esc' - to quit. --------------------------------------------------------------------------- - -Usage: cpp-tutorial-pnp_detection [params] - - -c, --confidence (value:0.95) - RANSAC confidence - -e, --error (value:2.0) - RANSAC reprojection errror - -f, --fast (value:true) - use of robust fast match - -h, --help (value:true) - print this message - --in, --inliers (value:30) - minimum inliers for Kalman update - --it, --iterations (value:500) - RANSAC maximum iterations count - -k, --keypoints (value:2000) - number of keypoints to detect - --mesh - path to ply mesh - --method, --pnp (value:0) - PnP method: (0) ITERATIVE - (1) EPNP - (2) P3P - (3) DLS - --model - path to yml model - -r, --ratio (value:0.7) - threshold for ratio test - -v, --video - path to recorded video -@endcode -For example, you can run the application changing the pnp method: -@code{.cpp} -./cpp-tutorial-pnp_detection --method=2 -@endcode Explanation ----------- Here is explained in detail the code for the real time application: -1. **Read 3D textured object model and object mesh.** - -In order to load the textured model I implemented the *class* **Model** which has the function -*load()* that opens a YAML file and take the stored 3D points with its corresponding descriptors. -You can find an example of a 3D textured model in -`samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/Data/cookies_ORB.yml`. -@code{.cpp} -/* Load a YAML file using OpenCV */ -void Model::load(const std::string path) -{ - cv::Mat points3d_mat; - - cv::FileStorage storage(path, cv::FileStorage::READ); - storage["points_3d"] >> points3d_mat; - storage["descriptors"] >> descriptors_; - - points3d_mat.copyTo(list_points3d_in_); - - storage.release(); - -} -@endcode -In the main program the model is loaded as follows: -@code{.cpp} -Model model; // instantiate Model object -model.load(yml_read_path); // load a 3D textured object model -@endcode -In order to read the model mesh I implemented a *class* **Mesh** which has a function *load()* -that opens a \f$*\f$.ply file and store the 3D points of the object and also the composed triangles. -You can find an example of a model mesh in -`samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/Data/box.ply`. -@code{.cpp} -/* Load a CSV with *.ply format */ -void Mesh::load(const std::string path) -{ - - // Create the reader - CsvReader csvReader(path); +-# **Read 3D textured object model and object mesh.** - // Clear previous data - list_vertex_.clear(); - list_triangles_.clear(); - - // Read from .ply file - csvReader.readPLY(list_vertex_, list_triangles_); - - // Update mesh attributes - num_vertexs_ = list_vertex_.size(); - num_triangles_ = list_triangles_.size(); - -} -@endcode -In the main program the mesh is loaded as follows: -@code{.cpp} -Mesh mesh; // instantiate Mesh object -mesh.load(ply_read_path); // load an object mesh -@endcode -You can also load different model and mesh: -@code{.cpp} -./cpp-tutorial-pnp_detection --mesh=/absolute_path_to_your_mesh.ply --model=/absolute_path_to_your_model.yml -@endcode -2. **Take input from Camera or Video** - -To detect is necessary capture video. It's done loading a recorded video by passing the absolute -path where it is located in your machine. In order to test the application you can find a recorded -video in `samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/Data/box.mp4`. -@code{.cpp} -cv::VideoCapture cap; // instantiate VideoCapture -cap.open(video_read_path); // open a recorded video - -if(!cap.isOpened()) // check if we succeeded -{ - std::cout << "Could not open the camera device" << std::endl; - return -1; -} -@endcode -Then the algorithm is computed frame per frame: -@code{.cpp} -cv::Mat frame, frame_vis; - -while(cap.read(frame) && cv::waitKey(30) != 27) // capture frame until ESC is pressed -{ - - frame_vis = frame.clone(); // refresh visualisation frame - - // MAIN ALGORITHM - -} -@endcode -You can also load different recorded video: -@code{.cpp} -./cpp-tutorial-pnp_detection --video=/absolute_path_to_your_video.mp4 -@endcode -3. **Extract ORB features and descriptors from the scene** - -The next step is to detect the scene features and extract it descriptors. For this task I -implemented a *class* **RobustMatcher** which has a function for keypoints detection and features -extraction. You can find it in -`samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/RobusMatcher.cpp`. In your -*RobusMatch* object you can use any of the 2D features detectors of OpenCV. In this case I used -@ref cv::ORB features because is based on @ref cv::FAST to detect the keypoints and @ref cv::xfeatures2d::BriefDescriptorExtractor -to extract the descriptors which means that is fast and robust to rotations. You can find more -detailed information about *ORB* in the documentation. - -The following code is how to instantiate and set the features detector and the descriptors -extractor: -@code{.cpp} -RobustMatcher rmatcher; // instantiate RobustMatcher - -cv::FeatureDetector * detector = new cv::OrbFeatureDetector(numKeyPoints); // instatiate ORB feature detector -cv::DescriptorExtractor * extractor = new cv::OrbDescriptorExtractor(); // instatiate ORB descriptor extractor - -rmatcher.setFeatureDetector(detector); // set feature detector -rmatcher.setDescriptorExtractor(extractor); // set descriptor extractor -@endcode -The features and descriptors will be computed by the *RobustMatcher* inside the matching function. - -4. **Match scene descriptors with model descriptors using Flann matcher** - -It is the first step in our detection algorithm. The main idea is to match the scene descriptors -with our model descriptors in order to know the 3D coordinates of the found features into the -current scene. - -Firstly, we have to set which matcher we want to use. In this case is used -@ref cv::FlannBasedMatcher matcher which in terms of computational cost is faster than the -@ref cv::BFMatcher matcher as we increase the trained collectction of features. Then, for -FlannBased matcher the index created is *Multi-Probe LSH: Efficient Indexing for High-Dimensional -Similarity Search* due to *ORB* descriptors are binary. - -You can tune the *LSH* and search parameters to improve the matching efficiency: -@code{.cpp} -cv::Ptr indexParams = cv::makePtr(6, 12, 1); // instantiate LSH index parameters -cv::Ptr searchParams = cv::makePtr(50); // instantiate flann search parameters - -cv::DescriptorMatcher * matcher = new cv::FlannBasedMatcher(indexParams, searchParams); // instantiate FlannBased matcher -rmatcher.setDescriptorMatcher(matcher); // set matcher -@endcode -Secondly, we have to call the matcher by using *robustMatch()* or *fastRobustMatch()* function. -The difference of using this two functions is its computational cost. The first method is slower -but more robust at filtering good matches because uses two ratio test and a symmetry test. In -contrast, the second method is faster but less robust because only applies a single ratio test to -the matches. - -The following code is to get the model 3D points and its descriptors and then call the matcher in -the main program: -@code{.cpp} -// Get the MODEL INFO - -std::vector list_points3d_model = model.get_points3d(); // list with model 3D coordinates -cv::Mat descriptors_model = model.get_descriptors(); // list with descriptors of each 3D coordinate -@endcode -@code{.cpp} -// -- Step 1: Robust matching between model descriptors and scene descriptors - -std::vector good_matches; // to obtain the model 3D points in the scene -std::vector keypoints_scene; // to obtain the 2D points of the scene - -if(fast_match) -{ - rmatcher.fastRobustMatch(frame, good_matches, keypoints_scene, descriptors_model); -} -else -{ - rmatcher.robustMatch(frame, good_matches, keypoints_scene, descriptors_model); -} -@endcode -The following code corresponds to the *robustMatch()* function which belongs to the -*RobustMatcher* class. This function uses the given image to detect the keypoints and extract the -descriptors, match using *two Nearest Neighbour* the extracted descriptors with the given model -descriptors and vice versa. Then, a ratio test is applied to the two direction matches in order to -remove these matches which its distance ratio between the first and second best match is larger -than a given threshold. Finally, a symmetry test is applied in order the remove non symmetrical -matches. -@code{.cpp} -void RobustMatcher::robustMatch( const cv::Mat& frame, std::vector& good_matches, - std::vector& keypoints_frame, - const std::vector& keypoints_model, const cv::Mat& descriptors_model ) -{ - - // 1a. Detection of the ORB features - this->computeKeyPoints(frame, keypoints_frame); - - // 1b. Extraction of the ORB descriptors - cv::Mat descriptors_frame; - this->computeDescriptors(frame, keypoints_frame, descriptors_frame); - - // 2. Match the two image descriptors - std::vector > matches12, matches21; - - // 2a. From image 1 to image 2 - matcher_->knnMatch(descriptors_frame, descriptors_model, matches12, 2); // return 2 nearest neighbours - - // 2b. From image 2 to image 1 - matcher_->knnMatch(descriptors_model, descriptors_frame, matches21, 2); // return 2 nearest neighbours - - // 3. Remove matches for which NN ratio is > than threshold - // clean image 1 -> image 2 matches - int removed1 = ratioTest(matches12); - // clean image 2 -> image 1 matches - int removed2 = ratioTest(matches21); - - // 4. Remove non-symmetrical matches - symmetryTest(matches12, matches21, good_matches); - -} -@endcode -After the matches filtering we have to subtract the 2D and 3D correspondences from the found scene -keypoints and our 3D model using the obtained *DMatches* vector. For more information about -@ref cv::DMatch check the documentation. -@code{.cpp} -// -- Step 2: Find out the 2D/3D correspondences - -std::vector list_points3d_model_match; // container for the model 3D coordinates found in the scene -std::vector list_points2d_scene_match; // container for the model 2D coordinates found in the scene - -for(unsigned int match_index = 0; match_index < good_matches.size(); ++match_index) -{ - cv::Point3f point3d_model = list_points3d_model[ good_matches[match_index].trainIdx ]; // 3D point from model - cv::Point2f point2d_scene = keypoints_scene[ good_matches[match_index].queryIdx ].pt; // 2D point from the scene - list_points3d_model_match.push_back(point3d_model); // add 3D point - list_points2d_scene_match.push_back(point2d_scene); // add 2D point -} -@endcode -You can also change the ratio test threshold, the number of keypoints to detect as well as use or -not the robust matcher: -@code{.cpp} -./cpp-tutorial-pnp_detection --ratio=0.8 --keypoints=1000 --fast=false -@endcode -5. **Pose estimation using PnP + Ransac** - -Once with the 2D and 3D correspondences we have to apply a PnP algorithm in order to estimate the -camera pose. The reason why we have to use @ref cv::solvePnPRansac instead of @ref cv::solvePnP is -due to the fact that after the matching not all the found correspondences are correct and, as like -as not, there are false correspondences or also called *outliers*. The [Random Sample -Consensus](http://en.wikipedia.org/wiki/RANSAC) or *Ransac* is a non-deterministic iterative -method which estimate parameters of a mathematical model from observed data producing an -aproximate result as the number of iterations increase. After appyling *Ransac* all the *outliers* -will be eliminated to then estimate the camera pose with a certain probability to obtain a good -solution. - -For the camera pose estimation I have implemented a *class* **PnPProblem**. This *class* has 4 -atributes: a given calibration matrix, the rotation matrix, the translation matrix and the -rotation-translation matrix. The intrinsic calibration parameters of the camera which you are -using to estimate the pose are necessary. In order to obtain the parameters you can check -@ref tutorial_camera_calibration_square_chess and @ref tutorial_camera_calibration tutorials. - -The following code is how to declare the *PnPProblem class* in the main program: -@code{.cpp} -// Intrinsic camera parameters: UVC WEBCAM - -double f = 55; // focal length in mm -double sx = 22.3, sy = 14.9; // sensor size -double width = 640, height = 480; // image size - -double params_WEBCAM[] = { width*f/sx, // fx - height*f/sy, // fy - width/2, // cx - height/2}; // cy - -PnPProblem pnp_detection(params_WEBCAM); // instantiate PnPProblem class -@endcode -The following code is how the *PnPProblem class* initialises its atributes: -@code{.cpp} -// Custom constructor given the intrinsic camera parameters - -PnPProblem::PnPProblem(const double params[]) -{ - _A_matrix = cv::Mat::zeros(3, 3, CV_64FC1); // intrinsic camera parameters - _A_matrix.at(0, 0) = params[0]; // [ fx 0 cx ] - _A_matrix.at(1, 1) = params[1]; // [ 0 fy cy ] - _A_matrix.at(0, 2) = params[2]; // [ 0 0 1 ] - _A_matrix.at(1, 2) = params[3]; - _A_matrix.at(2, 2) = 1; - _R_matrix = cv::Mat::zeros(3, 3, CV_64FC1); // rotation matrix - _t_matrix = cv::Mat::zeros(3, 1, CV_64FC1); // translation matrix - _P_matrix = cv::Mat::zeros(3, 4, CV_64FC1); // rotation-translation matrix - -} -@endcode -OpenCV provides four PnP methods: ITERATIVE, EPNP, P3P and DLS. Depending on the application type, -the estimation method will be different. In the case that we want to make a real time application, -the more suitable methods are EPNP and P3P due to that are faster than ITERATIVE and DLS at -finding an optimal solution. However, EPNP and P3P are not especially robust in front of planar -surfaces and sometimes the pose estimation seems to have a mirror effect. Therefore, in this this -tutorial is used ITERATIVE method due to the object to be detected has planar surfaces. - -The OpenCV Ransac implementation wants you to provide three parameters: the maximum number of -iterations until stop the algorithm, the maximum allowed distance between the observed and -computed point projections to consider it an inlier and the confidence to obtain a good result. -You can tune these paramaters in order to improve your algorithm performance. Increasing the -number of iterations you will have a more accurate solution, but will take more time to find a -solution. Increasing the reprojection error will reduce the computation time, but your solution -will be unaccurate. Decreasing the confidence your arlgorithm will be faster, but the obtained -solution will be unaccurate. - -The following parameters work for this application: -@code{.cpp} -// RANSAC parameters - -int iterationsCount = 500; // number of Ransac iterations. -float reprojectionError = 2.0; // maximum allowed distance to consider it an inlier. -float confidence = 0.95; // ransac successful confidence. -@endcode -The following code corresponds to the *estimatePoseRANSAC()* function which belongs to the -*PnPProblem class*. This function estimates the rotation and translation matrix given a set of -2D/3D correspondences, the desired PnP method to use, the output inliers container and the Ransac -parameters: -@code{.cpp} -// Estimate the pose given a list of 2D/3D correspondences with RANSAC and the method to use - -void PnPProblem::estimatePoseRANSAC( const std::vector &list_points3d, // list with model 3D coordinates - const std::vector &list_points2d, // list with scene 2D coordinates - int flags, cv::Mat &inliers, int iterationsCount, // PnP method; inliers container - float reprojectionError, float confidence ) // Ransac parameters -{ - cv::Mat distCoeffs = cv::Mat::zeros(4, 1, CV_64FC1); // vector of distortion coefficients - cv::Mat rvec = cv::Mat::zeros(3, 1, CV_64FC1); // output rotation vector - cv::Mat tvec = cv::Mat::zeros(3, 1, CV_64FC1); // output translation vector - - bool useExtrinsicGuess = false; // if true the function uses the provided rvec and tvec values as - // initial approximations of the rotation and translation vectors - - cv::solvePnPRansac( list_points3d, list_points2d, _A_matrix, distCoeffs, rvec, tvec, - useExtrinsicGuess, iterationsCount, reprojectionError, confidence, - inliers, flags ); - - Rodrigues(rvec,_R_matrix); // converts Rotation Vector to Matrix - _t_matrix = tvec; // set translation matrix - - this->set_P_matrix(_R_matrix, _t_matrix); // set rotation-translation matrix - -} -@endcode -In the following code are the 3th and 4th steps of the main algorithm. The first, calling the -above function and the second taking the output inliers vector from Ransac to get the 2D scene -points for drawing purpose. As seen in the code we must be sure to apply Ransac if we have -matches, in the other case, the function @ref cv::solvePnPRansac crashes due to any OpenCV *bug*. -@code{.cpp} -if(good_matches.size() > 0) // None matches, then RANSAC crashes -{ - - // -- Step 3: Estimate the pose using RANSAC approach - pnp_detection.estimatePoseRANSAC( list_points3d_model_match, list_points2d_scene_match, - pnpMethod, inliers_idx, iterationsCount, reprojectionError, confidence ); - - - // -- Step 4: Catch the inliers keypoints to draw - for(int inliers_index = 0; inliers_index < inliers_idx.rows; ++inliers_index) + In order to load the textured model I implemented the *class* **Model** which has the function + *load()* that opens a YAML file and take the stored 3D points with its corresponding descriptors. + You can find an example of a 3D textured model in + `samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/Data/cookies_ORB.yml`. + @code{.cpp} + /* Load a YAML file using OpenCV */ + void Model::load(const std::string path) + { + cv::Mat points3d_mat; + + cv::FileStorage storage(path, cv::FileStorage::READ); + storage["points_3d"] >> points3d_mat; + storage["descriptors"] >> descriptors_; + + points3d_mat.copyTo(list_points3d_in_); + + storage.release(); + + } + @endcode + In the main program the model is loaded as follows: + @code{.cpp} + Model model; // instantiate Model object + model.load(yml_read_path); // load a 3D textured object model + @endcode + In order to read the model mesh I implemented a *class* **Mesh** which has a function *load()* + that opens a \f$*\f$.ply file and store the 3D points of the object and also the composed triangles. + You can find an example of a model mesh in + `samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/Data/box.ply`. + @code{.cpp} + /* Load a CSV with *.ply format */ + void Mesh::load(const std::string path) { - int n = inliers_idx.at(inliers_index); // i-inlier - cv::Point2f point2d = list_points2d_scene_match[n]; // i-inlier point 2D - list_points2d_inliers.push_back(point2d); // add i-inlier to list -} -@endcode -Finally, once the camera pose has been estimated we can use the \f$R\f$ and \f$t\f$ in order to compute -the 2D projection onto the image of a given 3D point expressed in a world reference frame using -the showed formula on *Theory*. - -The following code corresponds to the *backproject3DPoint()* function which belongs to the -*PnPProblem class*. The function backproject a given 3D point expressed in a world reference frame -onto a 2D image: -@code{.cpp} -// Backproject a 3D point to 2D using the estimated pose parameters - -cv::Point2f PnPProblem::backproject3DPoint(const cv::Point3f &point3d) -{ - // 3D point vector [x y z 1]' - cv::Mat point3d_vec = cv::Mat(4, 1, CV_64FC1); - point3d_vec.at(0) = point3d.x; - point3d_vec.at(1) = point3d.y; - point3d_vec.at(2) = point3d.z; - point3d_vec.at(3) = 1; - - // 2D point vector [u v 1]' - cv::Mat point2d_vec = cv::Mat(4, 1, CV_64FC1); - point2d_vec = _A_matrix * _P_matrix * point3d_vec; - - // Normalization of [u v]' - cv::Point2f point2d; - point2d.x = point2d_vec.at(0) / point2d_vec.at(2); - point2d.y = point2d_vec.at(1) / point2d_vec.at(2); - - return point2d; -} -@endcode -The above function is used to compute all the 3D points of the object *Mesh* to show the pose of -the object. - -You can also change RANSAC parameters and PnP method: -@code{.cpp} -./cpp-tutorial-pnp_detection --error=0.25 --confidence=0.90 --iterations=250 --method=3 -@endcode -6. **Linear Kalman Filter for bad poses rejection** - -Is it common in computer vision or robotics fields that after applying detection or tracking -techniques, bad results are obtained due to some sensor errors. In order to avoid these bad -detections in this tutorial is explained how to implement a Linear Kalman Filter. The Kalman -Filter will be applied after detected a given number of inliers. - -You can find more information about what [Kalman -Filter](http://en.wikipedia.org/wiki/Kalman_filter) is. In this tutorial it's used the OpenCV -implementation of the @ref cv::KalmanFilter based on -[Linear Kalman Filter for position and orientation tracking](http://campar.in.tum.de/Chair/KalmanFilter) -to set the dynamics and measurement models. - -Firstly, we have to define our state vector which will have 18 states: the positional data (x,y,z) -with its first and second derivatives (velocity and acceleration), then rotation is added in form -of three euler angles (roll, pitch, jaw) together with their first and second derivatives (angular -velocity and acceleration) - -\f[X = (x,y,z,\dot x,\dot y,\dot z,\ddot x,\ddot y,\ddot z,\psi,\theta,\phi,\dot \psi,\dot \theta,\dot \phi,\ddot \psi,\ddot \theta,\ddot \phi)^T\f] - -Secondly, we have to define the number of measuremnts which will be 6: from \f$R\f$ and \f$t\f$ we can -extract \f$(x,y,z)\f$ and \f$(\psi,\theta,\phi)\f$. In addition, we have to define the number of control -actions to apply to the system which in this case will be *zero*. Finally, we have to define the -differential time between measurements which in this case is \f$1/T\f$, where *T* is the frame rate of -the video. -@code{.cpp} -cv::KalmanFilter KF; // instantiate Kalman Filter -int nStates = 18; // the number of states -int nMeasurements = 6; // the number of measured states -int nInputs = 0; // the number of action control + // Create the reader + CsvReader csvReader(path); + + // Clear previous data + list_vertex_.clear(); + list_triangles_.clear(); + + // Read from .ply file + csvReader.readPLY(list_vertex_, list_triangles_); + + // Update mesh attributes + num_vertexs_ = list_vertex_.size(); + num_triangles_ = list_triangles_.size(); + + } + @endcode + In the main program the mesh is loaded as follows: + @code{.cpp} + Mesh mesh; // instantiate Mesh object + mesh.load(ply_read_path); // load an object mesh + @endcode + You can also load different model and mesh: + @code{.cpp} + ./cpp-tutorial-pnp_detection --mesh=/absolute_path_to_your_mesh.ply --model=/absolute_path_to_your_model.yml + @endcode + +-# **Take input from Camera or Video** + + To detect is necessary capture video. It's done loading a recorded video by passing the absolute + path where it is located in your machine. In order to test the application you can find a recorded + video in `samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/Data/box.mp4`. + @code{.cpp} + cv::VideoCapture cap; // instantiate VideoCapture + cap.open(video_read_path); // open a recorded video + + if(!cap.isOpened()) // check if we succeeded + { + std::cout << "Could not open the camera device" << std::endl; + return -1; + } + @endcode + Then the algorithm is computed frame per frame: + @code{.cpp} + cv::Mat frame, frame_vis; + + while(cap.read(frame) && cv::waitKey(30) != 27) // capture frame until ESC is pressed + { -double dt = 0.125; // time between measurements (1/FPS) + frame_vis = frame.clone(); // refresh visualisation frame + + // MAIN ALGORITHM + + } + @endcode + You can also load different recorded video: + @code{.cpp} + ./cpp-tutorial-pnp_detection --video=/absolute_path_to_your_video.mp4 + @endcode + +-# **Extract ORB features and descriptors from the scene** + + The next step is to detect the scene features and extract it descriptors. For this task I + implemented a *class* **RobustMatcher** which has a function for keypoints detection and features + extraction. You can find it in + `samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/RobusMatcher.cpp`. In your + *RobusMatch* object you can use any of the 2D features detectors of OpenCV. In this case I used + @ref cv::ORB features because is based on @ref cv::FAST to detect the keypoints and @ref cv::xfeatures2d::BriefDescriptorExtractor + to extract the descriptors which means that is fast and robust to rotations. You can find more + detailed information about *ORB* in the documentation. + + The following code is how to instantiate and set the features detector and the descriptors + extractor: + @code{.cpp} + RobustMatcher rmatcher; // instantiate RobustMatcher + + cv::FeatureDetector * detector = new cv::OrbFeatureDetector(numKeyPoints); // instatiate ORB feature detector + cv::DescriptorExtractor * extractor = new cv::OrbDescriptorExtractor(); // instatiate ORB descriptor extractor + + rmatcher.setFeatureDetector(detector); // set feature detector + rmatcher.setDescriptorExtractor(extractor); // set descriptor extractor + @endcode + The features and descriptors will be computed by the *RobustMatcher* inside the matching function. + +-# **Match scene descriptors with model descriptors using Flann matcher** + + It is the first step in our detection algorithm. The main idea is to match the scene descriptors + with our model descriptors in order to know the 3D coordinates of the found features into the + current scene. + + Firstly, we have to set which matcher we want to use. In this case is used + @ref cv::FlannBasedMatcher matcher which in terms of computational cost is faster than the + @ref cv::BFMatcher matcher as we increase the trained collectction of features. Then, for + FlannBased matcher the index created is *Multi-Probe LSH: Efficient Indexing for High-Dimensional + Similarity Search* due to *ORB* descriptors are binary. + + You can tune the *LSH* and search parameters to improve the matching efficiency: + @code{.cpp} + cv::Ptr indexParams = cv::makePtr(6, 12, 1); // instantiate LSH index parameters + cv::Ptr searchParams = cv::makePtr(50); // instantiate flann search parameters + + cv::DescriptorMatcher * matcher = new cv::FlannBasedMatcher(indexParams, searchParams); // instantiate FlannBased matcher + rmatcher.setDescriptorMatcher(matcher); // set matcher + @endcode + Secondly, we have to call the matcher by using *robustMatch()* or *fastRobustMatch()* function. + The difference of using this two functions is its computational cost. The first method is slower + but more robust at filtering good matches because uses two ratio test and a symmetry test. In + contrast, the second method is faster but less robust because only applies a single ratio test to + the matches. + + The following code is to get the model 3D points and its descriptors and then call the matcher in + the main program: + @code{.cpp} + // Get the MODEL INFO + + std::vector list_points3d_model = model.get_points3d(); // list with model 3D coordinates + cv::Mat descriptors_model = model.get_descriptors(); // list with descriptors of each 3D coordinate + @endcode + @code{.cpp} + // -- Step 1: Robust matching between model descriptors and scene descriptors + + std::vector good_matches; // to obtain the model 3D points in the scene + std::vector keypoints_scene; // to obtain the 2D points of the scene + + if(fast_match) + { + rmatcher.fastRobustMatch(frame, good_matches, keypoints_scene, descriptors_model); + } + else + { + rmatcher.robustMatch(frame, good_matches, keypoints_scene, descriptors_model); + } + @endcode + The following code corresponds to the *robustMatch()* function which belongs to the + *RobustMatcher* class. This function uses the given image to detect the keypoints and extract the + descriptors, match using *two Nearest Neighbour* the extracted descriptors with the given model + descriptors and vice versa. Then, a ratio test is applied to the two direction matches in order to + remove these matches which its distance ratio between the first and second best match is larger + than a given threshold. Finally, a symmetry test is applied in order the remove non symmetrical + matches. + @code{.cpp} + void RobustMatcher::robustMatch( const cv::Mat& frame, std::vector& good_matches, + std::vector& keypoints_frame, + const std::vector& keypoints_model, const cv::Mat& descriptors_model ) + { -initKalmanFilter(KF, nStates, nMeasurements, nInputs, dt); // init function -@endcode -The following code corresponds to the *Kalman Filter* initialisation. Firstly, is set the process -noise, the measurement noise and the error covariance matrix. Secondly, are set the transition -matrix which is the dynamic model and finally the measurement matrix, which is the measurement -model. + // 1a. Detection of the ORB features + this->computeKeyPoints(frame, keypoints_frame); -You can tune the process and measurement noise to improve the *Kalman Filter* performance. As the -measurement noise is reduced the faster will converge doing the algorithm sensitive in front of -bad measurements. -@code{.cpp} -void initKalmanFilter(cv::KalmanFilter &KF, int nStates, int nMeasurements, int nInputs, double dt) -{ - - KF.init(nStates, nMeasurements, nInputs, CV_64F); // init Kalman Filter - - cv::setIdentity(KF.processNoiseCov, cv::Scalar::all(1e-5)); // set process noise - cv::setIdentity(KF.measurementNoiseCov, cv::Scalar::all(1e-4)); // set measurement noise - cv::setIdentity(KF.errorCovPost, cv::Scalar::all(1)); // error covariance - - - /* DYNAMIC MODEL */ - - // [1 0 0 dt 0 0 dt2 0 0 0 0 0 0 0 0 0 0 0] - // [0 1 0 0 dt 0 0 dt2 0 0 0 0 0 0 0 0 0 0] - // [0 0 1 0 0 dt 0 0 dt2 0 0 0 0 0 0 0 0 0] - // [0 0 0 1 0 0 dt 0 0 0 0 0 0 0 0 0 0 0] - // [0 0 0 0 1 0 0 dt 0 0 0 0 0 0 0 0 0 0] - // [0 0 0 0 0 1 0 0 dt 0 0 0 0 0 0 0 0 0] - // [0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0] - // [0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0] - // [0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0] - // [0 0 0 0 0 0 0 0 0 1 0 0 dt 0 0 dt2 0 0] - // [0 0 0 0 0 0 0 0 0 0 1 0 0 dt 0 0 dt2 0] - // [0 0 0 0 0 0 0 0 0 0 0 1 0 0 dt 0 0 dt2] - // [0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 dt 0 0] - // [0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 dt 0] - // [0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 dt] - // [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0] - // [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0] - // [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1] - - // position - KF.transitionMatrix.at(0,3) = dt; - KF.transitionMatrix.at(1,4) = dt; - KF.transitionMatrix.at(2,5) = dt; - KF.transitionMatrix.at(3,6) = dt; - KF.transitionMatrix.at(4,7) = dt; - KF.transitionMatrix.at(5,8) = dt; - KF.transitionMatrix.at(0,6) = 0.5*pow(dt,2); - KF.transitionMatrix.at(1,7) = 0.5*pow(dt,2); - KF.transitionMatrix.at(2,8) = 0.5*pow(dt,2); - - // orientation - KF.transitionMatrix.at(9,12) = dt; - KF.transitionMatrix.at(10,13) = dt; - KF.transitionMatrix.at(11,14) = dt; - KF.transitionMatrix.at(12,15) = dt; - KF.transitionMatrix.at(13,16) = dt; - KF.transitionMatrix.at(14,17) = dt; - KF.transitionMatrix.at(9,15) = 0.5*pow(dt,2); - KF.transitionMatrix.at(10,16) = 0.5*pow(dt,2); - KF.transitionMatrix.at(11,17) = 0.5*pow(dt,2); - - - /* MEASUREMENT MODEL */ - - // [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] - // [0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] - // [0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] - // [0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0] - // [0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0] - // [0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0] - - KF.measurementMatrix.at(0,0) = 1; // x - KF.measurementMatrix.at(1,1) = 1; // y - KF.measurementMatrix.at(2,2) = 1; // z - KF.measurementMatrix.at(3,9) = 1; // roll - KF.measurementMatrix.at(4,10) = 1; // pitch - KF.measurementMatrix.at(5,11) = 1; // yaw - -} -@endcode -In the following code is the 5th step of the main algorithm. When the obtained number of inliers -after *Ransac* is over the threshold, the measurements matrix is filled and then the *Kalman -Filter* is updated: -@code{.cpp} -// -- Step 5: Kalman Filter + // 1b. Extraction of the ORB descriptors + cv::Mat descriptors_frame; + this->computeDescriptors(frame, keypoints_frame, descriptors_frame); -// GOOD MEASUREMENT -if( inliers_idx.rows >= minInliersKalman ) -{ + // 2. Match the two image descriptors + std::vector > matches12, matches21; - // Get the measured translation - cv::Mat translation_measured(3, 1, CV_64F); - translation_measured = pnp_detection.get_t_matrix(); + // 2a. From image 1 to image 2 + matcher_->knnMatch(descriptors_frame, descriptors_model, matches12, 2); // return 2 nearest neighbours - // Get the measured rotation - cv::Mat rotation_measured(3, 3, CV_64F); - rotation_measured = pnp_detection.get_R_matrix(); + // 2b. From image 2 to image 1 + matcher_->knnMatch(descriptors_model, descriptors_frame, matches21, 2); // return 2 nearest neighbours - // fill the measurements vector - fillMeasurements(measurements, translation_measured, rotation_measured); + // 3. Remove matches for which NN ratio is > than threshold + // clean image 1 -> image 2 matches + int removed1 = ratioTest(matches12); + // clean image 2 -> image 1 matches + int removed2 = ratioTest(matches21); -} + // 4. Remove non-symmetrical matches + symmetryTest(matches12, matches21, good_matches); -// Instantiate estimated translation and rotation -cv::Mat translation_estimated(3, 1, CV_64F); -cv::Mat rotation_estimated(3, 3, CV_64F); + } + @endcode + After the matches filtering we have to subtract the 2D and 3D correspondences from the found scene + keypoints and our 3D model using the obtained *DMatches* vector. For more information about + @ref cv::DMatch check the documentation. + @code{.cpp} + // -- Step 2: Find out the 2D/3D correspondences -// update the Kalman filter with good measurements -updateKalmanFilter( KF, measurements, - translation_estimated, rotation_estimated); -@endcode -The following code corresponds to the *fillMeasurements()* function which converts the measured -[Rotation Matrix to Eulers -angles](http://euclideanspace.com/maths/geometry/rotations/conversions/matrixToEuler/index.htm) -and fill the measurements matrix along with the measured translation vector: -@code{.cpp} -void fillMeasurements( cv::Mat &measurements, - const cv::Mat &translation_measured, const cv::Mat &rotation_measured) -{ - // Convert rotation matrix to euler angles - cv::Mat measured_eulers(3, 1, CV_64F); - measured_eulers = rot2euler(rotation_measured); - - // Set measurement to predict - measurements.at(0) = translation_measured.at(0); // x - measurements.at(1) = translation_measured.at(1); // y - measurements.at(2) = translation_measured.at(2); // z - measurements.at(3) = measured_eulers.at(0); // roll - measurements.at(4) = measured_eulers.at(1); // pitch - measurements.at(5) = measured_eulers.at(2); // yaw -} -@endcode -The following code corresponds to the *updateKalmanFilter()* function which update the Kalman -Filter and set the estimated Rotation Matrix and translation vector. The estimated Rotation Matrix -comes from the estimated [Euler angles to Rotation -Matrix](http://euclideanspace.com/maths/geometry/rotations/conversions/eulerToMatrix/index.htm). -@code{.cpp} -void updateKalmanFilter( cv::KalmanFilter &KF, cv::Mat &measurement, - cv::Mat &translation_estimated, cv::Mat &rotation_estimated ) -{ + std::vector list_points3d_model_match; // container for the model 3D coordinates found in the scene + std::vector list_points2d_scene_match; // container for the model 2D coordinates found in the scene - // First predict, to update the internal statePre variable - cv::Mat prediction = KF.predict(); + for(unsigned int match_index = 0; match_index < good_matches.size(); ++match_index) + { + cv::Point3f point3d_model = list_points3d_model[ good_matches[match_index].trainIdx ]; // 3D point from model + cv::Point2f point2d_scene = keypoints_scene[ good_matches[match_index].queryIdx ].pt; // 2D point from the scene + list_points3d_model_match.push_back(point3d_model); // add 3D point + list_points2d_scene_match.push_back(point2d_scene); // add 2D point + } + @endcode + You can also change the ratio test threshold, the number of keypoints to detect as well as use or + not the robust matcher: + @code{.cpp} + ./cpp-tutorial-pnp_detection --ratio=0.8 --keypoints=1000 --fast=false + @endcode + +-# **Pose estimation using PnP + Ransac** + + Once with the 2D and 3D correspondences we have to apply a PnP algorithm in order to estimate the + camera pose. The reason why we have to use @ref cv::solvePnPRansac instead of @ref cv::solvePnP is + due to the fact that after the matching not all the found correspondences are correct and, as like + as not, there are false correspondences or also called *outliers*. The [Random Sample + Consensus](http://en.wikipedia.org/wiki/RANSAC) or *Ransac* is a non-deterministic iterative + method which estimate parameters of a mathematical model from observed data producing an + aproximate result as the number of iterations increase. After appyling *Ransac* all the *outliers* + will be eliminated to then estimate the camera pose with a certain probability to obtain a good + solution. + + For the camera pose estimation I have implemented a *class* **PnPProblem**. This *class* has 4 + atributes: a given calibration matrix, the rotation matrix, the translation matrix and the + rotation-translation matrix. The intrinsic calibration parameters of the camera which you are + using to estimate the pose are necessary. In order to obtain the parameters you can check + @ref tutorial_camera_calibration_square_chess and @ref tutorial_camera_calibration tutorials. + + The following code is how to declare the *PnPProblem class* in the main program: + @code{.cpp} + // Intrinsic camera parameters: UVC WEBCAM + + double f = 55; // focal length in mm + double sx = 22.3, sy = 14.9; // sensor size + double width = 640, height = 480; // image size + + double params_WEBCAM[] = { width*f/sx, // fx + height*f/sy, // fy + width/2, // cx + height/2}; // cy + + PnPProblem pnp_detection(params_WEBCAM); // instantiate PnPProblem class + @endcode + The following code is how the *PnPProblem class* initialises its atributes: + @code{.cpp} + // Custom constructor given the intrinsic camera parameters + + PnPProblem::PnPProblem(const double params[]) + { + _A_matrix = cv::Mat::zeros(3, 3, CV_64FC1); // intrinsic camera parameters + _A_matrix.at(0, 0) = params[0]; // [ fx 0 cx ] + _A_matrix.at(1, 1) = params[1]; // [ 0 fy cy ] + _A_matrix.at(0, 2) = params[2]; // [ 0 0 1 ] + _A_matrix.at(1, 2) = params[3]; + _A_matrix.at(2, 2) = 1; + _R_matrix = cv::Mat::zeros(3, 3, CV_64FC1); // rotation matrix + _t_matrix = cv::Mat::zeros(3, 1, CV_64FC1); // translation matrix + _P_matrix = cv::Mat::zeros(3, 4, CV_64FC1); // rotation-translation matrix + + } + @endcode + OpenCV provides four PnP methods: ITERATIVE, EPNP, P3P and DLS. Depending on the application type, + the estimation method will be different. In the case that we want to make a real time application, + the more suitable methods are EPNP and P3P due to that are faster than ITERATIVE and DLS at + finding an optimal solution. However, EPNP and P3P are not especially robust in front of planar + surfaces and sometimes the pose estimation seems to have a mirror effect. Therefore, in this this + tutorial is used ITERATIVE method due to the object to be detected has planar surfaces. + + The OpenCV Ransac implementation wants you to provide three parameters: the maximum number of + iterations until stop the algorithm, the maximum allowed distance between the observed and + computed point projections to consider it an inlier and the confidence to obtain a good result. + You can tune these paramaters in order to improve your algorithm performance. Increasing the + number of iterations you will have a more accurate solution, but will take more time to find a + solution. Increasing the reprojection error will reduce the computation time, but your solution + will be unaccurate. Decreasing the confidence your arlgorithm will be faster, but the obtained + solution will be unaccurate. + + The following parameters work for this application: + @code{.cpp} + // RANSAC parameters + + int iterationsCount = 500; // number of Ransac iterations. + float reprojectionError = 2.0; // maximum allowed distance to consider it an inlier. + float confidence = 0.95; // ransac successful confidence. + @endcode + The following code corresponds to the *estimatePoseRANSAC()* function which belongs to the + *PnPProblem class*. This function estimates the rotation and translation matrix given a set of + 2D/3D correspondences, the desired PnP method to use, the output inliers container and the Ransac + parameters: + @code{.cpp} + // Estimate the pose given a list of 2D/3D correspondences with RANSAC and the method to use + + void PnPProblem::estimatePoseRANSAC( const std::vector &list_points3d, // list with model 3D coordinates + const std::vector &list_points2d, // list with scene 2D coordinates + int flags, cv::Mat &inliers, int iterationsCount, // PnP method; inliers container + float reprojectionError, float confidence ) // Ransac parameters + { + cv::Mat distCoeffs = cv::Mat::zeros(4, 1, CV_64FC1); // vector of distortion coefficients + cv::Mat rvec = cv::Mat::zeros(3, 1, CV_64FC1); // output rotation vector + cv::Mat tvec = cv::Mat::zeros(3, 1, CV_64FC1); // output translation vector + + bool useExtrinsicGuess = false; // if true the function uses the provided rvec and tvec values as + // initial approximations of the rotation and translation vectors + + cv::solvePnPRansac( list_points3d, list_points2d, _A_matrix, distCoeffs, rvec, tvec, + useExtrinsicGuess, iterationsCount, reprojectionError, confidence, + inliers, flags ); + + Rodrigues(rvec,_R_matrix); // converts Rotation Vector to Matrix + _t_matrix = tvec; // set translation matrix + + this->set_P_matrix(_R_matrix, _t_matrix); // set rotation-translation matrix + + } + @endcode + In the following code are the 3th and 4th steps of the main algorithm. The first, calling the + above function and the second taking the output inliers vector from Ransac to get the 2D scene + points for drawing purpose. As seen in the code we must be sure to apply Ransac if we have + matches, in the other case, the function @ref cv::solvePnPRansac crashes due to any OpenCV *bug*. + @code{.cpp} + if(good_matches.size() > 0) // None matches, then RANSAC crashes + { - // The "correct" phase that is going to use the predicted value and our measurement - cv::Mat estimated = KF.correct(measurement); + // -- Step 3: Estimate the pose using RANSAC approach + pnp_detection.estimatePoseRANSAC( list_points3d_model_match, list_points2d_scene_match, + pnpMethod, inliers_idx, iterationsCount, reprojectionError, confidence ); + + + // -- Step 4: Catch the inliers keypoints to draw + for(int inliers_index = 0; inliers_index < inliers_idx.rows; ++inliers_index) + { + int n = inliers_idx.at(inliers_index); // i-inlier + cv::Point2f point2d = list_points2d_scene_match[n]; // i-inlier point 2D + list_points2d_inliers.push_back(point2d); // add i-inlier to list + } + @endcode + Finally, once the camera pose has been estimated we can use the \f$R\f$ and \f$t\f$ in order to compute + the 2D projection onto the image of a given 3D point expressed in a world reference frame using + the showed formula on *Theory*. + + The following code corresponds to the *backproject3DPoint()* function which belongs to the + *PnPProblem class*. The function backproject a given 3D point expressed in a world reference frame + onto a 2D image: + @code{.cpp} + // Backproject a 3D point to 2D using the estimated pose parameters + + cv::Point2f PnPProblem::backproject3DPoint(const cv::Point3f &point3d) + { + // 3D point vector [x y z 1]' + cv::Mat point3d_vec = cv::Mat(4, 1, CV_64FC1); + point3d_vec.at(0) = point3d.x; + point3d_vec.at(1) = point3d.y; + point3d_vec.at(2) = point3d.z; + point3d_vec.at(3) = 1; + + // 2D point vector [u v 1]' + cv::Mat point2d_vec = cv::Mat(4, 1, CV_64FC1); + point2d_vec = _A_matrix * _P_matrix * point3d_vec; + + // Normalization of [u v]' + cv::Point2f point2d; + point2d.x = point2d_vec.at(0) / point2d_vec.at(2); + point2d.y = point2d_vec.at(1) / point2d_vec.at(2); + + return point2d; + } + @endcode + The above function is used to compute all the 3D points of the object *Mesh* to show the pose of + the object. + + You can also change RANSAC parameters and PnP method: + @code{.cpp} + ./cpp-tutorial-pnp_detection --error=0.25 --confidence=0.90 --iterations=250 --method=3 + @endcode + +-# **Linear Kalman Filter for bad poses rejection** + + Is it common in computer vision or robotics fields that after applying detection or tracking + techniques, bad results are obtained due to some sensor errors. In order to avoid these bad + detections in this tutorial is explained how to implement a Linear Kalman Filter. The Kalman + Filter will be applied after detected a given number of inliers. + + You can find more information about what [Kalman + Filter](http://en.wikipedia.org/wiki/Kalman_filter) is. In this tutorial it's used the OpenCV + implementation of the @ref cv::KalmanFilter based on + [Linear Kalman Filter for position and orientation tracking](http://campar.in.tum.de/Chair/KalmanFilter) + to set the dynamics and measurement models. + + Firstly, we have to define our state vector which will have 18 states: the positional data (x,y,z) + with its first and second derivatives (velocity and acceleration), then rotation is added in form + of three euler angles (roll, pitch, jaw) together with their first and second derivatives (angular + velocity and acceleration) + + \f[X = (x,y,z,\dot x,\dot y,\dot z,\ddot x,\ddot y,\ddot z,\psi,\theta,\phi,\dot \psi,\dot \theta,\dot \phi,\ddot \psi,\ddot \theta,\ddot \phi)^T\f] + + Secondly, we have to define the number of measuremnts which will be 6: from \f$R\f$ and \f$t\f$ we can + extract \f$(x,y,z)\f$ and \f$(\psi,\theta,\phi)\f$. In addition, we have to define the number of control + actions to apply to the system which in this case will be *zero*. Finally, we have to define the + differential time between measurements which in this case is \f$1/T\f$, where *T* is the frame rate of + the video. + @code{.cpp} + cv::KalmanFilter KF; // instantiate Kalman Filter + + int nStates = 18; // the number of states + int nMeasurements = 6; // the number of measured states + int nInputs = 0; // the number of action control + + double dt = 0.125; // time between measurements (1/FPS) + + initKalmanFilter(KF, nStates, nMeasurements, nInputs, dt); // init function + @endcode + The following code corresponds to the *Kalman Filter* initialisation. Firstly, is set the process + noise, the measurement noise and the error covariance matrix. Secondly, are set the transition + matrix which is the dynamic model and finally the measurement matrix, which is the measurement + model. + + You can tune the process and measurement noise to improve the *Kalman Filter* performance. As the + measurement noise is reduced the faster will converge doing the algorithm sensitive in front of + bad measurements. + @code{.cpp} + void initKalmanFilter(cv::KalmanFilter &KF, int nStates, int nMeasurements, int nInputs, double dt) + { - // Estimated translation - translation_estimated.at(0) = estimated.at(0); - translation_estimated.at(1) = estimated.at(1); - translation_estimated.at(2) = estimated.at(2); + KF.init(nStates, nMeasurements, nInputs, CV_64F); // init Kalman Filter + + cv::setIdentity(KF.processNoiseCov, cv::Scalar::all(1e-5)); // set process noise + cv::setIdentity(KF.measurementNoiseCov, cv::Scalar::all(1e-4)); // set measurement noise + cv::setIdentity(KF.errorCovPost, cv::Scalar::all(1)); // error covariance + + + /* DYNAMIC MODEL */ + + // [1 0 0 dt 0 0 dt2 0 0 0 0 0 0 0 0 0 0 0] + // [0 1 0 0 dt 0 0 dt2 0 0 0 0 0 0 0 0 0 0] + // [0 0 1 0 0 dt 0 0 dt2 0 0 0 0 0 0 0 0 0] + // [0 0 0 1 0 0 dt 0 0 0 0 0 0 0 0 0 0 0] + // [0 0 0 0 1 0 0 dt 0 0 0 0 0 0 0 0 0 0] + // [0 0 0 0 0 1 0 0 dt 0 0 0 0 0 0 0 0 0] + // [0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0] + // [0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0] + // [0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0] + // [0 0 0 0 0 0 0 0 0 1 0 0 dt 0 0 dt2 0 0] + // [0 0 0 0 0 0 0 0 0 0 1 0 0 dt 0 0 dt2 0] + // [0 0 0 0 0 0 0 0 0 0 0 1 0 0 dt 0 0 dt2] + // [0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 dt 0 0] + // [0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 dt 0] + // [0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 dt] + // [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0] + // [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0] + // [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1] + + // position + KF.transitionMatrix.at(0,3) = dt; + KF.transitionMatrix.at(1,4) = dt; + KF.transitionMatrix.at(2,5) = dt; + KF.transitionMatrix.at(3,6) = dt; + KF.transitionMatrix.at(4,7) = dt; + KF.transitionMatrix.at(5,8) = dt; + KF.transitionMatrix.at(0,6) = 0.5*pow(dt,2); + KF.transitionMatrix.at(1,7) = 0.5*pow(dt,2); + KF.transitionMatrix.at(2,8) = 0.5*pow(dt,2); + + // orientation + KF.transitionMatrix.at(9,12) = dt; + KF.transitionMatrix.at(10,13) = dt; + KF.transitionMatrix.at(11,14) = dt; + KF.transitionMatrix.at(12,15) = dt; + KF.transitionMatrix.at(13,16) = dt; + KF.transitionMatrix.at(14,17) = dt; + KF.transitionMatrix.at(9,15) = 0.5*pow(dt,2); + KF.transitionMatrix.at(10,16) = 0.5*pow(dt,2); + KF.transitionMatrix.at(11,17) = 0.5*pow(dt,2); + + + /* MEASUREMENT MODEL */ + + // [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] + // [0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] + // [0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] + // [0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0] + // [0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0] + // [0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0] + + KF.measurementMatrix.at(0,0) = 1; // x + KF.measurementMatrix.at(1,1) = 1; // y + KF.measurementMatrix.at(2,2) = 1; // z + KF.measurementMatrix.at(3,9) = 1; // roll + KF.measurementMatrix.at(4,10) = 1; // pitch + KF.measurementMatrix.at(5,11) = 1; // yaw + + } + @endcode + In the following code is the 5th step of the main algorithm. When the obtained number of inliers + after *Ransac* is over the threshold, the measurements matrix is filled and then the *Kalman + Filter* is updated: + @code{.cpp} + // -- Step 5: Kalman Filter + + // GOOD MEASUREMENT + if( inliers_idx.rows >= minInliersKalman ) + { - // Estimated euler angles - cv::Mat eulers_estimated(3, 1, CV_64F); - eulers_estimated.at(0) = estimated.at(9); - eulers_estimated.at(1) = estimated.at(10); - eulers_estimated.at(2) = estimated.at(11); + // Get the measured translation + cv::Mat translation_measured(3, 1, CV_64F); + translation_measured = pnp_detection.get_t_matrix(); + + // Get the measured rotation + cv::Mat rotation_measured(3, 3, CV_64F); + rotation_measured = pnp_detection.get_R_matrix(); + + // fill the measurements vector + fillMeasurements(measurements, translation_measured, rotation_measured); + + } + + // Instantiate estimated translation and rotation + cv::Mat translation_estimated(3, 1, CV_64F); + cv::Mat rotation_estimated(3, 3, CV_64F); + + // update the Kalman filter with good measurements + updateKalmanFilter( KF, measurements, + translation_estimated, rotation_estimated); + @endcode + The following code corresponds to the *fillMeasurements()* function which converts the measured + [Rotation Matrix to Eulers + angles](http://euclideanspace.com/maths/geometry/rotations/conversions/matrixToEuler/index.htm) + and fill the measurements matrix along with the measured translation vector: + @code{.cpp} + void fillMeasurements( cv::Mat &measurements, + const cv::Mat &translation_measured, const cv::Mat &rotation_measured) + { + // Convert rotation matrix to euler angles + cv::Mat measured_eulers(3, 1, CV_64F); + measured_eulers = rot2euler(rotation_measured); + + // Set measurement to predict + measurements.at(0) = translation_measured.at(0); // x + measurements.at(1) = translation_measured.at(1); // y + measurements.at(2) = translation_measured.at(2); // z + measurements.at(3) = measured_eulers.at(0); // roll + measurements.at(4) = measured_eulers.at(1); // pitch + measurements.at(5) = measured_eulers.at(2); // yaw + } + @endcode + The following code corresponds to the *updateKalmanFilter()* function which update the Kalman + Filter and set the estimated Rotation Matrix and translation vector. The estimated Rotation Matrix + comes from the estimated [Euler angles to Rotation + Matrix](http://euclideanspace.com/maths/geometry/rotations/conversions/eulerToMatrix/index.htm). + @code{.cpp} + void updateKalmanFilter( cv::KalmanFilter &KF, cv::Mat &measurement, + cv::Mat &translation_estimated, cv::Mat &rotation_estimated ) + { - // Convert estimated quaternion to rotation matrix - rotation_estimated = euler2rot(eulers_estimated); + // First predict, to update the internal statePre variable + cv::Mat prediction = KF.predict(); + + // The "correct" phase that is going to use the predicted value and our measurement + cv::Mat estimated = KF.correct(measurement); + + // Estimated translation + translation_estimated.at(0) = estimated.at(0); + translation_estimated.at(1) = estimated.at(1); + translation_estimated.at(2) = estimated.at(2); + + // Estimated euler angles + cv::Mat eulers_estimated(3, 1, CV_64F); + eulers_estimated.at(0) = estimated.at(9); + eulers_estimated.at(1) = estimated.at(10); + eulers_estimated.at(2) = estimated.at(11); + + // Convert estimated quaternion to rotation matrix + rotation_estimated = euler2rot(eulers_estimated); + + } + @endcode + The 6th step is set the estimated rotation-translation matrix: + @code{.cpp} + // -- Step 6: Set estimated projection matrix + pnp_detection_est.set_P_matrix(rotation_estimated, translation_estimated); + @endcode + The last and optional step is draw the found pose. To do it I implemented a function to draw all + the mesh 3D points and an extra reference axis: + @code{.cpp} + // -- Step X: Draw pose + + drawObjectMesh(frame_vis, &mesh, &pnp_detection, green); // draw current pose + drawObjectMesh(frame_vis, &mesh, &pnp_detection_est, yellow); // draw estimated pose + + double l = 5; + std::vector pose_points2d; + pose_points2d.push_back(pnp_detection_est.backproject3DPoint(cv::Point3f(0,0,0))); // axis center + pose_points2d.push_back(pnp_detection_est.backproject3DPoint(cv::Point3f(l,0,0))); // axis x + pose_points2d.push_back(pnp_detection_est.backproject3DPoint(cv::Point3f(0,l,0))); // axis y + pose_points2d.push_back(pnp_detection_est.backproject3DPoint(cv::Point3f(0,0,l))); // axis z + draw3DCoordinateAxes(frame_vis, pose_points2d); // draw axes + @endcode + You can also modify the minimum inliers to update Kalman Filter: + @code{.cpp} + ./cpp-tutorial-pnp_detection --inliers=20 + @endcode -} -@endcode -The 6th step is set the estimated rotation-translation matrix: -@code{.cpp} -// -- Step 6: Set estimated projection matrix -pnp_detection_est.set_P_matrix(rotation_estimated, translation_estimated); -@endcode -The last and optional step is draw the found pose. To do it I implemented a function to draw all -the mesh 3D points and an extra reference axis: -@code{.cpp} -// -- Step X: Draw pose - -drawObjectMesh(frame_vis, &mesh, &pnp_detection, green); // draw current pose -drawObjectMesh(frame_vis, &mesh, &pnp_detection_est, yellow); // draw estimated pose - -double l = 5; -std::vector pose_points2d; -pose_points2d.push_back(pnp_detection_est.backproject3DPoint(cv::Point3f(0,0,0))); // axis center -pose_points2d.push_back(pnp_detection_est.backproject3DPoint(cv::Point3f(l,0,0))); // axis x -pose_points2d.push_back(pnp_detection_est.backproject3DPoint(cv::Point3f(0,l,0))); // axis y -pose_points2d.push_back(pnp_detection_est.backproject3DPoint(cv::Point3f(0,0,l))); // axis z -draw3DCoordinateAxes(frame_vis, pose_points2d); // draw axes -@endcode -You can also modify the minimum inliers to update Kalman Filter: -@code{.cpp} -./cpp-tutorial-pnp_detection --inliers=20 -@endcode Results ------- diff --git a/doc/tutorials/core/adding_images/adding_images.markdown b/doc/tutorials/core/adding_images/adding_images.markdown index d3278b27b3..b6ef7b7cd2 100644 --- a/doc/tutorials/core/adding_images/adding_images.markdown +++ b/doc/tutorials/core/adding_images/adding_images.markdown @@ -73,7 +73,7 @@ int main( int argc, char** argv ) Explanation ----------- -1. Since we are going to perform: +-# Since we are going to perform: \f[g(x) = (1 - \alpha)f_{0}(x) + \alpha f_{1}(x)\f] @@ -87,7 +87,7 @@ Explanation Since we are *adding* *src1* and *src2*, they both have to be of the same size (width and height) and type. -2. Now we need to generate the `g(x)` image. For this, the function add_weighted:addWeighted comes quite handy: +-# Now we need to generate the `g(x)` image. For this, the function add_weighted:addWeighted comes quite handy: @code{.cpp} beta = ( 1.0 - alpha ); addWeighted( src1, alpha, src2, beta, 0.0, dst); @@ -96,9 +96,9 @@ Explanation \f[dst = \alpha \cdot src1 + \beta \cdot src2 + \gamma\f] In this case, `gamma` is the argument \f$0.0\f$ in the code above. -3. Create windows, show the images and wait for the user to end the program. +-# Create windows, show the images and wait for the user to end the program. Result ------ -![image](images/Adding_Images_Tutorial_Result_Big.jpg) +![](images/Adding_Images_Tutorial_Result_Big.jpg) diff --git a/doc/tutorials/core/basic_geometric_drawing/basic_geometric_drawing.markdown b/doc/tutorials/core/basic_geometric_drawing/basic_geometric_drawing.markdown index e5b9b102cf..9a921f2079 100644 --- a/doc/tutorials/core/basic_geometric_drawing/basic_geometric_drawing.markdown +++ b/doc/tutorials/core/basic_geometric_drawing/basic_geometric_drawing.markdown @@ -52,7 +52,7 @@ Code Explanation ----------- -1. Since we plan to draw two examples (an atom and a rook), we have to create 02 images and two +-# Since we plan to draw two examples (an atom and a rook), we have to create 02 images and two windows to display them. @code{.cpp} /// Windows names @@ -63,7 +63,7 @@ Explanation Mat atom_image = Mat::zeros( w, w, CV_8UC3 ); Mat rook_image = Mat::zeros( w, w, CV_8UC3 ); @endcode -2. We created functions to draw different geometric shapes. For instance, to draw the atom we used +-# We created functions to draw different geometric shapes. For instance, to draw the atom we used *MyEllipse* and *MyFilledCircle*: @code{.cpp} /// 1. Draw a simple atom: @@ -77,7 +77,7 @@ Explanation /// 1.b. Creating circles MyFilledCircle( atom_image, Point( w/2.0, w/2.0) ); @endcode -3. And to draw the rook we employed *MyLine*, *rectangle* and a *MyPolygon*: +-# And to draw the rook we employed *MyLine*, *rectangle* and a *MyPolygon*: @code{.cpp} /// 2. Draw a rook @@ -98,7 +98,7 @@ Explanation MyLine( rook_image, Point( w/2, 7*w/8 ), Point( w/2, w ) ); MyLine( rook_image, Point( 3*w/4, 7*w/8 ), Point( 3*w/4, w ) ); @endcode -4. Let's check what is inside each of these functions: +-# Let's check what is inside each of these functions: - *MyLine* @code{.cpp} void MyLine( Mat img, Point start, Point end ) @@ -240,5 +240,5 @@ Result Compiling and running your program should give you a result like this: -![image](images/Drawing_1_Tutorial_Result_0.png) +![](images/Drawing_1_Tutorial_Result_0.png) diff --git a/doc/tutorials/core/basic_linear_transform/basic_linear_transform.markdown b/doc/tutorials/core/basic_linear_transform/basic_linear_transform.markdown index 21a030fbfa..571781a3a9 100644 --- a/doc/tutorials/core/basic_linear_transform/basic_linear_transform.markdown +++ b/doc/tutorials/core/basic_linear_transform/basic_linear_transform.markdown @@ -101,16 +101,16 @@ int main( int argc, char** argv ) Explanation ----------- -1. We begin by creating parameters to save \f$\alpha\f$ and \f$\beta\f$ to be entered by the user: +-# We begin by creating parameters to save \f$\alpha\f$ and \f$\beta\f$ to be entered by the user: @code{.cpp} double alpha; int beta; @endcode -2. We load an image using @ref cv::imread and save it in a Mat object: +-# We load an image using @ref cv::imread and save it in a Mat object: @code{.cpp} Mat image = imread( argv[1] ); @endcode -3. Now, since we will make some transformations to this image, we need a new Mat object to store +-# Now, since we will make some transformations to this image, we need a new Mat object to store it. Also, we want this to have the following features: - Initial pixel values equal to zero @@ -121,7 +121,7 @@ Explanation We observe that @ref cv::Mat::zeros returns a Matlab-style zero initializer based on *image.size()* and *image.type()* -4. Now, to perform the operation \f$g(i,j) = \alpha \cdot f(i,j) + \beta\f$ we will access to each +-# Now, to perform the operation \f$g(i,j) = \alpha \cdot f(i,j) + \beta\f$ we will access to each pixel in image. Since we are operating with RGB images, we will have three values per pixel (R, G and B), so we will also access them separately. Here is the piece of code: @code{.cpp} @@ -141,7 +141,7 @@ Explanation integers (if \f$\alpha\f$ is float), we use cv::saturate_cast to make sure the values are valid. -5. Finally, we create windows and show the images, the usual way. +-# Finally, we create windows and show the images, the usual way. @code{.cpp} namedWindow("Original Image", 1); namedWindow("New Image", 1); @@ -166,7 +166,7 @@ Result - Running our code and using \f$\alpha = 2.2\f$ and \f$\beta = 50\f$ @code{.bash} - \f$ ./BasicLinearTransforms lena.jpg + $ ./BasicLinearTransforms lena.jpg Basic Linear Transforms ------------------------- * Enter the alpha value [1.0-3.0]: 2.2 @@ -175,4 +175,4 @@ Result - We get this: - ![image](images/Basic_Linear_Transform_Tutorial_Result_big.jpg) + ![](images/Basic_Linear_Transform_Tutorial_Result_big.jpg) diff --git a/doc/tutorials/core/discrete_fourier_transform/discrete_fourier_transform.markdown b/doc/tutorials/core/discrete_fourier_transform/discrete_fourier_transform.markdown index 1a65d7f7bc..f4c9b87af7 100644 --- a/doc/tutorials/core/discrete_fourier_transform/discrete_fourier_transform.markdown +++ b/doc/tutorials/core/discrete_fourier_transform/discrete_fourier_transform.markdown @@ -22,10 +22,14 @@ OpenCV source code library. Here's a sample usage of @ref cv::dft() : -@includelineno cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp - -lines - 1-4, 6, 20-21, 24-79 +@dontinclude cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp +@until highgui.hpp +@skipline iostream +@skip main +@until { +@skip filename +@until return 0; +@until } Explanation ----------- @@ -52,7 +56,7 @@ Fourier Transform too needs to be of a discrete type resulting in a Discrete Fou (*DFT*). You'll want to use this whenever you need to determine the structure of an image from a geometrical point of view. Here are the steps to follow (in case of a gray scale input image *I*): -1. **Expand the image to an optimal size**. The performance of a DFT is dependent of the image +-# **Expand the image to an optimal size**. The performance of a DFT is dependent of the image size. It tends to be the fastest for image sizes that are multiple of the numbers two, three and five. Therefore, to achieve maximal performance it is generally a good idea to pad border values to the image to get a size with such traits. The @ref cv::getOptimalDFTSize() returns this @@ -66,7 +70,7 @@ geometrical point of view. Here are the steps to follow (in case of a gray scale @endcode The appended pixels are initialized with zero. -2. **Make place for both the complex and the real values**. The result of a Fourier Transform is +-# **Make place for both the complex and the real values**. The result of a Fourier Transform is complex. This implies that for each image value the result is two image values (one per component). Moreover, the frequency domains range is much larger than its spatial counterpart. Therefore, we store these usually at least in a *float* format. Therefore we'll convert our @@ -76,12 +80,12 @@ geometrical point of view. Here are the steps to follow (in case of a gray scale Mat complexI; merge(planes, 2, complexI); // Add to the expanded another plane with zeros @endcode -3. **Make the Discrete Fourier Transform**. It's possible an in-place calculation (same input as +-# **Make the Discrete Fourier Transform**. It's possible an in-place calculation (same input as output): @code{.cpp} dft(complexI, complexI); // this way the result may fit in the source matrix @endcode -4. **Transform the real and complex values to magnitude**. A complex number has a real (*Re*) and a +-# **Transform the real and complex values to magnitude**. A complex number has a real (*Re*) and a complex (imaginary - *Im*) part. The results of a DFT are complex numbers. The magnitude of a DFT is: @@ -93,7 +97,7 @@ geometrical point of view. Here are the steps to follow (in case of a gray scale magnitude(planes[0], planes[1], planes[0]);// planes[0] = magnitude Mat magI = planes[0]; @endcode -5. **Switch to a logarithmic scale**. It turns out that the dynamic range of the Fourier +-# **Switch to a logarithmic scale**. It turns out that the dynamic range of the Fourier coefficients is too large to be displayed on the screen. We have some small and some high changing values that we can't observe like this. Therefore the high values will all turn out as white points, while the small ones as black. To use the gray scale values to for visualization @@ -106,7 +110,7 @@ geometrical point of view. Here are the steps to follow (in case of a gray scale magI += Scalar::all(1); // switch to logarithmic scale log(magI, magI); @endcode -6. **Crop and rearrange**. Remember, that at the first step, we expanded the image? Well, it's time +-# **Crop and rearrange**. Remember, that at the first step, we expanded the image? Well, it's time to throw away the newly introduced values. For visualization purposes we may also rearrange the quadrants of the result, so that the origin (zero, zero) corresponds with the image center. @code{.cpp} @@ -128,13 +132,14 @@ geometrical point of view. Here are the steps to follow (in case of a gray scale q2.copyTo(q1); tmp.copyTo(q2); @endcode -7. **Normalize**. This is done again for visualization purposes. We now have the magnitudes, +-# **Normalize**. This is done again for visualization purposes. We now have the magnitudes, however this are still out of our image display range of zero to one. We normalize our values to this range using the @ref cv::normalize() function. @code{.cpp} normalize(magI, magI, 0, 1, NORM_MINMAX); // Transform the matrix with float values into a // viewable image form (float between values 0 and 1). @endcode + Result ------ @@ -147,13 +152,12 @@ image about a text. In case of the horizontal text: -![image](images/result_normal.jpg) +![](images/result_normal.jpg) In case of a rotated text: -![image](images/result_rotated.jpg) +![](images/result_rotated.jpg) You can see that the most influential components of the frequency domain (brightest dots on the magnitude image) follow the geometric rotation of objects on the image. From this we may calculate the offset and perform an image rotation to correct eventual miss alignments. - diff --git a/doc/tutorials/core/file_input_output_with_xml_yml/file_input_output_with_xml_yml.markdown b/doc/tutorials/core/file_input_output_with_xml_yml/file_input_output_with_xml_yml.markdown index 0fc3af8e34..941f005ae0 100644 --- a/doc/tutorials/core/file_input_output_with_xml_yml/file_input_output_with_xml_yml.markdown +++ b/doc/tutorials/core/file_input_output_with_xml_yml/file_input_output_with_xml_yml.markdown @@ -22,10 +22,12 @@ library. Here's a sample code of how to achieve all the stuff enumerated at the goal list. -@includelineno cpp/tutorial_code/core/file_input_output/file_input_output.cpp +@dontinclude cpp/tutorial_code/core/file_input_output/file_input_output.cpp -lines - 1-7, 21-154 +@until std; +@skip class MyData +@until return 0; +@until } Explanation ----------- @@ -36,7 +38,7 @@ structures you may serialize: *mappings* (like the STL map) and *element sequenc vector). The difference between these is that in a map every element has a unique name through what you may access it. For sequences you need to go through them to query a specific item. -1. **XML/YAML File Open and Close.** Before you write any content to such file you need to open it +-# **XML/YAML File Open and Close.** Before you write any content to such file you need to open it and at the end to close it. The XML/YAML data structure in OpenCV is @ref cv::FileStorage . To specify that this structure to which file binds on your hard drive you can use either its constructor or the *open()* function of this: @@ -56,7 +58,7 @@ you may access it. For sequences you need to go through them to query a specific @code{.cpp} fs.release(); // explicit close @endcode -2. **Input and Output of text and numbers.** The data structure uses the same \<\< output operator +-# **Input and Output of text and numbers.** The data structure uses the same \<\< output operator that the STL library. For outputting any type of data structure we need first to specify its name. We do this by just simply printing out the name of this. For basic types you may follow this with the print of the value : @@ -70,7 +72,7 @@ you may access it. For sequences you need to go through them to query a specific fs["iterationNr"] >> itNr; itNr = (int) fs["iterationNr"]; @endcode -3. **Input/Output of OpenCV Data structures.** Well these behave exactly just as the basic C++ +-# **Input/Output of OpenCV Data structures.** Well these behave exactly just as the basic C++ types: @code{.cpp} Mat R = Mat_::eye (3, 3), @@ -82,7 +84,7 @@ you may access it. For sequences you need to go through them to query a specific fs["R"] >> R; // Read cv::Mat fs["T"] >> T; @endcode -4. **Input/Output of vectors (arrays) and associative maps.** As I mentioned beforehand, we can +-# **Input/Output of vectors (arrays) and associative maps.** As I mentioned beforehand, we can output maps and sequences (array, vector) too. Again we first print the name of the variable and then we have to specify if our output is either a sequence or map. @@ -121,7 +123,7 @@ you may access it. For sequences you need to go through them to query a specific cout << "Two " << (int)(n["Two"]) << "; "; cout << "One " << (int)(n["One"]) << endl << endl; @endcode -5. **Read and write your own data structures.** Suppose you have a data structure such as: +-# **Read and write your own data structures.** Suppose you have a data structure such as: @code{.cpp} class MyData { @@ -180,6 +182,7 @@ you may access it. For sequences you need to go through them to query a specific fs["NonExisting"] >> m; // Do not add a fs << "NonExisting" << m command for this to work cout << endl << "NonExisting = " << endl << m << endl; @endcode + Result ------ @@ -270,4 +273,3 @@ here](https://www.youtube.com/watch?v=A4yqVnByMMM) . \endhtmlonly - diff --git a/doc/tutorials/core/how_to_scan_images/how_to_scan_images.markdown b/doc/tutorials/core/how_to_scan_images/how_to_scan_images.markdown index 1f176d9ee3..e96b145a26 100644 --- a/doc/tutorials/core/how_to_scan_images/how_to_scan_images.markdown +++ b/doc/tutorials/core/how_to_scan_images/how_to_scan_images.markdown @@ -59,10 +59,10 @@ how_to_scan_images imageName.jpg intValueToReduce [G] The final argument is optional. If given the image will be loaded in gray scale format, otherwise the RGB color way is used. The first thing is to calculate the lookup table. -@includelineno cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp +@dontinclude cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp -lines - 49-61 +@skip int divideWith +@until table[i] Here we first use the C++ *stringstream* class to convert the third command line argument from text to an integer format. Then we use a simple look and the upper formula to calculate the lookup table. @@ -88,26 +88,12 @@ As you could already read in my @ref tutorial_mat_the_basic_image_container tuto depends of the color system used. More accurately, it depends from the number of channels used. In case of a gray scale image we have something like: -\f[\newcommand{\tabItG}[1] { \textcolor{black}{#1} \cellcolor[gray]{0.8}} -\begin{tabular} {ccccc} -~ & \multicolumn{1}{c}{Column 0} & \multicolumn{1}{c}{Column 1} & \multicolumn{1}{c}{Column ...} & \multicolumn{1}{c}{Column m}\\ -Row 0 & \tabItG{0,0} & \tabItG{0,1} & \tabItG{...} & \tabItG{0, m} \\ -Row 1 & \tabItG{1,0} & \tabItG{1,1} & \tabItG{...} & \tabItG{1, m} \\ -Row ... & \tabItG{...,0} & \tabItG{...,1} & \tabItG{...} & \tabItG{..., m} \\ -Row n & \tabItG{n,0} & \tabItG{n,1} & \tabItG{n,...} & \tabItG{n, m} \\ -\end{tabular}\f] +![](tutorial_how_matrix_stored_1.png) For multichannel images the columns contain as many sub columns as the number of channels. For example in case of an RGB color system: -\f[\newcommand{\tabIt}[1] { \textcolor{yellow}{#1} \cellcolor{blue} & \textcolor{black}{#1} \cellcolor{green} & \textcolor{black}{#1} \cellcolor{red}} -\begin{tabular} {ccccccccccccc} -~ & \multicolumn{3}{c}{Column 0} & \multicolumn{3}{c}{Column 1} & \multicolumn{3}{c}{Column ...} & \multicolumn{3}{c}{Column m}\\ -Row 0 & \tabIt{0,0} & \tabIt{0,1} & \tabIt{...} & \tabIt{0, m} \\ -Row 1 & \tabIt{1,0} & \tabIt{1,1} & \tabIt{...} & \tabIt{1, m} \\ -Row ... & \tabIt{...,0} & \tabIt{...,1} & \tabIt{...} & \tabIt{..., m} \\ -Row n & \tabIt{n,0} & \tabIt{n,1} & \tabIt{n,...} & \tabIt{n, m} \\ -\end{tabular}\f] +![](tutorial_how_matrix_stored_2.png) Note that the order of the channels is inverse: BGR instead of RGB. Because in many cases the memory is large enough to store the rows in a successive fashion the rows may follow one after another, @@ -121,10 +107,9 @@ The efficient way When it comes to performance you cannot beat the classic C style operator[] (pointer) access. Therefore, the most efficient method we can recommend for making the assignment is: -@includelineno cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp - -lines - 126-153 +@skip Mat& ScanImageAndReduceC +@until return +@until } Here we basically just acquire a pointer to the start of each row and go through it until it ends. In the special case that the matrix is stored in a continues manner we only need to request the @@ -156,10 +141,9 @@ considered a safer way as it takes over these tasks from the user. All you need begin and the end of the image matrix and then just increase the begin iterator until you reach the end. To acquire the value *pointed* by the iterator use the \* operator (add it before it). -@includelineno cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp - -lines - 155-183 +@skip ScanImageAndReduceIterator +@until return +@until } In case of color images we have three uchar items per column. This may be considered a short vector of uchar items, that has been baptized in OpenCV with the *Vec3b* name. To access the n-th sub @@ -177,10 +161,9 @@ what type we are looking at the image. It's no different here as you need manual type to use at the automatic lookup. You can observe this in case of the gray scale images for the following source code (the usage of the + @ref cv::at() function): -@includelineno cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp - -lines - 185-217 +@skip ScanImageAndReduceRandomAccess +@until return +@until } The functions takes your input type and coordinates and calculates on the fly the address of the queried item. Then returns a reference to that. This may be a constant when you *get* the value and @@ -209,17 +192,14 @@ OpenCV has a function that makes the modification without the need from you to w the image. We use the @ref cv::LUT() function of the core module. First we build a Mat type of the lookup table: -@includelineno cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp +@dontinclude cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp -lines - 108-111 +@skip Mat lookUpTable +@until p[i] = table[i] Finally call the function (I is our input image and J the output one): -@includelineno cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp - -lines - 116 +@skipline LUT Performance Difference ---------------------- diff --git a/doc/tutorials/core/how_to_scan_images/tutorial_how_matrix_stored_1.png b/doc/tutorials/core/how_to_scan_images/tutorial_how_matrix_stored_1.png new file mode 100644 index 0000000000000000000000000000000000000000..4d02f95ceb598622925770801233b27e573cc7d0 GIT binary patch literal 1953 zcma)7eK^y58y{PnmrPSr*+mOUHRDLiSeqE5tnwt!uq;U>R%wx!VT81@-{c%2so6uN zIK6n;ICYd|DzX=}9*cy`Bd_b#$LHK_fnM`hKYO1WPghHVX4i1Hd zg(wsXgTbVyr!yD~8jZ$cv0lD>3EuV})Hxg&%-O-Te?Zue>&mICG|c%|Jl8p`vnD$o zOc|e~(oaJm$hO60@be}l1_FWi1o(RIJNxEi`SGNhjmyZ=q%_gJfHJocy}rwImD$Ei z*EiqsnS6=pvh_GlPTbqZz))Tbw!VvLr%l~MwKGo@is(gNqz;ow#qM8vkLCZuSQ;jv zoYxXB0(=>7+e&@WjJIC(ud>5yFC5A(BE}Y$79TDD;=1F2@aFdnWv2#r#c|wZL-Tk2 zy08zwft;J|$oe_f?H8HS`pg#{|Fi+_KQ=Tjvf-RdYdbZ;z&XRW>{M5l(bt(KJIM-K zZqcO)d(W@s?8|G7S8-#!{5uvb?DwQhph`Ks>Ug|7DvAvqj~w60=) zhN!PcXBb;J59 zjcY&*e5;OP5> z)AQnmz0mXYC(1ADT;Nzcg_5eWLq7{0Hn{x0;ceTe@D-6O51C=BjGOtG$GK8ej4vD5 zn;Ma9bm(M%Z`s#JyrD$*UPzR{#SL(=b2UhI+`nr{Hpqk(lj8bzgG@_fAE@zWTY~Ii z$jXkq{*Xqm4wC~EdMeW#^>nc5ZbSDBt!QPss|pfT;^G2Sp~Pu3lZm8(-NGgbHyRf| zUmac99}*}*v=(e}R^9Be#PbUhbFIj@<#4!So9+7a%N3f5>f7#im@PAI;+?(W-1-6| z(Gg%AOXIvtj}1b`Y6(`T0Q67ElxVqWd*_hqMyKe!dCBPtuOn zB3C~*AS$eCZ}|QEV2`AJ9DX!`IaTq@sx9o`HJ2u7!7<-N?w!<>SLmQkmc(Nbq!Xm2 z1!dCNu&dgPj4rTjoCB8q+gy2m!caZE@2X!#Lh%)$_$$!q4l5197z%f5#LC!TzbJiD z>;cU;(MltX;TwZEcuBPre`JJ@K0|!Ym^J-Y5~)L3DKA4J0%n#oY8Y zei`7lb_SVw&HqurGOA$!*a=IxA}jzaBIjJnyU$&iy+4o>{xFtjfGwSayjYTY!`NnvEl@ z(awOr6wrCiGP1}Pi`q6Af#U1|m@5Q8npm%*o)xefwCHP8#7}lkXu>vN&{h+dVechC zT8J*~K)@_~L}kzPR-&B$VmknDV!f2QLNNJ}EV;m@{k74L|A-M)Qa^~gQPhfe4hoMA z>^;@{VS-6(Z-UwetWiZFyhVReRUZ*qRDbMUw1l(}p?#CgzFpzXV^`@`VdXdp3CV;~ zkLOJCNuiR4`z7N?x^2rh5Ob+{G4j>z{+xG?isS*e^(PP?AZgk50;CoUBIA5E1XLIF zzv_&Dc`u1sW8iT2!A=>`ru;MyMA`kLa*swT(wZO(vMHZ;x$Kj-G@+;R#o~Ajk#N(- zm`?|Hc(Nbpe#e@rxldm|=}nTWQ`jDLBT8ytV~V47+?A}s@g6s#?qWm?BC@O`?DbbX z;W(d$&r4`0!3bl__4a^LH(1?ENi5pbD$I$W5{w5Y=w_-IHyKF|>@%Ln>5H z8n#B#Q`tmW%yJoRO-wgQO9J27bLeWQhk wkIO?2beoPc*kG53UH>4Mde|5E_p}3M)03ZkengCD>0J{NT z9{`X601E);0N@4y@ZJ4y>nbbJ($ZhGwL90=1iQL4t*vV(CwC7F?89KlH*R1H3(sM( zH-1IOcbQc>t`0H@tdqSnfNicKSxXOM*1Kbrv57zOzsKO%Zkbyn$( zyVpPG=l2Kbx0&e4Y^{l;XCC(3mFosg5_9TpRJt?Sp}N8?4YD90yYJY}DP)RA-mCR@a@&<%PfI-D2n)b>9@R`qpW|XqULD ztvMINtGp+;Z@-^Sc;NuT53K=_fb&Zc*Tx%PIjFayKX-{+C?AlnXWc__--`LI>d5%I3nP8 zr<@Ybr^dpswAi3)YxMgI(Kpv}1beHvZyiF@aCsV?t=P^N?^3$Z!nqd8MQQPtgU&-g z(a61Yyo>%-&qoN`58Fmf;5w7v%H8ucMxN%Y&tB}eKl_l3Ttug5P#9CDRmZ614VwcO)m7+eE>((LTDtIA zoL)$PQ1*{C@##a5hwrxGR=0(?yTmb0CW;EAr=aC8IPuns$;bAE*OiP*c^O}TWiAn& z>vBzPL?76jOrB@)==tH{+OTgF4(&+;os*g6N#cI3V$D%4G|Iy_YWC)ON46dKE7@XB zw@%=`zdVvyX^}la>v20TOe%%tx|02p>nTU5qTIhSH!0rPYDImoia^%S3&K5BRaP}C z>pzxvsU;uHKfz}3xwR_a+yJogi?(>-6}CP zZ@tHZ8^dTgwfL9X^rpvxyy;L#W7GcDqM%D@aC}UGm|1ws9+{a{5A6g)SWs{#7PaUX zF<14Yelodicy`PC2=kcm7Z$k>sE$ocxyWz+n7&XX6$Ac;}bO~ z%S&#XJbeQTXco(Fjxh&X>)Br|?KVr%sj-BiGCKFhcwdW$ z6aor(F3vH!H@ryUCc#+CP0Z?W3qJ8Ed3D`nPtmYq(jJ)=UGl*(y98Kg4~98!u*YG{ zACuNgJ@k7L&QTJ|dq9C6moJ}QELvXe9}St$6RVn4wF@*Go!XqiMc)&PnVqr=^c$Uj z^W}VGq1ePuE~-aCWB5>4L4CaH)~4VrCea&KkjIH7yPe8|>gawia2avNq`~9sMWV$z zdt`ROw9rVAa}?j5SaWJhRARza8?*SI!Ynr07VGLi6&iuRF5r-#lEjJzX+*d+&s3rZ#q z8Io%YZbw#cpX}?4us9I^JgXV3lV)D_Ot%8w7xWSB{7i+hffMNZ&NvT7`OeZ=ayqaC zbQi97JSqw$|KzDC7t<(@R($*IeD$*su6@p`=BlQq;$B2p)~!3S6Ao7b-o{aGy*6kh zAJ*xzNZnsK-{ziwnVk4!T+6ZV*LX=Wy^1>{q{n4Vt3_c-Oic}4g?=jUKag2Tm2%?V z!0m0cWw-t~6kf*oPLVws=Nz+^!bV3@nx)Z`efo-fkod;H^ql7Q&b7SQAK#7`Q#Z~8 z_FA>xb(r}0`3p_E+Vs8amt#M1aa)ViAMJ)Xb^R;MI$8ZVW>MEDvdG?pYPN-U1vl3p zj$kKcu1!riM`4J`Z3!NcUXW@5x#Z!0g;i&t%6KU%%WyA)a9-PgF= zbhufk2swPcJN`7-2XaA80Ia+HaM8x1zU;)6td>X4Ss12&mW+$HuMheW%iXB7l*N!@ zOPMBhCnS?r*woPlZt~iLCnFvn<1;6HhTL+OIi*MWctF^e z32X+S%KQmGpDD4lDBq7L3-MktGC&xZ(^dd6V00z9qnN0YeZ8Ke)v`SbT&Q3GMkkRo zC9MSFCm5X-n;-KC=;)X`I8ABNVUy&bl>J7AaC70oN`Hbfw^Q%Ju}k2-3hLFFp6KDh z^4U>o;Nbf=T7d1Ot2|T?EIhly6n~)bgb))jDDKCKT^eek%RxI4VjWs71AI}C=ks8; z=aNv#FVbYk1p53{yR}*jau(#E8GO+kOfMKorM_$&5%Tt(CE1^Fx%&3RuQ0*jOu0vh zkhl>(p@XE}#EtDE2PP*seOwxCU82uzB0{b$X**6B!&5856WIGUIEx1pq?m*T;o&!0 zN)fMOF8_Z%L2o`oNrrG~m##C$Aludbh0i$MqmoPluASB~?K>*1M1+ig;lQFUi>-j# zNU$#I4dDM==PoqW*930+TjTkA8`|1J$2=ANj*{0y&{JUraQEX$cF>ClfcW9C5TW(K zu*dND0T?f_lIzU?knHU&!07O6T>?>13qcv*+c;Na@^F}xlfLvql)G+43XmEh8l96d zx4M=G@42m12I-Y~Q9^7O2!8jR;=7$~7!8@FDwjca-@>o}QEPe#0qlyh)an_5LPw@8 zbP^!|+D1r9vH(<~AC*-G5eusc0W9{1$&3U_jbs@0p0Z2Nz&f$c?jy02*M?l9{?H{T z6Lk?I)ctnQff)htW(V(_?$jle615SSwuiQSrHP&S#WnBv_3lMBP@2{VyYcfU0)W|b-c6upv%8>1p8Yw zq!mRKKgrJYjcM04|5!1ZIh!3qc;@wd-jRR%Fm91Q)uxM{q&x` zAbJGdhsT!IU~$XW)?TT6&v&5jDEbpt{IYkMsL={TWR&J;9qZgb?(hAN@07onO9X-! zSq3>zp!*RHT>5})`AvOB3PamI2@+90flW#&QRfm}kp42}Z_-y_JxR)V2$uf4AK;_> z8cE3Es}>}i0o0~q@obQcdDAP=^?xrSJhz;snqjVrwTO&j!etCky^{1z0f_ z)P7s2k=4AW2>h5F&xN%TIutIn4x3D>l6fiVMR-WZ52Nkh5~7NZJnC+Ov>^#*DG6aXw~W z12RXa1LU?krq{HPq2hkXu@ygGl`mRuQ9cS+T>8c@yYe3B4ej&DW_roq6!}OqI&^PI zlwP*vw+@c2wK|BI95d zBkBE@r+S*Ou+B|$l)@ERH2R;zEd(c3FuK$Fim&jH-lcHU)J=gUM8=@5QrNNQl*(GK zvv|n07S3+9P9#P0$tTxqtFWCHbeB^;R3iB~i_A{fhNh z-F(%N{Jj$Mq9E$<-M&VeH+~Ebu9g;}EU3SQP>hF%3g$Jk|4{Undt=WHaur7E)9>?5mYFIN%g!9OD1&+9*i)@uji zOP^v-+dPUfqaqUoidF@U=N~)X8`m&t%a0S#c?lkXLA{#o!&YoR!bjPLsv{M9{`!3{ f%H4Hx(`;Y+!6BM+g%bD^37k4g@Ci(vWz_~uw literal 0 HcmV?d00001 diff --git a/doc/tutorials/core/how_to_use_ippa_conversion/how_to_use_ippa_conversion.markdown b/doc/tutorials/core/how_to_use_ippa_conversion/how_to_use_ippa_conversion.markdown index 64ff0daecb..c52a1e9d7d 100644 --- a/doc/tutorials/core/how_to_use_ippa_conversion/how_to_use_ippa_conversion.markdown +++ b/doc/tutorials/core/how_to_use_ippa_conversion/how_to_use_ippa_conversion.markdown @@ -23,7 +23,7 @@ download it from [here](samples/cpp/tutorial_code/core/ippasync/ippasync_sample. Explanation ----------- -1. Create parameters for OpenCV: +-# Create parameters for OpenCV: @code{.cpp} VideoCapture cap; Mat image, gray, result; @@ -36,7 +36,7 @@ Explanation hppStatus sts; hppiVirtualMatrix * virtMatrix; @endcode -2. Load input image or video. How to open and read video stream you can see in the +-# Load input image or video. How to open and read video stream you can see in the @ref tutorial_video_input_psnr_ssim tutorial. @code{.cpp} if( useCamera ) @@ -56,7 +56,7 @@ Explanation return -1; } @endcode -3. Create accelerator instance using +-# Create accelerator instance using [hppCreateInstance](http://software.intel.com/en-us/node/501686): @code{.cpp} accelType = sAccel == "cpu" ? HPP_ACCEL_TYPE_CPU: @@ -67,12 +67,12 @@ Explanation sts = hppCreateInstance(accelType, 0, &accel); CHECK_STATUS(sts, "hppCreateInstance"); @endcode -4. Create an array of virtual matrices using +-# Create an array of virtual matrices using [hppiCreateVirtualMatrices](http://software.intel.com/en-us/node/501700) function. @code{.cpp} virtMatrix = hppiCreateVirtualMatrices(accel, 1); @endcode -5. Prepare a matrix for input and output data: +-# Prepare a matrix for input and output data: @code{.cpp} cap >> image; if(image.empty()) @@ -82,7 +82,7 @@ Explanation result.create( image.rows, image.cols, CV_8U); @endcode -6. Convert Mat to [hppiMatrix](http://software.intel.com/en-us/node/501660) using @ref cv::hpp::getHpp +-# Convert Mat to [hppiMatrix](http://software.intel.com/en-us/node/501660) using @ref cv::hpp::getHpp and call [hppiSobel](http://software.intel.com/en-us/node/474701) function. @code{.cpp} //convert Mat to hppiMatrix @@ -104,14 +104,14 @@ Explanation HPP_DATA_TYPE_16S data type for source matrix with HPP_DATA_TYPE_8U type. You should check hppStatus after each call IPP Async function. -7. Create windows and show the images, the usual way. +-# Create windows and show the images, the usual way. @code{.cpp} imshow("image", image); imshow("rez", result); waitKey(15); @endcode -8. Delete hpp matrices. +-# Delete hpp matrices. @code{.cpp} sts = hppiFreeMatrix(src); CHECK_DEL_STATUS(sts,"hppiFreeMatrix"); @@ -119,7 +119,7 @@ Explanation sts = hppiFreeMatrix(dst); CHECK_DEL_STATUS(sts,"hppiFreeMatrix"); @endcode -9. Delete virtual matrices and accelerator instance. +-# Delete virtual matrices and accelerator instance. @code{.cpp} if (virtMatrix) { @@ -140,4 +140,4 @@ Result After compiling the code above we can execute it giving an image or video path and accelerator type as an argument. For this tutorial we use baboon.png image as input. The result is below. -![image](images/How_To_Use_IPPA_Result.jpg) +![](images/How_To_Use_IPPA_Result.jpg) diff --git a/doc/tutorials/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.markdown b/doc/tutorials/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.markdown index 873c29ae3d..589e31f6fc 100644 --- a/doc/tutorials/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.markdown +++ b/doc/tutorials/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.markdown @@ -93,20 +93,18 @@ To further help on seeing the difference the programs supports two modes: one mi one pure C++. If you define the *DEMO_MIXED_API_USE* you'll end up using the first. The program separates the color planes, does some modifications on them and in the end merge them back together. -@includelineno -cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp - -lines - 1-10, 23-26, 29-46 +@dontinclude cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp +@until namespace cv +@skip ifdef +@until endif +@skip main +@until endif Here you can observe that with the new structure we have no pointer problems, although it is possible to use the old functions and in the end just transform the result to a *Mat* object. -@includelineno -cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp - -lines - 48-53 +@skip convert image +@until split Because, we want to mess around with the images luma component we first convert from the default RGB to the YUV color space and then split the result up into separate planes. Here the program splits: @@ -116,11 +114,8 @@ image some Gaussian noise and then mix together the channels according to some f The scanning version looks like: -@includelineno -cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp - -lines - 57-77 +@skip #if 1 +@until #else Here you can observe that we may go through all the pixels of an image in three fashions: an iterator, a C pointer and an individual element access style. You can read a more in-depth @@ -128,26 +123,20 @@ description of these in the @ref tutorial_how_to_scan_images tutorial. Convertin names is easy. Just remove the cv prefix and use the new *Mat* data structure. Here's an example of this by using the weighted addition function: -@includelineno -cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp - -lines - 81-113 +@until planes[0] +@until endif As you may observe the *planes* variable is of type *Mat*. However, converting from *Mat* to *IplImage* is easy and made automatically with a simple assignment operator. -@includelineno -cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp - -lines - 117-129 +@skip merge(planes +@until #endif The new *imshow* highgui function accepts both the *Mat* and *IplImage* data structures. Compile and run the program and if the first image below is your input you may get either the first or second as output: -![image](images/outputInteropOpenCV1.jpg) +![](images/outputInteropOpenCV1.jpg) You may observe a runtime instance of this on the [YouTube here](https://www.youtube.com/watch?v=qckm-zvo31w) and you can [download the source code from here diff --git a/doc/tutorials/core/mat-mask-operations/mat_mask_operations.markdown b/doc/tutorials/core/mat-mask-operations/mat_mask_operations.markdown index dbc10e6713..e185d2803d 100644 --- a/doc/tutorials/core/mat-mask-operations/mat_mask_operations.markdown +++ b/doc/tutorials/core/mat-mask-operations/mat_mask_operations.markdown @@ -130,7 +130,7 @@ difference. For example: -![image](images/resultMatMaskFilter2D.png) +![](images/resultMatMaskFilter2D.png) You can download this source code from [here ](samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp) or look in the diff --git a/doc/tutorials/core/mat_the_basic_image_container/mat_the_basic_image_container.markdown b/doc/tutorials/core/mat_the_basic_image_container/mat_the_basic_image_container.markdown index 3bc234e0cd..e31d252781 100644 --- a/doc/tutorials/core/mat_the_basic_image_container/mat_the_basic_image_container.markdown +++ b/doc/tutorials/core/mat_the_basic_image_container/mat_the_basic_image_container.markdown @@ -9,7 +9,7 @@ computed tomography, and magnetic resonance imaging to name a few. In every case see are images. However, when transforming this to our digital devices what we record are numerical values for each of the points of the image. -![image](images/MatBasicImageForComputer.jpg) +![](images/MatBasicImageForComputer.jpg) For example in the above image you can see that the mirror of the car is nothing more than a matrix containing all the intensity values of the pixel points. How we get and store the pixels values may @@ -144,18 +144,18 @@ file by using the @ref cv::imwrite() function. However, for debugging purposes i convenient to see the actual values. You can do this using the \<\< operator of *Mat*. Be aware that this only works for two dimensional matrices. +@dontinclude cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp + Although *Mat* works really well as an image container, it is also a general matrix class. Therefore, it is possible to create and manipulate multidimensional matrices. You can create a Mat object in multiple ways: - @ref cv::Mat::Mat Constructor - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - - lines 27-28 + @skip Mat M(2 + @until cout - ![image](images/MatBasicContainerOut1.png) + ![](images/MatBasicContainerOut1.png) For two dimensional and multichannel images we first define their size: row and column count wise. @@ -173,11 +173,8 @@ object in multiple ways: - Use C/C++ arrays and initialize via constructor - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - - lines - 35-36 + @skip int sz + @until Mat L The upper example shows how to create a matrix with more than two dimensions. Specify its dimension, then pass a pointer containing the size for each dimension and the rest remains the @@ -188,14 +185,14 @@ object in multiple ways: IplImage* img = cvLoadImage("greatwave.png", 1); Mat mtx(img); // convert IplImage* -> Mat @endcode -- @ref cv::Mat::create function: - - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - lines 31-32 +- @ref cv::Mat::create function: + @code + M.create(4,4, CV_8UC(2)); + cout << "M = "<< endl << " " << M << endl << endl; + @endcode - ![image](images/MatBasicContainerOut2.png) + ![](images/MatBasicContainerOut2.png) You cannot initialize the matrix values with this construction. It will only reallocate its matrix data memory if the new size will not fit into the old one. @@ -203,41 +200,31 @@ object in multiple ways: - MATLAB style initializer: @ref cv::Mat::zeros , @ref cv::Mat::ones , @ref cv::Mat::eye . Specify size and data type to use: - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - - lines - 40-47 + @skip Mat E + @until cout - ![image](images/MatBasicContainerOut3.png) + ![](images/MatBasicContainerOut3.png) - For small matrices you may use comma separated initializers: - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp + @skip Mat C + @until cout - lines 50-51 - - ![image](images/MatBasicContainerOut6.png) + ![](images/MatBasicContainerOut6.png) - Create a new header for an existing *Mat* object and @ref cv::Mat::clone or @ref cv::Mat::copyTo it. - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - - lines 53-54 + @skip Mat RowClone + @until cout - ![image](images/MatBasicContainerOut7.png) + ![](images/MatBasicContainerOut7.png) @note - You can fill out a matrix with random values using the @ref cv::randu() function. You need to - give the lower and upper value for the random values: + You can fill out a matrix with random values using the @ref cv::randu() function. You need to + give the lower and upper value for the random values: + @skip Mat R + @until randu - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - - lines - 57-58 Output formatting ----------------- @@ -246,54 +233,26 @@ In the above examples you could see the default formatting option. OpenCV, howev format your matrix output: - Default - - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - - lines - 61 - - ![image](images/MatBasicContainerOut8.png) + @skipline (default) + ![](images/MatBasicContainerOut8.png) - Python - - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - - lines - 62 - - ![image](images/MatBasicContainerOut16.png) + @skipline (python) + ![](images/MatBasicContainerOut16.png) - Comma separated values (CSV) - - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - - lines - 64 - - ![image](images/MatBasicContainerOut10.png) + @skipline (csv) + ![](images/MatBasicContainerOut10.png) - Numpy - - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - - lines - 63 - - ![image](images/MatBasicContainerOut9.png) + @code + cout << "R (numpy) = " << endl << format(R, Formatter::FMT_NUMPY ) << endl << endl; + @endcode + ![](images/MatBasicContainerOut9.png) - C - - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - - lines - 65 - - ![image](images/MatBasicContainerOut11.png) + @skipline (c) + ![](images/MatBasicContainerOut11.png) Output of other common items ---------------------------- @@ -301,44 +260,24 @@ Output of other common items OpenCV offers support for output of other common OpenCV data structures too via the \<\< operator: - 2D Point - - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - - lines - 67-68 - - ![image](images/MatBasicContainerOut12.png) + @skip Point2f P + @until cout + ![](images/MatBasicContainerOut12.png) - 3D Point - - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - - lines - 70-71 - - ![image](images/MatBasicContainerOut13.png) + @skip Point3f P3f + @until cout + ![](images/MatBasicContainerOut13.png) - std::vector via cv::Mat - - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - - lines - 74-77 - - ![image](images/MatBasicContainerOut14.png) + @skip vector v + @until cout + ![](images/MatBasicContainerOut14.png) - std::vector of points - - @includelineno - cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp - - lines - 79-83 - - ![image](images/MatBasicContainerOut15.png) + @skip vector vPoints + @until cout + ![](images/MatBasicContainerOut15.png) Most of the samples here have been included in a small console application. You can download it from [here](samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp) diff --git a/doc/tutorials/core/random_generator_and_text/random_generator_and_text.markdown b/doc/tutorials/core/random_generator_and_text/random_generator_and_text.markdown index 835a453a82..fa7dc07ee7 100644 --- a/doc/tutorials/core/random_generator_and_text/random_generator_and_text.markdown +++ b/doc/tutorials/core/random_generator_and_text/random_generator_and_text.markdown @@ -25,7 +25,7 @@ Code Explanation ----------- -1. Let's start by checking out the *main* function. We observe that first thing we do is creating a +-# Let's start by checking out the *main* function. We observe that first thing we do is creating a *Random Number Generator* object (RNG): @code{.cpp} RNG rng( 0xFFFFFFFF ); @@ -33,7 +33,7 @@ Explanation RNG implements a random number generator. In this example, *rng* is a RNG element initialized with the value *0xFFFFFFFF* -2. Then we create a matrix initialized to *zeros* (which means that it will appear as black), +-# Then we create a matrix initialized to *zeros* (which means that it will appear as black), specifying its height, width and its type: @code{.cpp} /// Initialize a matrix filled with zeros @@ -42,7 +42,7 @@ Explanation /// Show it in a window during DELAY ms imshow( window_name, image ); @endcode -3. Then we proceed to draw crazy stuff. After taking a look at the code, you can see that it is +-# Then we proceed to draw crazy stuff. After taking a look at the code, you can see that it is mainly divided in 8 sections, defined as functions: @code{.cpp} /// Now, let's draw some lines @@ -79,7 +79,7 @@ Explanation All of these functions follow the same pattern, so we will analyze only a couple of them, since the same explanation applies for all. -4. Checking out the function **Drawing_Random_Lines**: +-# Checking out the function **Drawing_Random_Lines**: @code{.cpp} int Drawing_Random_Lines( Mat image, char* window_name, RNG rng ) { @@ -133,11 +133,11 @@ Explanation are used as the *R*, *G* and *B* parameters for the line color. Hence, the color of the lines will be random too! -5. The explanation above applies for the other functions generating circles, ellipses, polygones, +-# The explanation above applies for the other functions generating circles, ellipses, polygones, etc. The parameters such as *center* and *vertices* are also generated randomly. -6. Before finishing, we also should take a look at the functions *Display_Random_Text* and +-# Before finishing, we also should take a look at the functions *Display_Random_Text* and *Displaying_Big_End*, since they both have a few interesting features: -7. **Display_Random_Text:** +-# **Display_Random_Text:** @code{.cpp} int Displaying_Random_Text( Mat image, char* window_name, RNG rng ) { @@ -178,7 +178,7 @@ Explanation As a result, we will get (analagously to the other drawing functions) **NUMBER** texts over our image, in random locations. -8. **Displaying_Big_End** +-# **Displaying_Big_End** @code{.cpp} int Displaying_Big_End( Mat image, char* window_name, RNG rng ) { @@ -222,28 +222,28 @@ Result As you just saw in the Code section, the program will sequentially execute diverse drawing functions, which will produce: -1. First a random set of *NUMBER* lines will appear on screen such as it can be seen in this +-# First a random set of *NUMBER* lines will appear on screen such as it can be seen in this screenshot: - ![image](images/Drawing_2_Tutorial_Result_0.jpg) + ![](images/Drawing_2_Tutorial_Result_0.jpg) -2. Then, a new set of figures, these time *rectangles* will follow. -3. Now some ellipses will appear, each of them with random position, size, thickness and arc +-# Then, a new set of figures, these time *rectangles* will follow. +-# Now some ellipses will appear, each of them with random position, size, thickness and arc length: - ![image](images/Drawing_2_Tutorial_Result_2.jpg) + ![](images/Drawing_2_Tutorial_Result_2.jpg) -4. Now, *polylines* with 03 segments will appear on screen, again in random configurations. +-# Now, *polylines* with 03 segments will appear on screen, again in random configurations. - ![image](images/Drawing_2_Tutorial_Result_3.jpg) + ![](images/Drawing_2_Tutorial_Result_3.jpg) -5. Filled polygons (in this example triangles) will follow. -6. The last geometric figure to appear: circles! +-# Filled polygons (in this example triangles) will follow. +-# The last geometric figure to appear: circles! - ![image](images/Drawing_2_Tutorial_Result_5.jpg) + ![](images/Drawing_2_Tutorial_Result_5.jpg) -7. Near the end, the text *"Testing Text Rendering"* will appear in a variety of fonts, sizes, +-# Near the end, the text *"Testing Text Rendering"* will appear in a variety of fonts, sizes, colors and positions. -8. And the big end (which by the way expresses a big truth too): +-# And the big end (which by the way expresses a big truth too): - ![image](images/Drawing_2_Tutorial_Result_big.jpg) + ![](images/Drawing_2_Tutorial_Result_big.jpg) diff --git a/doc/tutorials/features2d/akaze_matching/akaze_matching.markdown b/doc/tutorials/features2d/akaze_matching/akaze_matching.markdown index 8575830e8b..43d9929b76 100644 --- a/doc/tutorials/features2d/akaze_matching/akaze_matching.markdown +++ b/doc/tutorials/features2d/akaze_matching/akaze_matching.markdown @@ -4,10 +4,10 @@ AKAZE local features matching {#tutorial_akaze_matching} Introduction ------------ -In this tutorial we will learn how to use [AKAZE]_ local features to detect and match keypoints on +In this tutorial we will learn how to use AKAZE @cite ANB13 local features to detect and match keypoints on two images. - We will find keypoints on a pair of images with given homography matrix, match them and count the + number of inliers (i. e. matches that fit in the given homography). You can find expanded version of this example here: @@ -18,7 +18,7 @@ Data We are going to use images 1 and 3 from *Graffity* sequence of Oxford dataset. -![image](images/graf.png) +![](images/graf.png) Homography is given by a 3 by 3 matrix: @code{.none} @@ -35,92 +35,92 @@ You can find the images (*graf1.png*, *graf3.png*) and homography (*H1to3p.xml*) ### Explanation -1. **Load images and homography** -@code{.cpp} -Mat img1 = imread("graf1.png", IMREAD_GRAYSCALE); -Mat img2 = imread("graf3.png", IMREAD_GRAYSCALE); - -Mat homography; -FileStorage fs("H1to3p.xml", FileStorage::READ); -fs.getFirstTopLevelNode() >> homography; -@endcode -We are loading grayscale images here. Homography is stored in the xml created with FileStorage. - -1. **Detect keypoints and compute descriptors using AKAZE** -@code{.cpp} -vector kpts1, kpts2; -Mat desc1, desc2; - -AKAZE akaze; -akaze(img1, noArray(), kpts1, desc1); -akaze(img2, noArray(), kpts2, desc2); -@endcode -We create AKAZE object and use it's *operator()* functionality. Since we don't need the *mask* -parameter, *noArray()* is used. - -1. **Use brute-force matcher to find 2-nn matches** -@code{.cpp} -BFMatcher matcher(NORM_HAMMING); -vector< vector > nn_matches; -matcher.knnMatch(desc1, desc2, nn_matches, 2); -@endcode -We use Hamming distance, because AKAZE uses binary descriptor by default. - -1. **Use 2-nn matches to find correct keypoint matches** -@code{.cpp} -for(size_t i = 0; i < nn_matches.size(); i++) { - DMatch first = nn_matches[i][0]; - float dist1 = nn_matches[i][0].distance; - float dist2 = nn_matches[i][1].distance; - - if(dist1 < nn_match_ratio * dist2) { - matched1.push_back(kpts1[first.queryIdx]); - matched2.push_back(kpts2[first.trainIdx]); +-# **Load images and homography** + @code{.cpp} + Mat img1 = imread("graf1.png", IMREAD_GRAYSCALE); + Mat img2 = imread("graf3.png", IMREAD_GRAYSCALE); + + Mat homography; + FileStorage fs("H1to3p.xml", FileStorage::READ); + fs.getFirstTopLevelNode() >> homography; + @endcode + We are loading grayscale images here. Homography is stored in the xml created with FileStorage. + +-# **Detect keypoints and compute descriptors using AKAZE** + @code{.cpp} + vector kpts1, kpts2; + Mat desc1, desc2; + + AKAZE akaze; + akaze(img1, noArray(), kpts1, desc1); + akaze(img2, noArray(), kpts2, desc2); + @endcode + We create AKAZE object and use it's *operator()* functionality. Since we don't need the *mask* + parameter, *noArray()* is used. + +-# **Use brute-force matcher to find 2-nn matches** + @code{.cpp} + BFMatcher matcher(NORM_HAMMING); + vector< vector > nn_matches; + matcher.knnMatch(desc1, desc2, nn_matches, 2); + @endcode + We use Hamming distance, because AKAZE uses binary descriptor by default. + +-# **Use 2-nn matches to find correct keypoint matches** + @code{.cpp} + for(size_t i = 0; i < nn_matches.size(); i++) { + DMatch first = nn_matches[i][0]; + float dist1 = nn_matches[i][0].distance; + float dist2 = nn_matches[i][1].distance; + + if(dist1 < nn_match_ratio * dist2) { + matched1.push_back(kpts1[first.queryIdx]); + matched2.push_back(kpts2[first.trainIdx]); + } } -} -@endcode -If the closest match is *ratio* closer than the second closest one, then the match is correct. - -1. **Check if our matches fit in the homography model** -@code{.cpp} -for(int i = 0; i < matched1.size(); i++) { - Mat col = Mat::ones(3, 1, CV_64F); - col.at(0) = matched1[i].pt.x; - col.at(1) = matched1[i].pt.y; - - col = homography * col; - col /= col.at(2); - float dist = sqrt( pow(col.at(0) - matched2[i].pt.x, 2) + - pow(col.at(1) - matched2[i].pt.y, 2)); - - if(dist < inlier_threshold) { - int new_i = inliers1.size(); - inliers1.push_back(matched1[i]); - inliers2.push_back(matched2[i]); - good_matches.push_back(DMatch(new_i, new_i, 0)); + @endcode + If the closest match is *ratio* closer than the second closest one, then the match is correct. + +-# **Check if our matches fit in the homography model** + @code{.cpp} + for(int i = 0; i < matched1.size(); i++) { + Mat col = Mat::ones(3, 1, CV_64F); + col.at(0) = matched1[i].pt.x; + col.at(1) = matched1[i].pt.y; + + col = homography * col; + col /= col.at(2); + float dist = sqrt( pow(col.at(0) - matched2[i].pt.x, 2) + + pow(col.at(1) - matched2[i].pt.y, 2)); + + if(dist < inlier_threshold) { + int new_i = inliers1.size(); + inliers1.push_back(matched1[i]); + inliers2.push_back(matched2[i]); + good_matches.push_back(DMatch(new_i, new_i, 0)); + } } -} -@endcode -If the distance from first keypoint's projection to the second keypoint is less than threshold, -then it it fits in the homography. + @endcode + If the distance from first keypoint's projection to the second keypoint is less than threshold, + then it it fits in the homography. -We create a new set of matches for the inliers, because it is required by the drawing function. + We create a new set of matches for the inliers, because it is required by the drawing function. -1. **Output results** -@code{.cpp} -Mat res; -drawMatches(img1, inliers1, img2, inliers2, good_matches, res); -imwrite("res.png", res); -... -@endcode -Here we save the resulting image and print some statistics. +-# **Output results** + @code{.cpp} + Mat res; + drawMatches(img1, inliers1, img2, inliers2, good_matches, res); + imwrite("res.png", res); + ... + @endcode + Here we save the resulting image and print some statistics. ### Results Found matches ------------- -![image](images/res.png) +![](images/res.png) A-KAZE Matching Results ----------------------- diff --git a/doc/tutorials/features2d/akaze_matching/akaze_matching.rst b/doc/tutorials/features2d/akaze_matching/akaze_matching.rst index 729f1f1f5e..4007d653da 100644 --- a/doc/tutorials/features2d/akaze_matching/akaze_matching.rst +++ b/doc/tutorials/features2d/akaze_matching/akaze_matching.rst @@ -152,8 +152,9 @@ A-KAZE Matching Results -------------------------- .. code-block:: none - Keypoints 1: 2943 - Keypoints 2: 3511 - Matches: 447 - Inliers: 308 - Inlier Ratio: 0.689038 + + Keypoints 1 2943 + Keypoints 2 3511 + Matches 447 + Inliers 308 + Inlier Ratio 0.689038 diff --git a/doc/tutorials/features2d/akaze_tracking/akaze_tracking.markdown b/doc/tutorials/features2d/akaze_tracking/akaze_tracking.markdown index e37b005429..a93a5f2366 100644 --- a/doc/tutorials/features2d/akaze_tracking/akaze_tracking.markdown +++ b/doc/tutorials/features2d/akaze_tracking/akaze_tracking.markdown @@ -11,16 +11,17 @@ The algorithm is as follows: - Detect and describe keypoints on the first frame, manually set object boundaries - For every next frame: - 1. Detect and describe keypoints - 2. Match them using bruteforce matcher - 3. Estimate homography transformation using RANSAC - 4. Filter inliers from all the matches - 5. Apply homography transformation to the bounding box to find the object - 6. Draw bounding box and inliers, compute inlier ratio as evaluation metric + -# Detect and describe keypoints + -# Match them using bruteforce matcher + -# Estimate homography transformation using RANSAC + -# Filter inliers from all the matches + -# Apply homography transformation to the bounding box to find the object + -# Draw bounding box and inliers, compute inlier ratio as evaluation metric -![image](images/frame.png) +![](images/frame.png) -### Data +Data +---- To do the tracking we need a video and object position on the first frame. @@ -31,14 +32,16 @@ To run the code you have to specify input and output video path and object bound @code{.none} ./planar_tracking blais.mp4 result.avi blais_bb.xml.gz @endcode -### Source Code + +Source Code +----------- @includelineno cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp -### Explanation +Explanation +----------- -Tracker class -------------- +### Tracker class This class implements algorithm described abobve using given feature detector and descriptor matcher. @@ -63,62 +66,60 @@ matcher. - **Processing frames** - 1. Locate keypoints and compute descriptors - @code{.cpp} - (*detector)(frame, noArray(), kp, desc); - @endcode - - To find matches between frames we have to locate the keypoints first. - - In this tutorial detectors are set up to find about 1000 keypoints on each frame. + -# Locate keypoints and compute descriptors + @code{.cpp} + (*detector)(frame, noArray(), kp, desc); + @endcode - 1. Use 2-nn matcher to find correspondences - @code{.cpp} - matcher->knnMatch(first_desc, desc, matches, 2); - for(unsigned i = 0; i < matches.size(); i++) { - if(matches[i][0].distance < nn_match_ratio * matches[i][1].distance) { - matched1.push_back(first_kp[matches[i][0].queryIdx]); - matched2.push_back( kp[matches[i][0].trainIdx]); - } - } - @endcode - - If the closest match is *nn_match_ratio* closer than the second closest one, then it's a - match. + To find matches between frames we have to locate the keypoints first. - 2. Use *RANSAC* to estimate homography transformation - @code{.cpp} - homography = findHomography(Points(matched1), Points(matched2), - RANSAC, ransac_thresh, inlier_mask); - @endcode - - If there are at least 4 matches we can use random sample consensus to estimate image - transformation. + In this tutorial detectors are set up to find about 1000 keypoints on each frame. - 3. Save the inliers - @code{.cpp} - for(unsigned i = 0; i < matched1.size(); i++) { - if(inlier_mask.at(i)) { - int new_i = static_cast(inliers1.size()); - inliers1.push_back(matched1[i]); - inliers2.push_back(matched2[i]); - inlier_matches.push_back(DMatch(new_i, new_i, 0)); + -# Use 2-nn matcher to find correspondences + @code{.cpp} + matcher->knnMatch(first_desc, desc, matches, 2); + for(unsigned i = 0; i < matches.size(); i++) { + if(matches[i][0].distance < nn_match_ratio * matches[i][1].distance) { + matched1.push_back(first_kp[matches[i][0].queryIdx]); + matched2.push_back( kp[matches[i][0].trainIdx]); + } } - } - @endcode - - Since *findHomography* computes the inliers we only have to save the chosen points and - matches. + @endcode + If the closest match is *nn_match_ratio* closer than the second closest one, then it's a + match. + + -# Use *RANSAC* to estimate homography transformation + @code{.cpp} + homography = findHomography(Points(matched1), Points(matched2), + RANSAC, ransac_thresh, inlier_mask); + @endcode + If there are at least 4 matches we can use random sample consensus to estimate image + transformation. + + -# Save the inliers + @code{.cpp} + for(unsigned i = 0; i < matched1.size(); i++) { + if(inlier_mask.at(i)) { + int new_i = static_cast(inliers1.size()); + inliers1.push_back(matched1[i]); + inliers2.push_back(matched2[i]); + inlier_matches.push_back(DMatch(new_i, new_i, 0)); + } + } + @endcode + Since *findHomography* computes the inliers we only have to save the chosen points and + matches. - 4. Project object bounding box - @code{.cpp} - perspectiveTransform(object_bb, new_bb, homography); - @endcode - - If there is a reasonable number of inliers we can use estimated transformation to locate the - object. + -# Project object bounding box + @code{.cpp} + perspectiveTransform(object_bb, new_bb, homography); + @endcode -### Results + If there is a reasonable number of inliers we can use estimated transformation to locate the + object. + +Results +------- You can watch the resulting [video on youtube](http://www.youtube.com/watch?v=LWY-w8AGGhE). @@ -129,6 +130,7 @@ Inliers 410 Inlier ratio 0.58 Keypoints 1117 @endcode + *ORB* statistics: @code{.none} Matches 504 diff --git a/doc/tutorials/features2d/feature_description/feature_description.markdown b/doc/tutorials/features2d/feature_description/feature_description.markdown index 91f9e930a2..9a71b131ba 100644 --- a/doc/tutorials/features2d/feature_description/feature_description.markdown +++ b/doc/tutorials/features2d/feature_description/feature_description.markdown @@ -87,4 +87,4 @@ Result Here is the result after applying the BruteForce matcher between the two original images: -![image](images/Feature_Description_BruteForce_Result.jpg) +![](images/Feature_Description_BruteForce_Result.jpg) diff --git a/doc/tutorials/features2d/feature_detection/feature_detection.markdown b/doc/tutorials/features2d/feature_detection/feature_detection.markdown index 5e3997daad..09e7d6f304 100644 --- a/doc/tutorials/features2d/feature_detection/feature_detection.markdown +++ b/doc/tutorials/features2d/feature_detection/feature_detection.markdown @@ -79,10 +79,10 @@ Explanation Result ------ -1. Here is the result of the feature detection applied to the first image: +-# Here is the result of the feature detection applied to the first image: - ![image](images/Feature_Detection_Result_a.jpg) + ![](images/Feature_Detection_Result_a.jpg) -2. And here is the result for the second image: +-# And here is the result for the second image: - ![image](images/Feature_Detection_Result_b.jpg) + ![](images/Feature_Detection_Result_b.jpg) diff --git a/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.markdown b/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.markdown index 70e97c66ac..0e983d925d 100644 --- a/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.markdown +++ b/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.markdown @@ -130,10 +130,10 @@ Explanation Result ------ -1. Here is the result of the feature detection applied to the first image: +-# Here is the result of the feature detection applied to the first image: - ![image](images/Featur_FlannMatcher_Result.jpg) + ![](images/Featur_FlannMatcher_Result.jpg) -2. Additionally, we get as console output the keypoints filtered: +-# Additionally, we get as console output the keypoints filtered: - ![image](images/Feature_FlannMatcher_Keypoints_Result.jpg) + ![](images/Feature_FlannMatcher_Keypoints_Result.jpg) diff --git a/doc/tutorials/features2d/feature_homography/feature_homography.markdown b/doc/tutorials/features2d/feature_homography/feature_homography.markdown index d679ebcfb0..5eacdf35ea 100644 --- a/doc/tutorials/features2d/feature_homography/feature_homography.markdown +++ b/doc/tutorials/features2d/feature_homography/feature_homography.markdown @@ -134,8 +134,8 @@ Explanation Result ------ -1. And here is the result for the detected object (highlighted in green) +-# And here is the result for the detected object (highlighted in green) - ![image](images/Feature_Homography_Result.jpg) + ![](images/Feature_Homography_Result.jpg) diff --git a/doc/tutorials/features2d/trackingmotion/corner_subpixeles/corner_subpixeles.markdown b/doc/tutorials/features2d/trackingmotion/corner_subpixeles/corner_subpixeles.markdown index 3ed8971bc1..70323efd41 100644 --- a/doc/tutorials/features2d/trackingmotion/corner_subpixeles/corner_subpixeles.markdown +++ b/doc/tutorials/features2d/trackingmotion/corner_subpixeles/corner_subpixeles.markdown @@ -122,9 +122,9 @@ Explanation Result ------ -![image](images/Corner_Subpixeles_Original_Image.jpg) +![](images/Corner_Subpixeles_Original_Image.jpg) Here is the result: -![image](images/Corner_Subpixeles_Result.jpg) +![](images/Corner_Subpixeles_Result.jpg) diff --git a/doc/tutorials/features2d/trackingmotion/generic_corner_detector/generic_corner_detector.markdown b/doc/tutorials/features2d/trackingmotion/generic_corner_detector/generic_corner_detector.markdown index d1b66e8b9f..b64bc49f0d 100644 --- a/doc/tutorials/features2d/trackingmotion/generic_corner_detector/generic_corner_detector.markdown +++ b/doc/tutorials/features2d/trackingmotion/generic_corner_detector/generic_corner_detector.markdown @@ -30,7 +30,7 @@ Explanation Result ------ -![image](images/My_Harris_corner_detector_Result.jpg) +![](images/My_Harris_corner_detector_Result.jpg) -![image](images/My_Shi_Tomasi_corner_detector_Result.jpg) +![](images/My_Shi_Tomasi_corner_detector_Result.jpg) diff --git a/doc/tutorials/features2d/trackingmotion/good_features_to_track/good_features_to_track.markdown b/doc/tutorials/features2d/trackingmotion/good_features_to_track/good_features_to_track.markdown index 26c4d452ed..80c96ffb6b 100644 --- a/doc/tutorials/features2d/trackingmotion/good_features_to_track/good_features_to_track.markdown +++ b/doc/tutorials/features2d/trackingmotion/good_features_to_track/good_features_to_track.markdown @@ -111,5 +111,5 @@ Explanation Result ------ -![image](images/Feature_Detection_Result_a.jpg) +![](images/Feature_Detection_Result_a.jpg) diff --git a/doc/tutorials/features2d/trackingmotion/harris_detector/harris_detector.markdown b/doc/tutorials/features2d/trackingmotion/harris_detector/harris_detector.markdown index d36ed0da45..fc89519f80 100644 --- a/doc/tutorials/features2d/trackingmotion/harris_detector/harris_detector.markdown +++ b/doc/tutorials/features2d/trackingmotion/harris_detector/harris_detector.markdown @@ -201,9 +201,9 @@ Result The original image: -![image](images/Harris_Detector_Original_Image.jpg) +![](images/Harris_Detector_Original_Image.jpg) The detected corners are surrounded by a small black circle -![image](images/Harris_Detector_Result.jpg) +![](images/Harris_Detector_Result.jpg) diff --git a/doc/tutorials/general/table_of_content_general/table_of_content_general.markdown b/doc/tutorials/general/table_of_content_general/table_of_content_general.markdown deleted file mode 100644 index fbdfcf1600..0000000000 --- a/doc/tutorials/general/table_of_content_general/table_of_content_general.markdown +++ /dev/null @@ -1,8 +0,0 @@ -General tutorials {#tutorial_table_of_content_general} -================= - -These tutorials are the bottom of the iceberg as they link together multiple of the modules -presented above in order to solve complex problems. - - - diff --git a/doc/tutorials/gpu/gpu-basics-similarity/gpu_basics_similarity.markdown b/doc/tutorials/gpu/gpu-basics-similarity/gpu_basics_similarity.markdown index 3da7699628..e24fe03598 100644 --- a/doc/tutorials/gpu/gpu-basics-similarity/gpu_basics_similarity.markdown +++ b/doc/tutorials/gpu/gpu-basics-similarity/gpu_basics_similarity.markdown @@ -24,28 +24,45 @@ The source code You may also find the source code and these video file in the `samples/cpp/tutorial_code/gpu/gpu-basics-similarity/gpu-basics-similarity` folder of the OpenCV -source library or download it from here -\<../../../../samples/cpp/tutorial_code/gpu/gpu-basics-similarity/gpu-basics-similarity.cpp\>. The -full source code is quite long (due to the controlling of the application via the command line +source library or download it from [here](samples/cpp/tutorial_code/gpu/gpu-basics-similarity/gpu-basics-similarity.cpp). +The full source code is quite long (due to the controlling of the application via the command line arguments and performance measurement). Therefore, to avoid cluttering up these sections with those you'll find here only the functions itself. The PSNR returns a float number, that if the two inputs are similar between 30 and 50 (higher is better). -@includelineno samples/cpp/tutorial_code/gpu/gpu-basics-similarity/gpu-basics-similarity.cpp +@dontinclude samples/cpp/tutorial_code/gpu/gpu-basics-similarity/gpu-basics-similarity.cpp -lines - 165-210, 18-23, 210-235 +@skip struct BufferPSNR +@until }; + +@skip double getPSNR( +@until return psnr; +@until } +@until } + +@skip double getPSNR_CUDA( +@until return psnr; +@until } +@until } The SSIM returns the MSSIM of the images. This is too a float number between zero and one (higher is better), however we have one for each channel. Therefore, we return a *Scalar* OpenCV data structure: -@includelineno samples/cpp/tutorial_code/gpu/gpu-basics-similarity/gpu-basics-similarity.cpp +@dontinclude samples/cpp/tutorial_code/gpu/gpu-basics-similarity/gpu-basics-similarity.cpp + +@skip struct BufferMSSIM +@until }; -lines - 235-355, 26-42, 357- +@skip Scalar getMSSIM( +@until return mssim; +@until } + +@skip Scalar getMSSIM_CUDA_optimized( +@until return mssim; +@until } How to do it? - The GPU ----------------------- @@ -124,7 +141,7 @@ The reason for this is that you're throwing out on the window the price for memo data transfer. And on the GPU this is damn high. Another possibility for optimization is to introduce asynchronous OpenCV GPU calls too with the help of the @ref cv::cuda::Stream. -1. Memory allocation on the GPU is considerable. Therefore, if it’s possible allocate new memory as +-# Memory allocation on the GPU is considerable. Therefore, if it’s possible allocate new memory as few times as possible. If you create a function what you intend to call multiple times it is a good idea to allocate any local parameters for the function only once, during the first call. To do this you create a data structure containing all the local variables you will use. For @@ -148,7 +165,7 @@ introduce asynchronous OpenCV GPU calls too with the help of the @ref cv::cuda:: Now you access these local parameters as: *b.gI1*, *b.buf* and so on. The GpuMat will only reallocate itself on a new call if the new matrix size is different from the previous one. -2. Avoid unnecessary function data transfers. Any small data transfer will be significant one once +-# Avoid unnecessary function data transfers. Any small data transfer will be significant one once you go to the GPU. Therefore, if possible make all calculations in-place (in other words do not create new memory objects - for reasons explained at the previous point). For example, although expressing arithmetical operations may be easier to express in one line formulas, it will be @@ -164,7 +181,7 @@ introduce asynchronous OpenCV GPU calls too with the help of the @ref cv::cuda:: gpu::multiply(b.mu1_mu2, 2, b.t1); //b.t1 = 2 * b.mu1_mu2 + C1; gpu::add(b.t1, C1, b.t1); @endcode -3. Use asynchronous calls (the @ref cv::cuda::Stream ). By default whenever you call a gpu function +-# Use asynchronous calls (the @ref cv::cuda::Stream ). By default whenever you call a gpu function it will wait for the call to finish and return with the result afterwards. However, it is possible to make asynchronous calls, meaning it will call for the operation execution, make the costly data allocations for the algorithm and return back right away. Now you can call another @@ -189,7 +206,7 @@ Result and conclusion --------------------- On an Intel P8700 laptop CPU paired with a low end NVidia GT220M here are the performance numbers: -@code{.cpp} +@code Time of PSNR CPU (averaged for 10 runs): 41.4122 milliseconds. With result of: 19.2506 Time of PSNR GPU (averaged for 10 runs): 158.977 milliseconds. With result of: 19.2506 Initial call GPU optimized: 31.3418 milliseconds. With result of: 19.2506 diff --git a/doc/tutorials/highgui/raster-gdal/images/flood-zone.jpg b/doc/tutorials/highgui/raster-gdal/images/gdal_flood-zone.jpg similarity index 100% rename from doc/tutorials/highgui/raster-gdal/images/flood-zone.jpg rename to doc/tutorials/highgui/raster-gdal/images/gdal_flood-zone.jpg diff --git a/doc/tutorials/highgui/raster-gdal/images/heat-map.jpg b/doc/tutorials/highgui/raster-gdal/images/gdal_heat-map.jpg similarity index 100% rename from doc/tutorials/highgui/raster-gdal/images/heat-map.jpg rename to doc/tutorials/highgui/raster-gdal/images/gdal_heat-map.jpg diff --git a/doc/tutorials/highgui/raster-gdal/images/output.jpg b/doc/tutorials/highgui/raster-gdal/images/gdal_output.jpg similarity index 100% rename from doc/tutorials/highgui/raster-gdal/images/output.jpg rename to doc/tutorials/highgui/raster-gdal/images/gdal_output.jpg diff --git a/doc/tutorials/highgui/raster-gdal/raster_io_gdal.markdown b/doc/tutorials/highgui/raster-gdal/raster_io_gdal.markdown index 7291e0c9d9..a60c754551 100644 --- a/doc/tutorials/highgui/raster-gdal/raster_io_gdal.markdown +++ b/doc/tutorials/highgui/raster-gdal/raster_io_gdal.markdown @@ -94,9 +94,8 @@ Below is the output of the program. Use the first image as the input. For the DE the SRTM file located at the USGS here. [](http://dds.cr.usgs.gov/srtm/version2_1/SRTM1/Region_04/N37W123.hgt.zip) -![image](images/output.jpg) +![](images/gdal_output.jpg) -![image](images/heat-map.jpg) - -![image](images/flood-zone.jpg) +![](images/gdal_heat-map.jpg) +![](images/gdal_flood-zone.jpg) diff --git a/doc/tutorials/highgui/raster-gdal/raster_io_gdal.rst b/doc/tutorials/highgui/raster-gdal/raster_io_gdal.rst index d896ef5d79..91932a35bb 100644 --- a/doc/tutorials/highgui/raster-gdal/raster_io_gdal.rst +++ b/doc/tutorials/highgui/raster-gdal/raster_io_gdal.rst @@ -106,8 +106,8 @@ Results Below is the output of the program. Use the first image as the input. For the DEM model, download the SRTM file located at the USGS here. `http://dds.cr.usgs.gov/srtm/version2_1/SRTM1/Region_04/N37W123.hgt.zip `_ -.. image:: images/output.jpg +.. image:: images/gdal_output.jpg -.. image:: images/heat-map.jpg +.. image:: images/gdal_heat-map.jpg -.. image:: images/flood-zone.jpg +.. image:: images/gdal_flood-zone.jpg diff --git a/doc/tutorials/highgui/trackbar/trackbar.markdown b/doc/tutorials/highgui/trackbar/trackbar.markdown index 5181fa4a66..50c13fa4af 100644 --- a/doc/tutorials/highgui/trackbar/trackbar.markdown +++ b/doc/tutorials/highgui/trackbar/trackbar.markdown @@ -7,7 +7,7 @@ Adding a Trackbar to our applications! {#tutorial_trackbar} - Well, it is time to use some fancy GUI tools. OpenCV provides some GUI utilities (*highgui.h*) for you. An example of this is a **Trackbar** - ![image](images/Adding_Trackbars_Tutorial_Trackbar.png) + ![](images/Adding_Trackbars_Tutorial_Trackbar.png) - In this tutorial we will just modify our two previous programs so that they get the input information from the trackbar. @@ -88,16 +88,16 @@ Explanation We only analyze the code that is related to Trackbar: -1. First, we load 02 images, which are going to be blended. +-# First, we load 02 images, which are going to be blended. @code{.cpp} src1 = imread("../../images/LinuxLogo.jpg"); src2 = imread("../../images/WindowsLogo.jpg"); @endcode -2. To create a trackbar, first we have to create the window in which it is going to be located. So: +-# To create a trackbar, first we have to create the window in which it is going to be located. So: @code{.cpp} namedWindow("Linear Blend", 1); @endcode -3. Now we can create the Trackbar: +-# Now we can create the Trackbar: @code{.cpp} createTrackbar( TrackbarName, "Linear Blend", &alpha_slider, alpha_slider_max, on_trackbar ); @endcode @@ -110,7 +110,7 @@ We only analyze the code that is related to Trackbar: - The numerical value of Trackbar is stored in **alpha_slider** - Whenever the user moves the Trackbar, the callback function **on_trackbar** is called -4. Finally, we have to define the callback function **on_trackbar** +-# Finally, we have to define the callback function **on_trackbar** @code{.cpp} void on_trackbar( int, void* ) { @@ -133,10 +133,10 @@ Result - Our program produces the following output: - ![image](images/Adding_Trackbars_Tutorial_Result_0.jpg) + ![](images/Adding_Trackbars_Tutorial_Result_0.jpg) - As a manner of practice, you can also add 02 trackbars for the program made in @ref tutorial_basic_linear_transform. One trackbar to set \f$\alpha\f$ and another for \f$\beta\f$. The output might look like: - ![image](images/Adding_Trackbars_Tutorial_Result_1.jpg) + ![](images/Adding_Trackbars_Tutorial_Result_1.jpg) diff --git a/doc/tutorials/highgui/video-input-psnr-ssim/video_input_psnr_ssim.markdown b/doc/tutorials/highgui/video-input-psnr-ssim/video_input_psnr_ssim.markdown index 052237218e..6d470a9728 100644 --- a/doc/tutorials/highgui/video-input-psnr-ssim/video_input_psnr_ssim.markdown +++ b/doc/tutorials/highgui/video-input-psnr-ssim/video_input_psnr_ssim.markdown @@ -25,10 +25,14 @@ version of it ](samples/cpp/tutorial_code/HighGUI/video-input-psnr-ssim/video/Me You may also find the source code and these video file in the `samples/cpp/tutorial_code/HighGUI/video-input-psnr-ssim/` folder of the OpenCV source library. -@includelineno cpp/tutorial_code/HighGUI/video-input-psnr-ssim/video-input-psnr-ssim.cpp +@dontinclude cpp/tutorial_code/HighGUI/video-input-psnr-ssim/video-input-psnr-ssim.cpp -lines - 1-15, 29-31, 33-208 +@until Scalar getMSSIM +@skip main +@until { +@skip if +@until return mssim; +@until } How to read a video stream (online-camera or offline-file)? ----------------------------------------------------------- @@ -243,10 +247,9 @@ for each frame, and the SSIM only for the frames where the PSNR falls below an i visualization purpose we show both images in an OpenCV window and print the PSNR and MSSIM values to the console. Expect to see something like: -![image](images/outputVideoInput.png) +![](images/outputVideoInput.png) -You may observe a runtime instance of this on the [YouTube -here](https://www.youtube.com/watch?v=iOcNljutOgg). +You may observe a runtime instance of this on the [YouTube here](https://www.youtube.com/watch?v=iOcNljutOgg). \htmlonly
diff --git a/doc/tutorials/highgui/video-write/video_write.markdown b/doc/tutorials/highgui/video-write/video_write.markdown index 05745518f2..1c86e3771b 100644 --- a/doc/tutorials/highgui/video-write/video_write.markdown +++ b/doc/tutorials/highgui/video-write/video_write.markdown @@ -47,7 +47,7 @@ somehow longer and includes names such as *XVID*, *DIVX*, *H264* or *LAGS* (*Lag Codec*). The full list of codecs you may use on a system depends on just what one you have installed. -![image](images/videoFileStructure.png) +![](images/videoFileStructure.png) As you can see things can get really complicated with videos. However, OpenCV is mainly a computer vision library, not a video stream, codec and write one. Therefore, the developers tried to keep @@ -75,7 +75,7 @@ const string source = argv[1]; // the source file name string::size_type pAt = source.find_last_of('.'); // Find extension point const string NAME = source.substr(0, pAt) + argv[2][0] + ".avi"; // Form the new name with container @endcode -1. The codec to use for the video track. Now all the video codecs have a unique short name of +-# The codec to use for the video track. Now all the video codecs have a unique short name of maximum four characters. Hence, the *XVID*, *DIVX* or *H264* names. This is called a four character code. You may also ask this from an input video by using its *get* function. Because the *get* function is a general function it always returns double values. A double value is @@ -109,13 +109,13 @@ const string NAME = source.substr(0, pAt) + argv[2][0] + ".avi"; // Form the n If you pass for this argument minus one than a window will pop up at runtime that contains all the codec installed on your system and ask you to select the one to use: - ![image](images/videoCompressSelect.png) + ![](images/videoCompressSelect.png) -2. The frame per second for the output video. Again, here I keep the input videos frame per second +-# The frame per second for the output video. Again, here I keep the input videos frame per second by using the *get* function. -3. The size of the frames for the output video. Here too I keep the input videos frame size per +-# The size of the frames for the output video. Here too I keep the input videos frame size per second by using the *get* function. -4. The final argument is an optional one. By default is true and says that the output will be a +-# The final argument is an optional one. By default is true and says that the output will be a colorful one (so for write you will send three channel images). To create a gray scale video pass a false parameter here. @@ -148,7 +148,7 @@ merge(spl, res); Put all this together and you'll get the upper source code, whose runtime result will show something around the idea: -![image](images/resultOutputWideoWrite.png) +![](images/resultOutputWideoWrite.png) You may observe a runtime instance of this on the [YouTube here](https://www.youtube.com/watch?v=jpBwHxsl1_0). diff --git a/doc/tutorials/imgproc/erosion_dilatation/erosion_dilatation.markdown b/doc/tutorials/imgproc/erosion_dilatation/erosion_dilatation.markdown index d1b64dc21d..af54c0321b 100644 --- a/doc/tutorials/imgproc/erosion_dilatation/erosion_dilatation.markdown +++ b/doc/tutorials/imgproc/erosion_dilatation/erosion_dilatation.markdown @@ -28,7 +28,7 @@ Morphological Operations - Finding of intensity bumps or holes in an image - We will explain dilation and erosion briefly, using the following image as an example: - ![image](images/Morphology_1_Tutorial_Theory_Original_Image.png) + ![](images/Morphology_1_Tutorial_Theory_Original_Image.png) ### Dilation @@ -40,7 +40,7 @@ Morphological Operations deduce, this maximizing operation causes bright regions within an image to "grow" (therefore the name *dilation*). Take as an example the image above. Applying dilation we can get: - ![image](images/Morphology_1_Tutorial_Theory_Dilation.png) + ![](images/Morphology_1_Tutorial_Theory_Dilation.png) The background (bright) dilates around the black regions of the letter. @@ -54,7 +54,7 @@ The background (bright) dilates around the black regions of the letter. (shown above). You can see in the result below that the bright areas of the image (the background, apparently), get thinner, whereas the dark zones (the "writing") gets bigger. - ![image](images/Morphology_1_Tutorial_Theory_Erosion.png) + ![](images/Morphology_1_Tutorial_Theory_Erosion.png) Code ---- @@ -66,7 +66,7 @@ This tutorial code's is shown lines below. You can also download it from Explanation ----------- -1. Most of the stuff shown is known by you (if you have any doubt, please refer to the tutorials in +-# Most of the stuff shown is known by you (if you have any doubt, please refer to the tutorials in previous sections). Let's check the general structure of the program: - Load an image (can be RGB or grayscale) @@ -80,7 +80,7 @@ Explanation Let's analyze these two functions: -2. **erosion:** +-# **erosion:** @code{.cpp} /* @function Erosion */ void Erosion( int, void* ) @@ -124,7 +124,7 @@ Explanation (iterations) at once. We are not using it in this simple tutorial, though. You can check out the Reference for more details. -3. **dilation:** +-# **dilation:** The code is below. As you can see, it is completely similar to the snippet of code for **erosion**. Here we also have the option of defining our kernel, its anchor point and the size of the operator @@ -152,10 +152,10 @@ Results Compile the code above and execute it with an image as argument. For instance, using this image: -![image](images/Morphology_1_Tutorial_Original_Image.jpg) +![](images/Morphology_1_Tutorial_Original_Image.jpg) We get the results below. Varying the indices in the Trackbars give different output images, naturally. Try them out! You can even try to add a third Trackbar to control the number of iterations. -![image](images/Morphology_1_Result.jpg) +![](images/Morphology_1_Result.jpg) diff --git a/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.markdown b/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.markdown index 2e65daad1b..43753ca6e1 100644 --- a/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.markdown +++ b/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.markdown @@ -56,17 +56,15 @@ enumeratevisibleitemswithsquare produce the output array. - Just to make the picture clearer, remember how a 1D Gaussian kernel look like? - ![image](images/Smoothing_Tutorial_theory_gaussian_0.jpg) + ![](images/Smoothing_Tutorial_theory_gaussian_0.jpg) Assuming that an image is 1D, you can notice that the pixel located in the middle would have the biggest weight. The weight of its neighbors decreases as the spatial distance between them and the center pixel increases. -@note - Remember that a 2D Gaussian can be represented as : - + @note + Remember that a 2D Gaussian can be represented as : \f[G_{0}(x, y) = A e^{ \dfrac{ -(x - \mu_{x})^{2} }{ 2\sigma^{2}_{x} } + \dfrac{ -(y - \mu_{y})^{2} }{ 2\sigma^{2}_{y} } }\f] - where \f$\mu\f$ is the mean (the peak) and \f$\sigma\f$ represents the variance (per each of the variables \f$x\f$ and \f$y\f$) @@ -188,12 +186,13 @@ int display_dst( int delay ); return 0; } @endcode + Explanation ----------- -1. Let's check the OpenCV functions that involve only the smoothing procedure, since the rest is +-# Let's check the OpenCV functions that involve only the smoothing procedure, since the rest is already known by now. -2. **Normalized Block Filter:** +-# **Normalized Block Filter:** OpenCV offers the function @ref cv::blur to perform smoothing with this filter. @code{.cpp} @@ -211,7 +210,7 @@ Explanation respect to the neighborhood. If there is a negative value, then the center of the kernel is considered the anchor point. -3. **Gaussian Filter:** +-# **Gaussian Filter:** It is performed by the function @ref cv::GaussianBlur : @code{.cpp} @@ -231,7 +230,7 @@ Explanation - \f$\sigma_{y}\f$: The standard deviation in y. Writing \f$0\f$ implies that \f$\sigma_{y}\f$ is calculated using kernel size. -4. **Median Filter:** +-# **Median Filter:** This filter is provided by the @ref cv::medianBlur function: @code{.cpp} @@ -245,7 +244,7 @@ Explanation - *dst*: Destination image, must be the same type as *src* - *i*: Size of the kernel (only one because we use a square window). Must be odd. -5. **Bilateral Filter** +-# **Bilateral Filter** Provided by OpenCV function @ref cv::bilateralFilter @code{.cpp} @@ -268,6 +267,4 @@ Results filters explained. - Here is a snapshot of the image smoothed using *medianBlur*: - ![image](images/Smoothing_Tutorial_Result_Median_Filter.jpg) - - + ![](images/Smoothing_Tutorial_Result_Median_Filter.jpg) diff --git a/doc/tutorials/imgproc/histograms/back_projection/back_projection.markdown b/doc/tutorials/imgproc/histograms/back_projection/back_projection.markdown index 611458a4fc..474bd4ad34 100644 --- a/doc/tutorials/imgproc/histograms/back_projection/back_projection.markdown +++ b/doc/tutorials/imgproc/histograms/back_projection/back_projection.markdown @@ -28,17 +28,14 @@ Theory - Let's say you have gotten a skin histogram (Hue-Saturation) based on the image below. The histogram besides is going to be our *model histogram* (which we know represents a sample of skin tonality). You applied some mask to capture only the histogram of the skin area: - - ------ ------ - |T0| |T1| - ------ ------ + ![T0](images/Back_Projection_Theory0.jpg) + ![T1](images/Back_Projection_Theory1.jpg) - Now, let's imagine that you get another hand image (Test Image) like the one below: (with its respective histogram): + ![T2](images/Back_Projection_Theory2.jpg) + ![T3](images/Back_Projection_Theory3.jpg) - ------ ------ - |T2| |T3| - ------ ------ - What we want to do is to use our *model histogram* (that we know represents a skin tonality) to detect skin areas in our Test Image. Here are the steps @@ -50,7 +47,7 @@ Theory the *model histogram* first, so the output for the Test Image can be visible for you. -# Applying the steps above, we get the following BackProjection image for our Test Image: - ![image](images/Back_Projection_Theory4.jpg) + ![](images/Back_Projection_Theory4.jpg) -# In terms of statistics, the values stored in *BackProjection* represent the *probability* that a pixel in *Test Image* belongs to a skin area, based on the *model histogram* that we @@ -83,98 +80,23 @@ Code in samples. - **Code at glance:** -@code{.cpp} -#include "opencv2/imgproc.hpp" -#include "opencv2/highgui.hpp" - -#include - -using namespace cv; -using namespace std; - -/// Global Variables -Mat src; Mat hsv; Mat hue; -int bins = 25; - -/// Function Headers -void Hist_and_Backproj(int, void* ); - -/* @function main */ -int main( int argc, char** argv ) -{ - /// Read the image - src = imread( argv[1], 1 ); - /// Transform it to HSV - cvtColor( src, hsv, COLOR_BGR2HSV ); - - /// Use only the Hue value - hue.create( hsv.size(), hsv.depth() ); - int ch[] = { 0, 0 }; - mixChannels( &hsv, 1, &hue, 1, ch, 1 ); - - /// Create Trackbar to enter the number of bins - char* window_image = "Source image"; - namedWindow( window_image, WINDOW_AUTOSIZE ); - createTrackbar("* Hue bins: ", window_image, &bins, 180, Hist_and_Backproj ); - Hist_and_Backproj(0, 0); - - /// Show the image - imshow( window_image, src ); - - /// Wait until user exits the program - waitKey(0); - return 0; -} +@includelineno samples/cpp/tutorial_code/Histograms_Matching/calcBackProject_Demo1.cpp - -/* - * @function Hist_and_Backproj - * @brief Callback to Trackbar - */ -void Hist_and_Backproj(int, void* ) -{ - MatND hist; - int histSize = MAX( bins, 2 ); - float hue_range[] = { 0, 180 }; - const float* ranges = { hue_range }; - - /// Get the Histogram and normalize it - calcHist( &hue, 1, 0, Mat(), hist, 1, &histSize, &ranges, true, false ); - normalize( hist, hist, 0, 255, NORM_MINMAX, -1, Mat() ); - - /// Get Backprojection - MatND backproj; - calcBackProject( &hue, 1, 0, hist, backproj, &ranges, 1, true ); - - /// Draw the backproj - imshow( "BackProj", backproj ); - - /// Draw the histogram - int w = 400; int h = 400; - int bin_w = cvRound( (double) w / histSize ); - Mat histImg = Mat::zeros( w, h, CV_8UC3 ); - - for( int i = 0; i < bins; i ++ ) - { rectangle( histImg, Point( i*bin_w, h ), Point( (i+1)*bin_w, h - cvRound( hist.at(i)*h/255.0 ) ), Scalar( 0, 0, 255 ), -1 ); } - - imshow( "Histogram", histImg ); -} -@endcode Explanation ----------- -1. Declare the matrices to store our images and initialize the number of bins to be used by our +-# Declare the matrices to store our images and initialize the number of bins to be used by our histogram: @code{.cpp} Mat src; Mat hsv; Mat hue; int bins = 25; @endcode -2. Read the input image and transform it to HSV format: +-# Read the input image and transform it to HSV format: @code{.cpp} src = imread( argv[1], 1 ); cvtColor( src, hsv, COLOR_BGR2HSV ); @endcode -3. For this tutorial, we will use only the Hue value for our 1-D histogram (check out the fancier +-# For this tutorial, we will use only the Hue value for our 1-D histogram (check out the fancier code in the links above if you want to use the more standard H-S histogram, which yields better results): @code{.cpp} @@ -182,7 +104,7 @@ Explanation int ch[] = { 0, 0 }; mixChannels( &hsv, 1, &hue, 1, ch, 1 ); @endcode - as you see, we use the function :mix_channels:mixChannels to get only the channel 0 (Hue) from + as you see, we use the function @ref cv::mixChannels to get only the channel 0 (Hue) from the hsv image. It gets the following parameters: - **&hsv:** The source array from which the channels will be copied @@ -193,7 +115,7 @@ Explanation case, the Hue(0) channel of &hsv is being copied to the 0 channel of &hue (1-channel) - **1:** Number of index pairs -4. Create a Trackbar for the user to enter the bin values. Any change on the Trackbar means a call +-# Create a Trackbar for the user to enter the bin values. Any change on the Trackbar means a call to the **Hist_and_Backproj** callback function. @code{.cpp} char* window_image = "Source image"; @@ -201,14 +123,14 @@ Explanation createTrackbar("* Hue bins: ", window_image, &bins, 180, Hist_and_Backproj ); Hist_and_Backproj(0, 0); @endcode -5. Show the image and wait for the user to exit the program: +-# Show the image and wait for the user to exit the program: @code{.cpp} imshow( window_image, src ); waitKey(0); return 0; @endcode -6. **Hist_and_Backproj function:** Initialize the arguments needed for @ref cv::calcHist . The +-# **Hist_and_Backproj function:** Initialize the arguments needed for @ref cv::calcHist . The number of bins comes from the Trackbar: @code{.cpp} void Hist_and_Backproj(int, void* ) @@ -218,12 +140,12 @@ Explanation float hue_range[] = { 0, 180 }; const float* ranges = { hue_range }; @endcode -7. Calculate the Histogram and normalize it to the range \f$[0,255]\f$ +-# Calculate the Histogram and normalize it to the range \f$[0,255]\f$ @code{.cpp} calcHist( &hue, 1, 0, Mat(), hist, 1, &histSize, &ranges, true, false ); normalize( hist, hist, 0, 255, NORM_MINMAX, -1, Mat() ); @endcode -8. Get the Backprojection of the same image by calling the function @ref cv::calcBackProject +-# Get the Backprojection of the same image by calling the function @ref cv::calcBackProject @code{.cpp} MatND backproj; calcBackProject( &hue, 1, 0, hist, backproj, &ranges, 1, true ); @@ -231,11 +153,11 @@ Explanation all the arguments are known (the same as used to calculate the histogram), only we add the backproj matrix, which will store the backprojection of the source image (&hue) -9. Display backproj: +-# Display backproj: @code{.cpp} imshow( "BackProj", backproj ); @endcode -10. Draw the 1-D Hue histogram of the image: +-# Draw the 1-D Hue histogram of the image: @code{.cpp} int w = 400; int h = 400; int bin_w = cvRound( (double) w / histSize ); @@ -246,12 +168,12 @@ Explanation imshow( "Histogram", histImg ); @endcode + Results ------- -1. Here are the output by using a sample image ( guess what? Another hand ). You can play with the - bin values and you will observe how it affects the results: - - ------ ------ ------ - |R0| |R1| |R2| - ------ ------ ------ +Here are the output by using a sample image ( guess what? Another hand ). You can play with the +bin values and you will observe how it affects the results: +![R0](images/Back_Projection1_Source_Image.jpg) +![R1](images/Back_Projection1_Histogram.jpg) +![R2](images/Back_Projection1_BackProj.jpg) diff --git a/doc/tutorials/imgproc/histograms/histogram_calculation/histogram_calculation.markdown b/doc/tutorials/imgproc/histograms/histogram_calculation/histogram_calculation.markdown index 591605f4fa..f5f04b2e35 100644 --- a/doc/tutorials/imgproc/histograms/histogram_calculation/histogram_calculation.markdown +++ b/doc/tutorials/imgproc/histograms/histogram_calculation/histogram_calculation.markdown @@ -21,7 +21,7 @@ histogram called *Image histogram*. Now we will considerate it in its more gener - Let's see an example. Imagine that a Matrix contains information of an image (i.e. intensity in the range \f$0-255\f$): - ![image](images/Histogram_Calculation_Theory_Hist0.jpg) + ![](images/Histogram_Calculation_Theory_Hist0.jpg) - What happens if we want to *count* this data in an organized way? Since we know that the *range* of information value for this case is 256 values, we can segment our range in subparts (called @@ -36,7 +36,7 @@ histogram called *Image histogram*. Now we will considerate it in its more gener this to the example above we get the image below ( axis x represents the bins and axis y the number of pixels in each of them). - ![image](images/Histogram_Calculation_Theory_Hist1.jpg) + ![](images/Histogram_Calculation_Theory_Hist1.jpg) - This was just a simple example of how an histogram works and why it is useful. An histogram can keep count not only of color intensities, but of whatever image features that we want to measure @@ -73,18 +73,18 @@ Code Explanation ----------- -1. Create the necessary matrices: +-# Create the necessary matrices: @code{.cpp} Mat src, dst; @endcode -2. Load the source image +-# Load the source image @code{.cpp} src = imread( argv[1], 1 ); if( !src.data ) { return -1; } @endcode -3. Separate the source image in its three R,G and B planes. For this we use the OpenCV function +-# Separate the source image in its three R,G and B planes. For this we use the OpenCV function @ref cv::split : @code{.cpp} vector bgr_planes; @@ -93,7 +93,7 @@ Explanation our input is the image to be divided (this case with three channels) and the output is a vector of Mat ) -4. Now we are ready to start configuring the **histograms** for each plane. Since we are working +-# Now we are ready to start configuring the **histograms** for each plane. Since we are working with the B, G and R planes, we know that our values will range in the interval \f$[0,255]\f$ -# Establish number of bins (5, 10...): @code{.cpp} @@ -137,7 +137,7 @@ Explanation - **uniform** and **accumulate**: The bin sizes are the same and the histogram is cleared at the beginning. -5. Create an image to display the histograms: +-# Create an image to display the histograms: @code{.cpp} // Draw the histograms for R, G and B int hist_w = 512; int hist_h = 400; @@ -145,7 +145,7 @@ Explanation Mat histImage( hist_h, hist_w, CV_8UC3, Scalar( 0,0,0) ); @endcode -6. Notice that before drawing, we first @ref cv::normalize the histogram so its values fall in the +-# Notice that before drawing, we first @ref cv::normalize the histogram so its values fall in the range indicated by the parameters entered: @code{.cpp} /// Normalize the result to [ 0, histImage.rows ] @@ -164,7 +164,7 @@ Explanation - **-1:** Implies that the output normalized array will be the same type as the input - **Mat():** Optional mask -7. Finally, observe that to access the bin (in this case in this 1D-Histogram): +-# Finally, observe that to access the bin (in this case in this 1D-Histogram): @code{.cpp} /// Draw for each channel for( int i = 1; i < histSize; i++ ) @@ -189,7 +189,7 @@ Explanation b_hist.at( i, j ) @endcode -8. Finally we display our histograms and wait for the user to exit: +-# Finally we display our histograms and wait for the user to exit: @code{.cpp} namedWindow("calcHist Demo", WINDOW_AUTOSIZE ); imshow("calcHist Demo", histImage ); @@ -202,10 +202,10 @@ Explanation Result ------ -1. Using as input argument an image like the shown below: +-# Using as input argument an image like the shown below: - ![image](images/Histogram_Calculation_Original_Image.jpg) + ![](images/Histogram_Calculation_Original_Image.jpg) -2. Produces the following histogram: +-# Produces the following histogram: - ![image](images/Histogram_Calculation_Result.jpg) + ![](images/Histogram_Calculation_Result.jpg) diff --git a/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.markdown b/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.markdown index 86652cb852..ec82e095f8 100644 --- a/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.markdown +++ b/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.markdown @@ -18,25 +18,18 @@ Theory - OpenCV implements the function @ref cv::compareHist to perform a comparison. It also offers 4 different metrics to compute the matching: -# **Correlation ( CV_COMP_CORREL )** - \f[d(H_1,H_2) = \frac{\sum_I (H_1(I) - \bar{H_1}) (H_2(I) - \bar{H_2})}{\sqrt{\sum_I(H_1(I) - \bar{H_1})^2 \sum_I(H_2(I) - \bar{H_2})^2}}\f] - where - \f[\bar{H_k} = \frac{1}{N} \sum _J H_k(J)\f] - and \f$N\f$ is the total number of histogram bins. -# **Chi-Square ( CV_COMP_CHISQR )** - \f[d(H_1,H_2) = \sum _I \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)}\f] -# **Intersection ( method=CV_COMP_INTERSECT )** - \f[d(H_1,H_2) = \sum _I \min (H_1(I), H_2(I))\f] -# **Bhattacharyya distance ( CV_COMP_BHATTACHARYYA )** - \f[d(H_1,H_2) = \sqrt{1 - \frac{1}{\sqrt{\bar{H_1} \bar{H_2} N^2}} \sum_I \sqrt{H_1(I) \cdot H_2(I)}}\f] Code @@ -59,7 +52,7 @@ Code Explanation ----------- -1. Declare variables such as the matrices to store the base image and the two other images to +-# Declare variables such as the matrices to store the base image and the two other images to compare ( RGB and HSV ) @code{.cpp} Mat src_base, hsv_base; @@ -67,7 +60,7 @@ Explanation Mat src_test2, hsv_test2; Mat hsv_half_down; @endcode -2. Load the base image (src_base) and the other two test images: +-# Load the base image (src_base) and the other two test images: @code{.cpp} if( argc < 4 ) { printf("** Error. Usage: ./compareHist_Demo \n"); @@ -78,17 +71,17 @@ Explanation src_test1 = imread( argv[2], 1 ); src_test2 = imread( argv[3], 1 ); @endcode -3. Convert them to HSV format: +-# Convert them to HSV format: @code{.cpp} cvtColor( src_base, hsv_base, COLOR_BGR2HSV ); cvtColor( src_test1, hsv_test1, COLOR_BGR2HSV ); cvtColor( src_test2, hsv_test2, COLOR_BGR2HSV ); @endcode -4. Also, create an image of half the base image (in HSV format): +-# Also, create an image of half the base image (in HSV format): @code{.cpp} hsv_half_down = hsv_base( Range( hsv_base.rows/2, hsv_base.rows - 1 ), Range( 0, hsv_base.cols - 1 ) ); @endcode -5. Initialize the arguments to calculate the histograms (bins, ranges and channels H and S ). +-# Initialize the arguments to calculate the histograms (bins, ranges and channels H and S ). @code{.cpp} int h_bins = 50; int s_bins = 60; int histSize[] = { h_bins, s_bins }; @@ -100,14 +93,14 @@ Explanation int channels[] = { 0, 1 }; @endcode -6. Create the MatND objects to store the histograms: +-# Create the MatND objects to store the histograms: @code{.cpp} MatND hist_base; MatND hist_half_down; MatND hist_test1; MatND hist_test2; @endcode -7. Calculate the Histograms for the base image, the 2 test images and the half-down base image: +-# Calculate the Histograms for the base image, the 2 test images and the half-down base image: @code{.cpp} calcHist( &hsv_base, 1, channels, Mat(), hist_base, 2, histSize, ranges, true, false ); normalize( hist_base, hist_base, 0, 1, NORM_MINMAX, -1, Mat() ); @@ -121,7 +114,7 @@ Explanation calcHist( &hsv_test2, 1, channels, Mat(), hist_test2, 2, histSize, ranges, true, false ); normalize( hist_test2, hist_test2, 0, 1, NORM_MINMAX, -1, Mat() ); @endcode -8. Apply sequentially the 4 comparison methods between the histogram of the base image (hist_base) +-# Apply sequentially the 4 comparison methods between the histogram of the base image (hist_base) and the other histograms: @code{.cpp} for( int i = 0; i < 4; i++ ) @@ -134,34 +127,32 @@ Explanation printf( " Method [%d] Perfect, Base-Half, Base-Test(1), Base-Test(2) : %f, %f, %f, %f \n", i, base_base, base_half , base_test1, base_test2 ); } @endcode + Results ------- -1. We use as input the following images: - - ----------- ----------- ----------- - |Base_0| |Test_1| |Test_2| - ----------- ----------- ----------- - +-# We use as input the following images: + ![Base_0](images/Histogram_Comparison_Source_0.jpg) + ![Test_1](images/Histogram_Comparison_Source_1.jpg) + ![Test_2](images/Histogram_Comparison_Source_2.jpg) where the first one is the base (to be compared to the others), the other 2 are the test images. We will also compare the first image with respect to itself and with respect of half the base image. -2. We should expect a perfect match when we compare the base image histogram with itself. Also, +-# We should expect a perfect match when we compare the base image histogram with itself. Also, compared with the histogram of half the base image, it should present a high match since both are from the same source. For the other two test images, we can observe that they have very different lighting conditions, so the matching should not be very good: -3. Here the numeric results: - - *Method* Base - Base Base - Half Base - Test 1 Base - Test 2 - ----------------- ------------- ------------- --------------- --------------- - *Correlation* 1.000000 0.930766 0.182073 0.120447 - *Chi-square* 0.000000 4.940466 21.184536 49.273437 - *Intersection* 24.391548 14.959809 3.889029 5.775088 - *Bhattacharyya* 0.000000 0.222609 0.646576 0.801869 - -For the *Correlation* and *Intersection* methods, the higher the metric, the more accurate the -match. As we can see, the match *base-base* is the highest of all as expected. Also we can observe -that the match *base-half* is the second best match (as we predicted). For the other two metrics, -the less the result, the better the match. We can observe that the matches between the test 1 and -test 2 with respect to the base are worse, which again, was expected. + +-# Here the numeric results: + *Method* | Base - Base | Base - Half | Base - Test 1 | Base - Test 2 + ----------------- | ------------ | ------------ | -------------- | --------------- + *Correlation* | 1.000000 | 0.930766 | 0.182073 | 0.120447 + *Chi-square* | 0.000000 | 4.940466 | 21.184536 | 49.273437 + *Intersection* | 24.391548 | 14.959809 | 3.889029 | 5.775088 + *Bhattacharyya* | 0.000000 | 0.222609 | 0.646576 | 0.801869 + For the *Correlation* and *Intersection* methods, the higher the metric, the more accurate the + match. As we can see, the match *base-base* is the highest of all as expected. Also we can observe + that the match *base-half* is the second best match (as we predicted). For the other two metrics, + the less the result, the better the match. We can observe that the matches between the test 1 and + test 2 with respect to the base are worse, which again, was expected. diff --git a/doc/tutorials/imgproc/histograms/histogram_equalization/histogram_equalization.markdown b/doc/tutorials/imgproc/histograms/histogram_equalization/histogram_equalization.markdown index 16a2e8cae1..d287c7535b 100644 --- a/doc/tutorials/imgproc/histograms/histogram_equalization/histogram_equalization.markdown +++ b/doc/tutorials/imgproc/histograms/histogram_equalization/histogram_equalization.markdown @@ -17,7 +17,7 @@ Theory - It is a graphical representation of the intensity distribution of an image. - It quantifies the number of pixels for each intensity value considered. -![image](images/Histogram_Equalization_Theory_0.jpg) +![](images/Histogram_Equalization_Theory_0.jpg) ### What is Histogram Equalization? @@ -29,7 +29,7 @@ Theory *underpopulated* intensities. After applying the equalization, we get an histogram like the figure in the center. The resulting image is shown in the picture at right. -![image](images/Histogram_Equalization_Theory_1.jpg) +![](images/Histogram_Equalization_Theory_1.jpg) ### How does it work? @@ -46,7 +46,7 @@ Theory is 255 ( or the maximum value for the intensity of the image ). From the example above, the cumulative function is: - ![image](images/Histogram_Equalization_Theory_2.jpg) + ![](images/Histogram_Equalization_Theory_2.jpg) - Finally, we use a simple remapping procedure to obtain the intensity values of the equalized image: @@ -69,14 +69,14 @@ Code Explanation ----------- -1. Declare the source and destination images as well as the windows names: +-# Declare the source and destination images as well as the windows names: @code{.cpp} Mat src, dst; char* source_window = "Source image"; char* equalized_window = "Equalized Image"; @endcode -2. Load the source image: +-# Load the source image: @code{.cpp} src = imread( argv[1], 1 ); @@ -84,18 +84,18 @@ Explanation { cout<<"Usage: ./Histogram_Demo "< -#include - -using namespace std; -using namespace cv; - -/// Global Variables -Mat img; Mat templ; Mat result; -char* image_window = "Source Image"; -char* result_window = "Result window"; - -int match_method; -int max_Trackbar = 5; - -/// Function Headers -void MatchingMethod( int, void* ); - -/* @function main */ -int main( int argc, char** argv ) -{ - /// Load image and template - img = imread( argv[1], 1 ); - templ = imread( argv[2], 1 ); - - /// Create windows - namedWindow( image_window, WINDOW_AUTOSIZE ); - namedWindow( result_window, WINDOW_AUTOSIZE ); - - /// Create Trackbar - char* trackbar_label = "Method: \n 0: SQDIFF \n 1: SQDIFF NORMED \n 2: TM CCORR \n 3: TM CCORR NORMED \n 4: TM COEFF \n 5: TM COEFF NORMED"; - createTrackbar( trackbar_label, image_window, &match_method, max_Trackbar, MatchingMethod ); - - MatchingMethod( 0, 0 ); - - waitKey(0); - return 0; -} - -/* - * @function MatchingMethod - * @brief Trackbar callback - */ -void MatchingMethod( int, void* ) -{ - /// Source image to display - Mat img_display; - img.copyTo( img_display ); - - /// Create the result matrix - int result_cols = img.cols - templ.cols + 1; - int result_rows = img.rows - templ.rows + 1; - - result.create( result_cols, result_rows, CV_32FC1 ); - - /// Do the Matching and Normalize - matchTemplate( img, templ, result, match_method ); - normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() ); - - /// Localizing the best match with minMaxLoc - double minVal; double maxVal; Point minLoc; Point maxLoc; - Point matchLoc; - - minMaxLoc( result, &minVal, &maxVal, &minLoc, &maxLoc, Mat() ); - - /// For SQDIFF and SQDIFF_NORMED, the best matches are lower values. For all the other methods, the higher the better - if( match_method == CV_TM_SQDIFF || match_method == CV_TM_SQDIFF_NORMED ) - { matchLoc = minLoc; } - else - { matchLoc = maxLoc; } - - /// Show me what you got - rectangle( img_display, matchLoc, Point( matchLoc.x + templ.cols , matchLoc.y + templ.rows ), Scalar::all(0), 2, 8, 0 ); - rectangle( result, matchLoc, Point( matchLoc.x + templ.cols , matchLoc.y + templ.rows ), Scalar::all(0), 2, 8, 0 ); - - imshow( image_window, img_display ); - imshow( result_window, result ); - - return; -} -@endcode + @includelineno samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp + Explanation ----------- -1. Declare some global variables, such as the image, template and result matrices, as well as the +-# Declare some global variables, such as the image, template and result matrices, as well as the match method and the window names: @code{.cpp} Mat img; Mat templ; Mat result; @@ -194,33 +113,33 @@ Explanation int match_method; int max_Trackbar = 5; @endcode -2. Load the source image and template: +-# Load the source image and template: @code{.cpp} img = imread( argv[1], 1 ); templ = imread( argv[2], 1 ); @endcode -3. Create the windows to show the results: +-# Create the windows to show the results: @code{.cpp} namedWindow( image_window, WINDOW_AUTOSIZE ); namedWindow( result_window, WINDOW_AUTOSIZE ); @endcode -4. Create the Trackbar to enter the kind of matching method to be used. When a change is detected +-# Create the Trackbar to enter the kind of matching method to be used. When a change is detected the callback function **MatchingMethod** is called. @code{.cpp} char* trackbar_label = "Method: \n 0: SQDIFF \n 1: SQDIFF NORMED \n 2: TM CCORR \n 3: TM CCORR NORMED \n 4: TM COEFF \n 5: TM COEFF NORMED"; createTrackbar( trackbar_label, image_window, &match_method, max_Trackbar, MatchingMethod ); @endcode -5. Wait until user exits the program. +-# Wait until user exits the program. @code{.cpp} waitKey(0); return 0; @endcode -6. Let's check out the callback function. First, it makes a copy of the source image: +-# Let's check out the callback function. First, it makes a copy of the source image: @code{.cpp} Mat img_display; img.copyTo( img_display ); @endcode -7. Next, it creates the result matrix that will store the matching results for each template +-# Next, it creates the result matrix that will store the matching results for each template location. Observe in detail the size of the result matrix (which matches all possible locations for it) @code{.cpp} @@ -229,18 +148,18 @@ Explanation result.create( result_cols, result_rows, CV_32FC1 ); @endcode -8. Perform the template matching operation: +-# Perform the template matching operation: @code{.cpp} matchTemplate( img, templ, result, match_method ); @endcode the arguments are naturally the input image **I**, the template **T**, the result **R** and the match_method (given by the Trackbar) -9. We normalize the results: +-# We normalize the results: @code{.cpp} normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() ); @endcode -10. We localize the minimum and maximum values in the result matrix **R** by using @ref +-# We localize the minimum and maximum values in the result matrix **R** by using @ref cv::minMaxLoc . @code{.cpp} double minVal; double maxVal; Point minLoc; Point maxLoc; @@ -256,7 +175,7 @@ Explanation array. - **Mat():** Optional mask -11. For the first two methods ( TM_SQDIFF and MT_SQDIFF_NORMED ) the best match are the lowest +-# For the first two methods ( TM_SQDIFF and MT_SQDIFF_NORMED ) the best match are the lowest values. For all the others, higher values represent better matches. So, we save the corresponding value in the **matchLoc** variable: @code{.cpp} @@ -265,7 +184,7 @@ Explanation else { matchLoc = maxLoc; } @endcode -12. Display the source image and the result matrix. Draw a rectangle around the highest possible +-# Display the source image and the result matrix. Draw a rectangle around the highest possible matching area: @code{.cpp} rectangle( img_display, matchLoc, Point( matchLoc.x + templ.cols , matchLoc.y + templ.rows ), Scalar::all(0), 2, 8, 0 ); @@ -274,29 +193,32 @@ Explanation imshow( image_window, img_display ); imshow( result_window, result ); @endcode + Results ------- -1. Testing our program with an input image such as: +-# Testing our program with an input image such as: - ![image](images/Template_Matching_Original_Image.jpg) + ![](images/Template_Matching_Original_Image.jpg) and a template image: - ![image](images/Template_Matching_Template_Image.jpg) + ![](images/Template_Matching_Template_Image.jpg) -2. Generate the following result matrices (first row are the standard methods SQDIFF, CCORR and +-# Generate the following result matrices (first row are the standard methods SQDIFF, CCORR and CCOEFF, second row are the same methods in its normalized version). In the first column, the darkest is the better match, for the other two columns, the brighter a location, the higher the match. - - |Result_0| |Result_2| |Result_4| - ------------- ------------- ------------- - |Result_1| |Result_3| |Result_5| - -3. The right match is shown below (black rectangle around the face of the guy at the right). Notice + ![Result_0](images/Template_Matching_Correl_Result_0.jpg) + ![Result_1](images/Template_Matching_Correl_Result_1.jpg) + ![Result_2](images/Template_Matching_Correl_Result_2.jpg) + ![Result_3](images/Template_Matching_Correl_Result_3.jpg) + ![Result_4](images/Template_Matching_Correl_Result_4.jpg) + ![Result_5](images/Template_Matching_Correl_Result_5.jpg) + +-# The right match is shown below (black rectangle around the face of the guy at the right). Notice that CCORR and CCDEFF gave erroneous best matches, however their normalized version did it right, this may be due to the fact that we are only considering the "highest match" and not the other possible high matches. - ![image](images/Template_Matching_Image_Result.jpg) + ![](images/Template_Matching_Image_Result.jpg) diff --git a/doc/tutorials/imgproc/imgtrans/canny_detector/canny_detector.markdown b/doc/tutorials/imgproc/imgtrans/canny_detector/canny_detector.markdown index dbfd3a08bd..f132c3d8e3 100644 --- a/doc/tutorials/imgproc/imgtrans/canny_detector/canny_detector.markdown +++ b/doc/tutorials/imgproc/imgtrans/canny_detector/canny_detector.markdown @@ -20,7 +20,7 @@ The *Canny Edge detector* was developed by John F. Canny in 1986. Also known to ### Steps -1. Filter out any noise. The Gaussian filter is used for this purpose. An example of a Gaussian +-# Filter out any noise. The Gaussian filter is used for this purpose. An example of a Gaussian kernel of \f$size = 5\f$ that might be used is shown below: \f[K = \dfrac{1}{159}\begin{bmatrix} @@ -31,8 +31,8 @@ The *Canny Edge detector* was developed by John F. Canny in 1986. Also known to 2 & 4 & 5 & 4 & 2 \end{bmatrix}\f] -2. Find the intensity gradient of the image. For this, we follow a procedure analogous to Sobel: - 1. Apply a pair of convolution masks (in \f$x\f$ and \f$y\f$ directions: +-# Find the intensity gradient of the image. For this, we follow a procedure analogous to Sobel: + -# Apply a pair of convolution masks (in \f$x\f$ and \f$y\f$ directions: \f[G_{x} = \begin{bmatrix} -1 & 0 & +1 \\ -2 & 0 & +2 \\ @@ -43,44 +43,44 @@ The *Canny Edge detector* was developed by John F. Canny in 1986. Also known to +1 & +2 & +1 \end{bmatrix}\f] - 2. Find the gradient strength and direction with: + -# Find the gradient strength and direction with: \f[\begin{array}{l} G = \sqrt{ G_{x}^{2} + G_{y}^{2} } \\ \theta = \arctan(\dfrac{ G_{y} }{ G_{x} }) \end{array}\f] The direction is rounded to one of four possible angles (namely 0, 45, 90 or 135) -3. *Non-maximum* suppression is applied. This removes pixels that are not considered to be part of +-# *Non-maximum* suppression is applied. This removes pixels that are not considered to be part of an edge. Hence, only thin lines (candidate edges) will remain. -4. *Hysteresis*: The final step. Canny does use two thresholds (upper and lower): +-# *Hysteresis*: The final step. Canny does use two thresholds (upper and lower): - 1. If a pixel gradient is higher than the *upper* threshold, the pixel is accepted as an edge - 2. If a pixel gradient value is below the *lower* threshold, then it is rejected. - 3. If the pixel gradient is between the two thresholds, then it will be accepted only if it is + -# If a pixel gradient is higher than the *upper* threshold, the pixel is accepted as an edge + -# If a pixel gradient value is below the *lower* threshold, then it is rejected. + -# If the pixel gradient is between the two thresholds, then it will be accepted only if it is connected to a pixel that is above the *upper* threshold. Canny recommended a *upper*:*lower* ratio between 2:1 and 3:1. -5. For more details, you can always consult your favorite Computer Vision book. +-# For more details, you can always consult your favorite Computer Vision book. Code ---- -1. **What does this program do?** +-# **What does this program do?** - Asks the user to enter a numerical value to set the lower threshold for our *Canny Edge Detector* (by means of a Trackbar) - Applies the *Canny Detector* and generates a **mask** (bright lines representing the edges on a black background). - Applies the mask obtained on the original image and display it in a window. -2. The tutorial code's is shown lines below. You can also download it from +-# The tutorial code's is shown lines below. You can also download it from [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp) @includelineno samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp Explanation ----------- -1. Create some needed variables: +-# Create some needed variables: @code{.cpp} Mat src, src_gray; Mat dst, detected_edges; @@ -94,12 +94,12 @@ Explanation @endcode Note the following: - 1. We establish a ratio of lower:upper threshold of 3:1 (with the variable *ratio*) - 2. We set the kernel size of \f$3\f$ (for the Sobel operations to be performed internally by the + -# We establish a ratio of lower:upper threshold of 3:1 (with the variable *ratio*) + -# We set the kernel size of \f$3\f$ (for the Sobel operations to be performed internally by the Canny function) - 3. We set a maximum value for the lower Threshold of \f$100\f$. + -# We set a maximum value for the lower Threshold of \f$100\f$. -2. Loads the source image: +-# Loads the source image: @code{.cpp} /// Load an image src = imread( argv[1] ); @@ -107,35 +107,35 @@ Explanation if( !src.data ) { return -1; } @endcode -3. Create a matrix of the same type and size of *src* (to be *dst*) +-# Create a matrix of the same type and size of *src* (to be *dst*) @code{.cpp} dst.create( src.size(), src.type() ); @endcode -4. Convert the image to grayscale (using the function @ref cv::cvtColor : +-# Convert the image to grayscale (using the function @ref cv::cvtColor : @code{.cpp} cvtColor( src, src_gray, COLOR_BGR2GRAY ); @endcode -5. Create a window to display the results +-# Create a window to display the results @code{.cpp} namedWindow( window_name, WINDOW_AUTOSIZE ); @endcode -6. Create a Trackbar for the user to enter the lower threshold for our Canny detector: +-# Create a Trackbar for the user to enter the lower threshold for our Canny detector: @code{.cpp} createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold ); @endcode Observe the following: - 1. The variable to be controlled by the Trackbar is *lowThreshold* with a limit of + -# The variable to be controlled by the Trackbar is *lowThreshold* with a limit of *max_lowThreshold* (which we set to 100 previously) - 2. Each time the Trackbar registers an action, the callback function *CannyThreshold* will be + -# Each time the Trackbar registers an action, the callback function *CannyThreshold* will be invoked. -7. Let's check the *CannyThreshold* function, step by step: - 1. First, we blur the image with a filter of kernel size 3: +-# Let's check the *CannyThreshold* function, step by step: + -# First, we blur the image with a filter of kernel size 3: @code{.cpp} blur( src_gray, detected_edges, Size(3,3) ); @endcode - 2. Second, we apply the OpenCV function @ref cv::Canny : + -# Second, we apply the OpenCV function @ref cv::Canny : @code{.cpp} Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size ); @endcode @@ -149,11 +149,11 @@ Explanation - *kernel_size*: We defined it to be 3 (the size of the Sobel kernel to be used internally) -8. We fill a *dst* image with zeros (meaning the image is completely black). +-# We fill a *dst* image with zeros (meaning the image is completely black). @code{.cpp} dst = Scalar::all(0); @endcode -9. Finally, we will use the function @ref cv::Mat::copyTo to map only the areas of the image that are +-# Finally, we will use the function @ref cv::Mat::copyTo to map only the areas of the image that are identified as edges (on a black background). @code{.cpp} src.copyTo( dst, detected_edges); @@ -163,20 +163,21 @@ Explanation contours on a black background, the resulting *dst* will be black in all the area but the detected edges. -10. We display our result: +-# We display our result: @code{.cpp} imshow( window_name, dst ); @endcode + Result ------ - After compiling the code above, we can run it giving as argument the path to an image. For example, using as an input the following image: - ![image](images/Canny_Detector_Tutorial_Original_Image.jpg) + ![](images/Canny_Detector_Tutorial_Original_Image.jpg) - Moving the slider, trying different threshold, we obtain the following result: - ![image](images/Canny_Detector_Tutorial_Result.jpg) + ![](images/Canny_Detector_Tutorial_Result.jpg) - Notice how the image is superposed to the black background on the edge regions. diff --git a/doc/tutorials/imgproc/imgtrans/copyMakeBorder/copyMakeBorder.markdown b/doc/tutorials/imgproc/imgtrans/copyMakeBorder/copyMakeBorder.markdown index 501b4e47f2..578a609976 100644 --- a/doc/tutorials/imgproc/imgtrans/copyMakeBorder/copyMakeBorder.markdown +++ b/doc/tutorials/imgproc/imgtrans/copyMakeBorder/copyMakeBorder.markdown @@ -14,14 +14,14 @@ Theory @note The explanation below belongs to the book **Learning OpenCV** by Bradski and Kaehler. -1. In our previous tutorial we learned to use convolution to operate on images. One problem that +-# In our previous tutorial we learned to use convolution to operate on images. One problem that naturally arises is how to handle the boundaries. How can we convolve them if the evaluated points are at the edge of the image? -2. What most of OpenCV functions do is to copy a given image onto another slightly larger image and +-# What most of OpenCV functions do is to copy a given image onto another slightly larger image and then automatically pads the boundary (by any of the methods explained in the sample code just below). This way, the convolution can be performed over the needed pixels without problems (the extra padding is cut after the operation is done). -3. In this tutorial, we will briefly explore two ways of defining the extra padding (border) for an +-# In this tutorial, we will briefly explore two ways of defining the extra padding (border) for an image: -# **BORDER_CONSTANT**: Pad the image with a constant value (i.e. black or \f$0\f$ @@ -33,91 +33,26 @@ Theory Code ---- -1. **What does this program do?** +-# **What does this program do?** - Load an image - Let the user choose what kind of padding use in the input image. There are two options: - 1. *Constant value border*: Applies a padding of a constant value for the whole border. + -# *Constant value border*: Applies a padding of a constant value for the whole border. This value will be updated randomly each 0.5 seconds. - 2. *Replicated border*: The border will be replicated from the pixel values at the edges of + -# *Replicated border*: The border will be replicated from the pixel values at the edges of the original image. The user chooses either option by pressing 'c' (constant) or 'r' (replicate) - The program finishes when the user presses 'ESC' -2. The tutorial code's is shown lines below. You can also download it from +-# The tutorial code's is shown lines below. You can also download it from [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp) -@code{.cpp} -#include "opencv2/imgproc.hpp" -#include "opencv2/highgui.hpp" -#include -#include - -using namespace cv; - -/// Global Variables -Mat src, dst; -int top, bottom, left, right; -int borderType; -Scalar value; -char* window_name = "copyMakeBorder Demo"; -RNG rng(12345); - -/* @function main */ -int main( int argc, char** argv ) -{ - - int c; - - /// Load an image - src = imread( argv[1] ); - - if( !src.data ) - { return -1; - printf(" No data entered, please enter the path to an image file \n"); - } - - /// Brief how-to for this program - printf( "\n \t copyMakeBorder Demo: \n" ); - printf( "\t -------------------- \n" ); - printf( " ** Press 'c' to set the border to a random constant value \n"); - printf( " ** Press 'r' to set the border to be replicated \n"); - printf( " ** Press 'ESC' to exit the program \n"); - - /// Create window - namedWindow( window_name, WINDOW_AUTOSIZE ); - - /// Initialize arguments for the filter - top = (int) (0.05*src.rows); bottom = (int) (0.05*src.rows); - left = (int) (0.05*src.cols); right = (int) (0.05*src.cols); - dst = src; - - imshow( window_name, dst ); - - while( true ) - { - c = waitKey(500); - - if( (char)c == 27 ) - { break; } - else if( (char)c == 'c' ) - { borderType = BORDER_CONSTANT; } - else if( (char)c == 'r' ) - { borderType = BORDER_REPLICATE; } - - value = Scalar( rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255) ); - copyMakeBorder( src, dst, top, bottom, left, right, borderType, value ); - - imshow( window_name, dst ); - } + @includelineno samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp - return 0; -} -@endcode Explanation ----------- -1. First we declare the variables we are going to use: +-# First we declare the variables we are going to use: @code{.cpp} Mat src, dst; int top, bottom, left, right; @@ -129,7 +64,7 @@ Explanation Especial attention deserves the variable *rng* which is a random number generator. We use it to generate the random border color, as we will see soon. -2. As usual we load our source image *src*: +-# As usual we load our source image *src*: @code{.cpp} src = imread( argv[1] ); @@ -138,17 +73,17 @@ Explanation printf(" No data entered, please enter the path to an image file \n"); } @endcode -3. After giving a short intro of how to use the program, we create a window: +-# After giving a short intro of how to use the program, we create a window: @code{.cpp} namedWindow( window_name, WINDOW_AUTOSIZE ); @endcode -4. Now we initialize the argument that defines the size of the borders (*top*, *bottom*, *left* and +-# Now we initialize the argument that defines the size of the borders (*top*, *bottom*, *left* and *right*). We give them a value of 5% the size of *src*. @code{.cpp} top = (int) (0.05*src.rows); bottom = (int) (0.05*src.rows); left = (int) (0.05*src.cols); right = (int) (0.05*src.cols); @endcode -5. The program begins a *while* loop. If the user presses 'c' or 'r', the *borderType* variable +-# The program begins a *while* loop. If the user presses 'c' or 'r', the *borderType* variable takes the value of *BORDER_CONSTANT* or *BORDER_REPLICATE* respectively: @code{.cpp} while( true ) @@ -162,14 +97,14 @@ Explanation else if( (char)c == 'r' ) { borderType = BORDER_REPLICATE; } @endcode -6. In each iteration (after 0.5 seconds), the variable *value* is updated... +-# In each iteration (after 0.5 seconds), the variable *value* is updated... @code{.cpp} value = Scalar( rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255) ); @endcode with a random value generated by the **RNG** variable *rng*. This value is a number picked randomly in the range \f$[0,255]\f$ -7. Finally, we call the function @ref cv::copyMakeBorder to apply the respective padding: +-# Finally, we call the function @ref cv::copyMakeBorder to apply the respective padding: @code{.cpp} copyMakeBorder( src, dst, top, bottom, left, right, borderType, value ); @endcode @@ -184,14 +119,15 @@ Explanation -# *value*: If *borderType* is *BORDER_CONSTANT*, this is the value used to fill the border pixels. -8. We display our output image in the image created previously +-# We display our output image in the image created previously @code{.cpp} imshow( window_name, dst ); @endcode + Results ------- -1. After compiling the code above, you can execute it giving as argument the path of an image. The +-# After compiling the code above, you can execute it giving as argument the path of an image. The result should be: - By default, it begins with the border set to BORDER_CONSTANT. Hence, a succession of random @@ -203,4 +139,4 @@ Results Below some screenshot showing how the border changes color and how the *BORDER_REPLICATE* option looks: - ![image](images/CopyMakeBorder_Tutorial_Results.jpg) + ![](images/CopyMakeBorder_Tutorial_Results.jpg) diff --git a/doc/tutorials/imgproc/imgtrans/filter_2d/filter_2d.markdown b/doc/tutorials/imgproc/imgtrans/filter_2d/filter_2d.markdown index 2cb8cd69d9..079bbed394 100644 --- a/doc/tutorials/imgproc/imgtrans/filter_2d/filter_2d.markdown +++ b/doc/tutorials/imgproc/imgtrans/filter_2d/filter_2d.markdown @@ -23,18 +23,18 @@ In a very general sense, convolution is an operation between every part of an im A kernel is essentially a fixed size array of numerical coefficeints along with an *anchor point* in that array, which is tipically located at the center. -![image](images/filter_2d_tutorial_kernel_theory.png) +![](images/filter_2d_tutorial_kernel_theory.png) ### How does convolution with a kernel work? Assume you want to know the resulting value of a particular location in the image. The value of the convolution is calculated in the following way: -1. Place the kernel anchor on top of a determined pixel, with the rest of the kernel overlaying the +-# Place the kernel anchor on top of a determined pixel, with the rest of the kernel overlaying the corresponding local pixels in the image. -2. Multiply the kernel coefficients by the corresponding image pixel values and sum the result. -3. Place the result to the location of the *anchor* in the input image. -4. Repeat the process for all pixels by scanning the kernel over the entire image. +-# Multiply the kernel coefficients by the corresponding image pixel values and sum the result. +-# Place the result to the location of the *anchor* in the input image. +-# Repeat the process for all pixels by scanning the kernel over the entire image. Expressing the procedure above in the form of an equation we would have: @@ -46,7 +46,7 @@ these operations. Code ---- -1. **What does this program do?** +-# **What does this program do?** - Loads an image - Performs a *normalized box filter*. For instance, for a kernel of size \f$size = 3\f$, the kernel would be: @@ -61,7 +61,7 @@ Code - The filter output (with each kernel) will be shown during 500 milliseconds -2. The tutorial code's is shown lines below. You can also download it from +-# The tutorial code's is shown lines below. You can also download it from [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp) @code{.cpp} #include "opencv2/imgproc.hpp" @@ -125,26 +125,26 @@ int main ( int argc, char** argv ) Explanation ----------- -1. Load an image +-# Load an image @code{.cpp} src = imread( argv[1] ); if( !src.data ) { return -1; } @endcode -2. Create a window to display the result +-# Create a window to display the result @code{.cpp} namedWindow( window_name, WINDOW_AUTOSIZE ); @endcode -3. Initialize the arguments for the linear filter +-# Initialize the arguments for the linear filter @code{.cpp} anchor = Point( -1, -1 ); delta = 0; ddepth = -1; @endcode -4. Perform an infinite loop updating the kernel size and applying our linear filter to the input +-# Perform an infinite loop updating the kernel size and applying our linear filter to the input image. Let's analyze that more in detail: -5. First we define the kernel our filter is going to use. Here it is: +-# First we define the kernel our filter is going to use. Here it is: @code{.cpp} kernel_size = 3 + 2*( ind%5 ); kernel = Mat::ones( kernel_size, kernel_size, CV_32F )/ (float)(kernel_size*kernel_size); @@ -153,7 +153,7 @@ Explanation line actually builds the kernel by setting its value to a matrix filled with \f$1's\f$ and normalizing it by dividing it between the number of elements. -6. After setting the kernel, we can generate the filter by using the function @ref cv::filter2D : +-# After setting the kernel, we can generate the filter by using the function @ref cv::filter2D : @code{.cpp} filter2D(src, dst, ddepth , kernel, anchor, delta, BORDER_DEFAULT ); @endcode @@ -169,14 +169,14 @@ Explanation -# *delta*: A value to be added to each pixel during the convolution. By default it is \f$0\f$ -# *BORDER_DEFAULT*: We let this value by default (more details in the following tutorial) -7. Our program will effectuate a *while* loop, each 500 ms the kernel size of our filter will be +-# Our program will effectuate a *while* loop, each 500 ms the kernel size of our filter will be updated in the range indicated. Results ------- -1. After compiling the code above, you can execute it giving as argument the path of an image. The +-# After compiling the code above, you can execute it giving as argument the path of an image. The result should be a window that shows an image blurred by a normalized filter. Each 0.5 seconds the kernel size should change, as can be seen in the series of snapshots below: - ![image](images/filter_2d_tutorial_result.jpg) + ![](images/filter_2d_tutorial_result.jpg) diff --git a/doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.markdown b/doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.markdown index 7e46c830ba..157cee42fe 100644 --- a/doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.markdown +++ b/doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.markdown @@ -23,7 +23,7 @@ Theory where \f$(x_{center}, y_{center})\f$ define the center position (green point) and \f$r\f$ is the radius, which allows us to completely define a circle, as it can be seen below: - ![image](images/Hough_Circle_Tutorial_Theory_0.jpg) + ![](images/Hough_Circle_Tutorial_Theory_0.jpg) - For sake of efficiency, OpenCV implements a detection method slightly trickier than the standard Hough Transform: *The Hough gradient method*, which is made up of two main stages. The first @@ -34,82 +34,35 @@ Theory Code ---- -1. **What does this program do?** +-# **What does this program do?** - Loads an image and blur it to reduce the noise - Applies the *Hough Circle Transform* to the blurred image . - Display the detected circle in a window. -2. The sample code that we will explain can be downloaded from - |TutorialHoughCirclesSimpleDownload|_. A slightly fancier version (which shows trackbars for - changing the threshold values) can be found |TutorialHoughCirclesFancyDownload|_. -@code{.cpp} -#include "opencv2/highgui.hpp" -#include "opencv2/imgproc.hpp" -#include -#include - -using namespace cv; - -/* @function main */ -int main(int argc, char** argv) -{ - Mat src, src_gray; - - /// Read the image - src = imread( argv[1], 1 ); - - if( !src.data ) - { return -1; } - - /// Convert it to gray - cvtColor( src, src_gray, COLOR_BGR2GRAY ); - - /// Reduce the noise so we avoid false circle detection - GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 ); - - vector circles; - - /// Apply the Hough Transform to find the circles - HoughCircles( src_gray, circles, HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0 ); - - /// Draw the circles detected - for( size_t i = 0; i < circles.size(); i++ ) - { - Point center(cvRound(circles[i][0]), cvRound(circles[i][1])); - int radius = cvRound(circles[i][2]); - // circle center - circle( src, center, 3, Scalar(0,255,0), -1, 8, 0 ); - // circle outline - circle( src, center, radius, Scalar(0,0,255), 3, 8, 0 ); - } - - /// Show your results - namedWindow( "Hough Circle Transform Demo", WINDOW_AUTOSIZE ); - imshow( "Hough Circle Transform Demo", src ); - - waitKey(0); - return 0; -} -@endcode +-# The sample code that we will explain can be downloaded from [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/houghcircles.cpp). + A slightly fancier version (which shows trackbars for + changing the threshold values) can be found [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp). + @includelineno samples/cpp/houghcircles.cpp + Explanation ----------- -1. Load an image +-# Load an image @code{.cpp} src = imread( argv[1], 1 ); if( !src.data ) { return -1; } @endcode -2. Convert it to grayscale: +-# Convert it to grayscale: @code{.cpp} cvtColor( src, src_gray, COLOR_BGR2GRAY ); @endcode -3. Apply a Gaussian blur to reduce noise and avoid false circle detection: +-# Apply a Gaussian blur to reduce noise and avoid false circle detection: @code{.cpp} GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 ); @endcode -4. Proceed to apply Hough Circle Transform: +-# Proceed to apply Hough Circle Transform: @code{.cpp} vector circles; @@ -129,7 +82,7 @@ Explanation - *min_radius = 0*: Minimum radio to be detected. If unknown, put zero as default. - *max_radius = 0*: Maximum radius to be detected. If unknown, put zero as default. -5. Draw the detected circles: +-# Draw the detected circles: @code{.cpp} for( size_t i = 0; i < circles.size(); i++ ) { @@ -143,19 +96,19 @@ Explanation @endcode You can see that we will draw the circle(s) on red and the center(s) with a small green dot -6. Display the detected circle(s): +-# Display the detected circle(s): @code{.cpp} namedWindow( "Hough Circle Transform Demo", WINDOW_AUTOSIZE ); imshow( "Hough Circle Transform Demo", src ); @endcode -7. Wait for the user to exit the program +-# Wait for the user to exit the program @code{.cpp} waitKey(0); @endcode + Result ------ The result of running the code above with a test image is shown below: -![image](images/Hough_Circle_Tutorial_Result.jpg) - +![](images/Hough_Circle_Tutorial_Result.jpg) diff --git a/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.markdown b/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.markdown index 8ea9ff8de3..cc73fca1e0 100644 --- a/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.markdown +++ b/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.markdown @@ -12,18 +12,22 @@ In this tutorial you will learn how to: Theory ------ -@note The explanation below belongs to the book **Learning OpenCV** by Bradski and Kaehler. Hough -Line Transform ---------------------\#. The Hough Line Transform is a transform used to detect -straight lines. \#. To apply the Transform, first an edge detection pre-processing is desirable. +@note The explanation below belongs to the book **Learning OpenCV** by Bradski and Kaehler. + +Hough Line Transform +-------------------- + +-# The Hough Line Transform is a transform used to detect straight lines. +-# To apply the Transform, first an edge detection pre-processing is desirable. ### How does it work? -1. As you know, a line in the image space can be expressed with two variables. For example: +-# As you know, a line in the image space can be expressed with two variables. For example: -# In the **Cartesian coordinate system:** Parameters: \f$(m,b)\f$. -# In the **Polar coordinate system:** Parameters: \f$(r,\theta)\f$ - ![image](images/Hough_Lines_Tutorial_Theory_0.jpg) + ![](images/Hough_Lines_Tutorial_Theory_0.jpg) For Hough Transforms, we will express lines in the *Polar system*. Hence, a line equation can be written as: @@ -32,7 +36,7 @@ straight lines. \#. To apply the Transform, first an edge detection pre-processi Arranging the terms: \f$r = x \cos \theta + y \sin \theta\f$ -1. In general for each point \f$(x_{0}, y_{0})\f$, we can define the family of lines that goes through +-# In general for each point \f$(x_{0}, y_{0})\f$, we can define the family of lines that goes through that point as: \f[r_{\theta} = x_{0} \cdot \cos \theta + y_{0} \cdot \sin \theta\f] @@ -40,30 +44,30 @@ Arranging the terms: \f$r = x \cos \theta + y \sin \theta\f$ Meaning that each pair \f$(r_{\theta},\theta)\f$ represents each line that passes by \f$(x_{0}, y_{0})\f$. -2. If for a given \f$(x_{0}, y_{0})\f$ we plot the family of lines that goes through it, we get a +-# If for a given \f$(x_{0}, y_{0})\f$ we plot the family of lines that goes through it, we get a sinusoid. For instance, for \f$x_{0} = 8\f$ and \f$y_{0} = 6\f$ we get the following plot (in a plane \f$\theta\f$ - \f$r\f$): - ![image](images/Hough_Lines_Tutorial_Theory_1.jpg) + ![](images/Hough_Lines_Tutorial_Theory_1.jpg) We consider only points such that \f$r > 0\f$ and \f$0< \theta < 2 \pi\f$. -3. We can do the same operation above for all the points in an image. If the curves of two +-# We can do the same operation above for all the points in an image. If the curves of two different points intersect in the plane \f$\theta\f$ - \f$r\f$, that means that both points belong to a same line. For instance, following with the example above and drawing the plot for two more points: \f$x_{1} = 9\f$, \f$y_{1} = 4\f$ and \f$x_{2} = 12\f$, \f$y_{2} = 3\f$, we get: - ![image](images/Hough_Lines_Tutorial_Theory_2.jpg) + ![](images/Hough_Lines_Tutorial_Theory_2.jpg) The three plots intersect in one single point \f$(0.925, 9.6)\f$, these coordinates are the parameters (\f$\theta, r\f$) or the line in which \f$(x_{0}, y_{0})\f$, \f$(x_{1}, y_{1})\f$ and \f$(x_{2}, y_{2})\f$ lay. -4. What does all the stuff above mean? It means that in general, a line can be *detected* by +-# What does all the stuff above mean? It means that in general, a line can be *detected* by finding the number of intersections between curves.The more curves intersecting means that the line represented by that intersection have more points. In general, we can define a *threshold* of the minimum number of intersections needed to *detect* a line. -5. This is what the Hough Line Transform does. It keeps track of the intersection between curves of +-# This is what the Hough Line Transform does. It keeps track of the intersection between curves of every point in the image. If the number of intersections is above some *threshold*, then it declares it as a line with the parameters \f$(\theta, r_{\theta})\f$ of the intersection point. @@ -86,83 +90,20 @@ b. **The Probabilistic Hough Line Transform** Code ---- -1. **What does this program do?** +-# **What does this program do?** - Loads an image - Applies either a *Standard Hough Line Transform* or a *Probabilistic Line Transform*. - Display the original image and the detected line in two windows. -2. The sample code that we will explain can be downloaded from here_. A slightly fancier version +-# The sample code that we will explain can be downloaded from [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/houghlines.cpp). A slightly fancier version (which shows both Hough standard and probabilistic with trackbars for changing the threshold - values) can be found here_. -@code{.cpp} -#include "opencv2/highgui.hpp" -#include "opencv2/imgproc.hpp" - -#include - -using namespace cv; -using namespace std; - -void help() -{ - cout << "\nThis program demonstrates line finding with the Hough transform.\n" - "Usage:\n" - "./houghlines , Default is pic1.jpg\n" << endl; -} - -int main(int argc, char** argv) -{ - const char* filename = argc >= 2 ? argv[1] : "pic1.jpg"; - - Mat src = imread(filename, 0); - if(src.empty()) - { - help(); - cout << "can not open " << filename << endl; - return -1; - } - - Mat dst, cdst; - Canny(src, dst, 50, 200, 3); - cvtColor(dst, cdst, COLOR_GRAY2BGR); - - #if 0 - vector lines; - HoughLines(dst, lines, 1, CV_PI/180, 100, 0, 0 ); - - for( size_t i = 0; i < lines.size(); i++ ) - { - float rho = lines[i][0], theta = lines[i][1]; - Point pt1, pt2; - double a = cos(theta), b = sin(theta); - double x0 = a*rho, y0 = b*rho; - pt1.x = cvRound(x0 + 1000*(-b)); - pt1.y = cvRound(y0 + 1000*(a)); - pt2.x = cvRound(x0 - 1000*(-b)); - pt2.y = cvRound(y0 - 1000*(a)); - line( cdst, pt1, pt2, Scalar(0,0,255), 3, LINE_AA); - } - #else - vector lines; - HoughLinesP(dst, lines, 1, CV_PI/180, 50, 50, 10 ); - for( size_t i = 0; i < lines.size(); i++ ) - { - Vec4i l = lines[i]; - line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, CV_AA); - } - #endif - imshow("source", src); - imshow("detected lines", cdst); - - waitKey(); - - return 0; -} -@endcode + values) can be found [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp). + @includelineno samples/cpp/houghlines.cpp + Explanation ----------- -1. Load an image +-# Load an image @code{.cpp} Mat src = imread(filename, 0); if(src.empty()) @@ -172,14 +113,14 @@ Explanation return -1; } @endcode -2. Detect the edges of the image by using a Canny detector +-# Detect the edges of the image by using a Canny detector @code{.cpp} Canny(src, dst, 50, 200, 3); @endcode Now we will apply the Hough Line Transform. We will explain how to use both OpenCV functions available for this purpose: -3. **Standard Hough Line Transform** +-# **Standard Hough Line Transform** -# First, you apply the Transform: @code{.cpp} vector lines; @@ -211,7 +152,7 @@ Explanation line( cdst, pt1, pt2, Scalar(0,0,255), 3, LINE_AA); } @endcode -4. **Probabilistic Hough Line Transform** +-# **Probabilistic Hough Line Transform** -# First you apply the transform: @code{.cpp} vector lines; @@ -239,15 +180,16 @@ Explanation line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, LINE_AA); } @endcode -5. Display the original image and the detected lines: +-# Display the original image and the detected lines: @code{.cpp} imshow("source", src); imshow("detected lines", cdst); @endcode -6. Wait until the user exits the program +-# Wait until the user exits the program @code{.cpp} waitKey(); @endcode + Result ------ @@ -258,11 +200,11 @@ Result Using an input image such as: -![image](images/Hough_Lines_Tutorial_Original_Image.jpg) +![](images/Hough_Lines_Tutorial_Original_Image.jpg) We get the following result by using the Probabilistic Hough Line Transform: -![image](images/Hough_Lines_Tutorial_Result.jpg) +![](images/Hough_Lines_Tutorial_Result.jpg) You may observe that the number of lines detected vary while you change the *threshold*. The explanation is sort of evident: If you establish a higher threshold, fewer lines will be detected diff --git a/doc/tutorials/imgproc/imgtrans/laplace_operator/laplace_operator.markdown b/doc/tutorials/imgproc/imgtrans/laplace_operator/laplace_operator.markdown index ac1962f86c..c98a7efd7d 100644 --- a/doc/tutorials/imgproc/imgtrans/laplace_operator/laplace_operator.markdown +++ b/doc/tutorials/imgproc/imgtrans/laplace_operator/laplace_operator.markdown @@ -12,16 +12,16 @@ In this tutorial you will learn how to: Theory ------ -1. In the previous tutorial we learned how to use the *Sobel Operator*. It was based on the fact +-# In the previous tutorial we learned how to use the *Sobel Operator*. It was based on the fact that in the edge area, the pixel intensity shows a "jump" or a high variation of intensity. Getting the first derivative of the intensity, we observed that an edge is characterized by a maximum, as it can be seen in the figure: - ![image](images/Laplace_Operator_Tutorial_Theory_Previous.jpg) + ![](images/Laplace_Operator_Tutorial_Theory_Previous.jpg) -2. And...what happens if we take the second derivative? +-# And...what happens if we take the second derivative? - ![image](images/Laplace_Operator_Tutorial_Theory_ddIntensity.jpg) + ![](images/Laplace_Operator_Tutorial_Theory_ddIntensity.jpg) You can observe that the second derivative is zero! So, we can also use this criterion to attempt to detect edges in an image. However, note that zeros will not only appear in edges @@ -30,81 +30,34 @@ Theory ### Laplacian Operator -1. From the explanation above, we deduce that the second derivative can be used to *detect edges*. +-# From the explanation above, we deduce that the second derivative can be used to *detect edges*. Since images are "*2D*", we would need to take the derivative in both dimensions. Here, the Laplacian operator comes handy. -2. The *Laplacian operator* is defined by: +-# The *Laplacian operator* is defined by: \f[Laplace(f) = \dfrac{\partial^{2} f}{\partial x^{2}} + \dfrac{\partial^{2} f}{\partial y^{2}}\f] -1. The Laplacian operator is implemented in OpenCV by the function @ref cv::Laplacian . In fact, +-# The Laplacian operator is implemented in OpenCV by the function @ref cv::Laplacian . In fact, since the Laplacian uses the gradient of images, it calls internally the *Sobel* operator to perform its computation. Code ---- -1. **What does this program do?** +-# **What does this program do?** - Loads an image - Remove noise by applying a Gaussian blur and then convert the original image to grayscale - Applies a Laplacian operator to the grayscale image and stores the output image - Display the result in a window -2. The tutorial code's is shown lines below. You can also download it from +-# The tutorial code's is shown lines below. You can also download it from [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp) -@code{.cpp} -#include "opencv2/imgproc.hpp" -#include "opencv2/highgui.hpp" -#include -#include + @includelineno samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp -using namespace cv; - -/* @function main */ -int main( int argc, char** argv ) -{ - Mat src, src_gray, dst; - int kernel_size = 3; - int scale = 1; - int delta = 0; - int ddepth = CV_16S; - char* window_name = "Laplace Demo"; - - int c; - - /// Load an image - src = imread( argv[1] ); - - if( !src.data ) - { return -1; } - - /// Remove noise by blurring with a Gaussian filter - GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT ); - - /// Convert the image to grayscale - cvtColor( src, src_gray, COLOR_RGB2GRAY ); - - /// Create window - namedWindow( window_name, WINDOW_AUTOSIZE ); - - /// Apply Laplace function - Mat abs_dst; - - Laplacian( src_gray, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT ); - convertScaleAbs( dst, abs_dst ); - - /// Show what you got - imshow( window_name, abs_dst ); - - waitKey(0); - - return 0; - } -@endcode Explanation ----------- -1. Create some needed variables: +-# Create some needed variables: @code{.cpp} Mat src, src_gray, dst; int kernel_size = 3; @@ -113,22 +66,22 @@ Explanation int ddepth = CV_16S; char* window_name = "Laplace Demo"; @endcode -2. Loads the source image: +-# Loads the source image: @code{.cpp} src = imread( argv[1] ); if( !src.data ) { return -1; } @endcode -3. Apply a Gaussian blur to reduce noise: +-# Apply a Gaussian blur to reduce noise: @code{.cpp} GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT ); @endcode -4. Convert the image to grayscale using @ref cv::cvtColor +-# Convert the image to grayscale using @ref cv::cvtColor @code{.cpp} cvtColor( src, src_gray, COLOR_RGB2GRAY ); @endcode -5. Apply the Laplacian operator to the grayscale image: +-# Apply the Laplacian operator to the grayscale image: @code{.cpp} Laplacian( src_gray, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT ); @endcode @@ -142,27 +95,26 @@ Explanation this example. - *scale*, *delta* and *BORDER_DEFAULT*: We leave them as default values. -6. Convert the output from the Laplacian operator to a *CV_8U* image: +-# Convert the output from the Laplacian operator to a *CV_8U* image: @code{.cpp} convertScaleAbs( dst, abs_dst ); @endcode -7. Display the result in a window: +-# Display the result in a window: @code{.cpp} imshow( window_name, abs_dst ); @endcode + Results ------- -1. After compiling the code above, we can run it giving as argument the path to an image. For +-# After compiling the code above, we can run it giving as argument the path to an image. For example, using as an input: - ![image](images/Laplace_Operator_Tutorial_Original_Image.jpg) + ![](images/Laplace_Operator_Tutorial_Original_Image.jpg) -2. We obtain the following result. Notice how the trees and the silhouette of the cow are +-# We obtain the following result. Notice how the trees and the silhouette of the cow are approximately well defined (except in areas in which the intensity are very similar, i.e. around the cow's head). Also, note that the roof of the house behind the trees (right side) is notoriously marked. This is due to the fact that the contrast is higher in that region. - ![image](images/Laplace_Operator_Tutorial_Result.jpg) - - + ![](images/Laplace_Operator_Tutorial_Result.jpg) diff --git a/doc/tutorials/imgproc/imgtrans/remap/remap.markdown b/doc/tutorials/imgproc/imgtrans/remap/remap.markdown index af4a5f3ea2..da8406f007 100644 --- a/doc/tutorials/imgproc/imgtrans/remap/remap.markdown +++ b/doc/tutorials/imgproc/imgtrans/remap/remap.markdown @@ -33,146 +33,53 @@ Theory What would happen? It is easily seen that the image would flip in the \f$x\f$ direction. For instance, consider the input image: - ![image](images/Remap_Tutorial_Theory_0.jpg) + ![](images/Remap_Tutorial_Theory_0.jpg) observe how the red circle changes positions with respect to x (considering \f$x\f$ the horizontal direction): - ![image](images/Remap_Tutorial_Theory_1.jpg) + ![](images/Remap_Tutorial_Theory_1.jpg) - In OpenCV, the function @ref cv::remap offers a simple remapping implementation. Code ---- -1. **What does this program do?** +-# **What does this program do?** - Loads an image - Each second, apply 1 of 4 different remapping processes to the image and display them indefinitely in a window. - Wait for the user to exit the program -2. The tutorial code's is shown lines below. You can also download it from +-# The tutorial code's is shown lines below. You can also download it from [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp) -@code{.cpp} -#include "opencv2/highgui.hpp" -#include "opencv2/imgproc.hpp" -#include -#include - -using namespace cv; - -/// Global variables -Mat src, dst; -Mat map_x, map_y; -char* remap_window = "Remap demo"; -int ind = 0; - -/// Function Headers -void update_map( void ); - -/* -* @function main -*/ -int main( int argc, char** argv ) -{ - /// Load the image - src = imread( argv[1], 1 ); - - /// Create dst, map_x and map_y with the same size as src: - dst.create( src.size(), src.type() ); - map_x.create( src.size(), CV_32FC1 ); - map_y.create( src.size(), CV_32FC1 ); - - /// Create window - namedWindow( remap_window, WINDOW_AUTOSIZE ); - - /// Loop - while( true ) - { - /// Each 1 sec. Press ESC to exit the program - int c = waitKey( 1000 ); - - if( (char)c == 27 ) - { break; } - - /// Update map_x & map_y. Then apply remap - update_map(); - remap( src, dst, map_x, map_y, INTER_LINEAR, BORDER_CONSTANT, Scalar(0,0, 0) ); - - /// Display results - imshow( remap_window, dst ); - } - return 0; -} - -/* -* @function update_map -* @brief Fill the map_x and map_y matrices with 4 types of mappings -*/ -void update_map( void ) -{ - ind = ind%4; - - for( int j = 0; j < src.rows; j++ ) - { for( int i = 0; i < src.cols; i++ ) - { - switch( ind ) - { - case 0: - if( i > src.cols*0.25 && i < src.cols*0.75 && j > src.rows*0.25 && j < src.rows*0.75 ) - { - map_x.at(j,i) = 2*( i - src.cols*0.25 ) + 0.5 ; - map_y.at(j,i) = 2*( j - src.rows*0.25 ) + 0.5 ; - } - else - { map_x.at(j,i) = 0 ; - map_y.at(j,i) = 0 ; - } - break; - case 1: - map_x.at(j,i) = i ; - map_y.at(j,i) = src.rows - j ; - break; - case 2: - map_x.at(j,i) = src.cols - i ; - map_y.at(j,i) = j ; - break; - case 3: - map_x.at(j,i) = src.cols - i ; - map_y.at(j,i) = src.rows - j ; - break; - } // end of switch - } - } - ind++; -@endcode -} + @includelineno samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp Explanation ----------- -1. Create some variables we will use: +-# Create some variables we will use: @code{.cpp} Mat src, dst; Mat map_x, map_y; char* remap_window = "Remap demo"; int ind = 0; @endcode -2. Load an image: +-# Load an image: @code{.cpp} src = imread( argv[1], 1 ); @endcode -3. Create the destination image and the two mapping matrices (for x and y ) +-# Create the destination image and the two mapping matrices (for x and y ) @code{.cpp} dst.create( src.size(), src.type() ); map_x.create( src.size(), CV_32FC1 ); map_y.create( src.size(), CV_32FC1 ); @endcode -4. Create a window to display results +-# Create a window to display results @code{.cpp} namedWindow( remap_window, WINDOW_AUTOSIZE ); @endcode -5. Establish a loop. Each 1000 ms we update our mapping matrices (*mat_x* and *mat_y*) and apply +-# Establish a loop. Each 1000 ms we update our mapping matrices (*mat_x* and *mat_y*) and apply them to our source image: @code{.cpp} while( true ) @@ -205,14 +112,11 @@ Explanation How do we update our mapping matrices *mat_x* and *mat_y*? Go on reading: -6. **Updating the mapping matrices:** We are going to perform 4 different mappings: +-# **Updating the mapping matrices:** We are going to perform 4 different mappings: -# Reduce the picture to half its size and will display it in the middle: - \f[h(i,j) = ( 2*i - src.cols/2 + 0.5, 2*j - src.rows/2 + 0.5)\f] - for all pairs \f$(i,j)\f$ such that: \f$\dfrac{src.cols}{4} -#include - -using namespace cv; -using namespace std; - -/// Global variables -char* source_window = "Source image"; -char* warp_window = "Warp"; -char* warp_rotate_window = "Warp + Rotate"; - -/* @function main */ - int main( int argc, char** argv ) - { - Point2f srcTri[3]; - Point2f dstTri[3]; - - Mat rot_mat( 2, 3, CV_32FC1 ); - Mat warp_mat( 2, 3, CV_32FC1 ); - Mat src, warp_dst, warp_rotate_dst; - - /// Load the image - src = imread( argv[1], 1 ); - - /// Set the dst image the same type and size as src - warp_dst = Mat::zeros( src.rows, src.cols, src.type() ); - - /// Set your 3 points to calculate the Affine Transform - srcTri[0] = Point2f( 0,0 ); - srcTri[1] = Point2f( src.cols - 1, 0 ); - srcTri[2] = Point2f( 0, src.rows - 1 ); - - dstTri[0] = Point2f( src.cols*0.0, src.rows*0.33 ); - dstTri[1] = Point2f( src.cols*0.85, src.rows*0.25 ); - dstTri[2] = Point2f( src.cols*0.15, src.rows*0.7 ); - - /// Get the Affine Transform - warp_mat = getAffineTransform( srcTri, dstTri ); + @includelineno samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp - /// Apply the Affine Transform just found to the src image - warpAffine( src, warp_dst, warp_mat, warp_dst.size() ); - - /* Rotating the image after Warp */ - - /// Compute a rotation matrix with respect to the center of the image - Point center = Point( warp_dst.cols/2, warp_dst.rows/2 ); - double angle = -50.0; - double scale = 0.6; - - /// Get the rotation matrix with the specifications above - rot_mat = getRotationMatrix2D( center, angle, scale ); - - /// Rotate the warped image - warpAffine( warp_dst, warp_rotate_dst, rot_mat, warp_dst.size() ); - - /// Show what you got - namedWindow( source_window, WINDOW_AUTOSIZE ); - imshow( source_window, src ); - - namedWindow( warp_window, WINDOW_AUTOSIZE ); - imshow( warp_window, warp_dst ); - - namedWindow( warp_rotate_window, WINDOW_AUTOSIZE ); - imshow( warp_rotate_window, warp_rotate_dst ); - - /// Wait until user exits the program - waitKey(0); - - return 0; - } -@endcode Explanation ----------- -1. Declare some variables we will use, such as the matrices to store our results and 2 arrays of +-# Declare some variables we will use, such as the matrices to store our results and 2 arrays of points to store the 2D points that define our Affine Transform. @code{.cpp} Point2f srcTri[3]; @@ -173,15 +105,15 @@ Explanation Mat warp_mat( 2, 3, CV_32FC1 ); Mat src, warp_dst, warp_rotate_dst; @endcode -2. Load an image: +-# Load an image: @code{.cpp} src = imread( argv[1], 1 ); @endcode -3. Initialize the destination image as having the same size and type as the source: +-# Initialize the destination image as having the same size and type as the source: @code{.cpp} warp_dst = Mat::zeros( src.rows, src.cols, src.type() ); @endcode -4. **Affine Transform:** As we explained lines above, we need two sets of 3 points to derive the +-# **Affine Transform:** As we explained lines above, we need two sets of 3 points to derive the affine transform relation. Take a look: @code{.cpp} srcTri[0] = Point2f( 0,0 ); @@ -196,14 +128,14 @@ Explanation approximately the same as the ones depicted in the example figure (in the Theory section). You may note that the size and orientation of the triangle defined by the 3 points change. -5. Armed with both sets of points, we calculate the Affine Transform by using OpenCV function @ref +-# Armed with both sets of points, we calculate the Affine Transform by using OpenCV function @ref cv::getAffineTransform : @code{.cpp} warp_mat = getAffineTransform( srcTri, dstTri ); @endcode We get as an output a \f$2 \times 3\f$ matrix (in this case **warp_mat**) -6. We apply the Affine Transform just found to the src image +-# We apply the Affine Transform just found to the src image @code{.cpp} warpAffine( src, warp_dst, warp_mat, warp_dst.size() ); @endcode @@ -217,7 +149,7 @@ Explanation We just got our first transformed image! We will display it in one bit. Before that, we also want to rotate it... -7. **Rotate:** To rotate an image, we need to know two things: +-# **Rotate:** To rotate an image, we need to know two things: -# The center with respect to which the image will rotate -# The angle to be rotated. In OpenCV a positive angle is counter-clockwise @@ -229,16 +161,16 @@ Explanation double angle = -50.0; double scale = 0.6; @endcode -8. We generate the rotation matrix with the OpenCV function @ref cv::getRotationMatrix2D , which +-# We generate the rotation matrix with the OpenCV function @ref cv::getRotationMatrix2D , which returns a \f$2 \times 3\f$ matrix (in this case *rot_mat*) @code{.cpp} rot_mat = getRotationMatrix2D( center, angle, scale ); @endcode -9. We now apply the found rotation to the output of our previous Transformation. +-# We now apply the found rotation to the output of our previous Transformation. @code{.cpp} warpAffine( warp_dst, warp_rotate_dst, rot_mat, warp_dst.size() ); @endcode -10. Finally, we display our results in two windows plus the original image for good measure: +-# Finally, we display our results in two windows plus the original image for good measure: @code{.cpp} namedWindow( source_window, WINDOW_AUTOSIZE ); imshow( source_window, src ); @@ -249,23 +181,24 @@ Explanation namedWindow( warp_rotate_window, WINDOW_AUTOSIZE ); imshow( warp_rotate_window, warp_rotate_dst ); @endcode -11. We just have to wait until the user exits the program +-# We just have to wait until the user exits the program @code{.cpp} waitKey(0); @endcode + Result ------ -1. After compiling the code above, we can give it the path of an image as argument. For instance, +-# After compiling the code above, we can give it the path of an image as argument. For instance, for a picture like: - ![image](images/Warp_Affine_Tutorial_Original_Image.jpg) + ![](images/Warp_Affine_Tutorial_Original_Image.jpg) after applying the first Affine Transform we obtain: - ![image](images/Warp_Affine_Tutorial_Result_Warp.jpg) + ![](images/Warp_Affine_Tutorial_Result_Warp.jpg) and finally, after applying a negative rotation (remember negative means clockwise) and a scale factor, we get: - ![image](images/Warp_Affine_Tutorial_Result_Warp_Rotate.jpg) + ![](images/Warp_Affine_Tutorial_Result_Warp_Rotate.jpg) diff --git a/doc/tutorials/imgproc/opening_closing_hats/images/Morphology_2_Tutorial_Cover.jpg b/doc/tutorials/imgproc/opening_closing_hats/images/Morphology_2_Tutorial_Result.jpg similarity index 100% rename from doc/tutorials/imgproc/opening_closing_hats/images/Morphology_2_Tutorial_Cover.jpg rename to doc/tutorials/imgproc/opening_closing_hats/images/Morphology_2_Tutorial_Result.jpg diff --git a/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.markdown b/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.markdown index d71c59f31a..e1eaed72bf 100644 --- a/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.markdown +++ b/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.markdown @@ -16,8 +16,9 @@ In this tutorial you will learn how to: Theory ------ -@note The explanation below belongs to the book **Learning OpenCV** by Bradski and Kaehler. In the -previous tutorial we covered two basic Morphology operations: +@note The explanation below belongs to the book **Learning OpenCV** by Bradski and Kaehler. + +In the previous tutorial we covered two basic Morphology operations: - Erosion - Dilation. @@ -37,7 +38,7 @@ discuss briefly 05 operations offered by OpenCV: at the right is the result after applying the opening transformation. We can observe that the small spaces in the corners of the letter tend to dissapear. - ![image](images/Morphology_2_Tutorial_Theory_Opening.png) + ![](images/Morphology_2_Tutorial_Theory_Opening.png) ### Closing @@ -47,7 +48,7 @@ discuss briefly 05 operations offered by OpenCV: - Useful to remove small holes (dark regions). - ![image](images/Morphology_2_Tutorial_Theory_Closing.png) + ![](images/Morphology_2_Tutorial_Theory_Closing.png) ### Morphological Gradient @@ -57,7 +58,7 @@ discuss briefly 05 operations offered by OpenCV: - It is useful for finding the outline of an object as can be seen below: - ![image](images/Morphology_2_Tutorial_Theory_Gradient.png) + ![](images/Morphology_2_Tutorial_Theory_Gradient.png) ### Top Hat @@ -65,7 +66,7 @@ discuss briefly 05 operations offered by OpenCV: \f[dst = tophat( src, element ) = src - open( src, element )\f] - ![image](images/Morphology_2_Tutorial_Theory_TopHat.png) + ![](images/Morphology_2_Tutorial_Theory_TopHat.png) ### Black Hat @@ -73,7 +74,7 @@ discuss briefly 05 operations offered by OpenCV: \f[dst = blackhat( src, element ) = close( src, element ) - src\f] - ![image](images/Morphology_2_Tutorial_Theory_BlackHat.png) + ![](images/Morphology_2_Tutorial_Theory_BlackHat.png) Code ---- @@ -150,10 +151,11 @@ void Morphology_Operations( int, void* ) imshow( window_name, dst ); } @endcode + Explanation ----------- -1. Let's check the general structure of the program: +-# Let's check the general structure of the program: - Load an image - Create a window to display results of the Morphological operations - Create 03 Trackbars for the user to enter parameters: @@ -185,17 +187,18 @@ Explanation /* * @function Morphology_Operations */ - @endcode - void Morphology_Operations( int, void\* ) { // Since MORPH_X : 2,3,4,5 and 6 int - operation = morph_operator + 2; - - Mat element = getStructuringElement( morph_elem, Size( 2\*morph_size + 1, - 2\*morph_size+1 ), Point( morph_size, morph_size ) ); - - /// Apply the specified morphology operation morphologyEx( src, dst, operation, element - ); imshow( window_name, dst ); - + void Morphology_Operations( int, void* ) + { + // Since MORPH_X : 2,3,4,5 and 6 + int operation = morph_operator + 2; + + Mat element = getStructuringElement( morph_elem, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) ); + + /// Apply the specified morphology operation + morphologyEx( src, dst, operation, element ); + imshow( window_name, dst ); } + @endcode We can observe that the key function to perform the morphology transformations is @ref cv::morphologyEx . In this example we use four arguments (leaving the rest as defaults): @@ -225,12 +228,10 @@ Results - After compiling the code above we can execute it giving an image path as an argument. For this tutorial we use as input the image: **baboon.png**: - ![image](images/Morphology_2_Tutorial_Original_Image.jpg) + ![](images/Morphology_2_Tutorial_Original_Image.jpg) - And here are two snapshots of the display window. The first picture shows the output after using the operator **Opening** with a cross kernel. The second picture (right side, shows the result of using a **Blackhat** operator with an ellipse kernel. - ![image](images/Morphology_2_Tutorial_Cover.jpg) - - + ![](images/Morphology_2_Tutorial_Result.jpg) diff --git a/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.rst b/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.rst index facb077897..e533933b67 100644 --- a/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.rst +++ b/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.rst @@ -276,6 +276,6 @@ Results * And here are two snapshots of the display window. The first picture shows the output after using the operator **Opening** with a cross kernel. The second picture (right side, shows the result of using a **Blackhat** operator with an ellipse kernel. - .. image:: images/Morphology_2_Tutorial_Cover.jpg + .. image:: images/Morphology_2_Tutorial_Result.jpg :alt: Morphology 2: Result sample :align: center diff --git a/doc/tutorials/imgproc/pyramids/pyramids.markdown b/doc/tutorials/imgproc/pyramids/pyramids.markdown index 690babd614..7feddfc5b2 100644 --- a/doc/tutorials/imgproc/pyramids/pyramids.markdown +++ b/doc/tutorials/imgproc/pyramids/pyramids.markdown @@ -16,8 +16,8 @@ Theory - Usually we need to convert an image to a size different than its original. For this, there are two possible options: - 1. *Upsize* the image (zoom in) or - 2. *Downsize* it (zoom out). + -# *Upsize* the image (zoom in) or + -# *Downsize* it (zoom out). - Although there is a *geometric transformation* function in OpenCV that -literally- resize an image (@ref cv::resize , which we will show in a future tutorial), in this section we analyze first the use of **Image Pyramids**, which are widely applied in a huge range of vision @@ -37,7 +37,7 @@ Theory - Imagine the pyramid as a set of layers in which the higher the layer, the smaller the size. - ![image](images/Pyramids_Tutorial_Pyramid_Theory.png) + ![](images/Pyramids_Tutorial_Pyramid_Theory.png) - Every layer is numbered from bottom to top, so layer \f$(i+1)\f$ (denoted as \f$G_{i+1}\f$ is smaller than layer \f$i\f$ (\f$G_{i}\f$). @@ -162,14 +162,14 @@ Results that comes in the *tutorial_code/image* folder. Notice that this image is \f$512 \times 512\f$, hence a downsample won't generate any error (\f$512 = 2^{9}\f$). The original image is shown below: - ![image](images/Pyramids_Tutorial_Original_Image.jpg) + ![](images/Pyramids_Tutorial_Original_Image.jpg) - First we apply two successive @ref cv::pyrDown operations by pressing 'd'. Our output is: - ![image](images/Pyramids_Tutorial_PyrDown_Result.jpg) + ![](images/Pyramids_Tutorial_PyrDown_Result.jpg) - Note that we should have lost some resolution due to the fact that we are diminishing the size of the image. This is evident after we apply @ref cv::pyrUp twice (by pressing 'u'). Our output is now: - ![image](images/Pyramids_Tutorial_PyrUp_Result.jpg) + ![](images/Pyramids_Tutorial_PyrUp_Result.jpg) diff --git a/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.markdown b/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.markdown index c753db82fe..bdf4a79c2b 100644 --- a/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.markdown +++ b/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.markdown @@ -17,96 +17,14 @@ Code This tutorial code's is shown lines below. You can also download it from [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo1.cpp) -@code{.cpp} -#include "opencv2/highgui.hpp" -#include "opencv2/imgproc.hpp" -#include -#include -#include +@includelineno samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo1.cpp -using namespace cv; -using namespace std; - -Mat src; Mat src_gray; -int thresh = 100; -int max_thresh = 255; -RNG rng(12345); - -/// Function header -void thresh_callback(int, void* ); - -/* @function main */ -int main( int argc, char** argv ) -{ - /// Load source image and convert it to gray - src = imread( argv[1], 1 ); - - /// Convert image to gray and blur it - cvtColor( src, src_gray, COLOR_BGR2GRAY ); - blur( src_gray, src_gray, Size(3,3) ); - - /// Create Window - char* source_window = "Source"; - namedWindow( source_window, WINDOW_AUTOSIZE ); - imshow( source_window, src ); - - createTrackbar( " Threshold:", "Source", &thresh, max_thresh, thresh_callback ); - thresh_callback( 0, 0 ); - - waitKey(0); - return(0); -} - -/* @function thresh_callback */ -void thresh_callback(int, void* ) -{ - Mat threshold_output; - vector > contours; - vector hierarchy; - - /// Detect edges using Threshold - threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY ); - /// Find contours - findContours( threshold_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) ); - - /// Approximate contours to polygons + get bounding rects and circles - vector > contours_poly( contours.size() ); - vector boundRect( contours.size() ); - vectorcenter( contours.size() ); - vectorradius( contours.size() ); - - for( int i = 0; i < contours.size(); i++ ) - { approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true ); - boundRect[i] = boundingRect( Mat(contours_poly[i]) ); - minEnclosingCircle( (Mat)contours_poly[i], center[i], radius[i] ); - } - - - /// Draw polygonal contour + bonding rects + circles - Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 ); - for( int i = 0; i< contours.size(); i++ ) - { - Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) ); - drawContours( drawing, contours_poly, i, color, 1, 8, vector(), 0, Point() ); - rectangle( drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0 ); - circle( drawing, center[i], (int)radius[i], color, 2, 8, 0 ); - } - - /// Show in a window - namedWindow( "Contours", WINDOW_AUTOSIZE ); - imshow( "Contours", drawing ); -} -@endcode Explanation ----------- Result ------ -1. Here it is: - - ---------- ---------- - |BRC_0| |BRC_1| - ---------- ---------- - - +Here it is: +![](images/Bounding_Rects_Circles_Source_Image.jpg) +![](images/Bounding_Rects_Circles_Result.jpg) diff --git a/doc/tutorials/imgproc/shapedescriptors/bounding_rotated_ellipses/bounding_rotated_ellipses.markdown b/doc/tutorials/imgproc/shapedescriptors/bounding_rotated_ellipses/bounding_rotated_ellipses.markdown index b8d2c9e6ab..b622d4616b 100644 --- a/doc/tutorials/imgproc/shapedescriptors/bounding_rotated_ellipses/bounding_rotated_ellipses.markdown +++ b/doc/tutorials/imgproc/shapedescriptors/bounding_rotated_ellipses/bounding_rotated_ellipses.markdown @@ -17,98 +17,14 @@ Code This tutorial code's is shown lines below. You can also download it from [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo2.cpp) -@code{.cpp} -#include "opencv2/highgui.hpp" -#include "opencv2/imgproc.hpp" -#include -#include -#include +@includelineno samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo2.cpp -using namespace cv; -using namespace std; - -Mat src; Mat src_gray; -int thresh = 100; -int max_thresh = 255; -RNG rng(12345); - -/// Function header -void thresh_callback(int, void* ); - -/* @function main */ -int main( int argc, char** argv ) -{ - /// Load source image and convert it to gray - src = imread( argv[1], 1 ); - - /// Convert image to gray and blur it - cvtColor( src, src_gray, COLOR_BGR2GRAY ); - blur( src_gray, src_gray, Size(3,3) ); - - /// Create Window - char* source_window = "Source"; - namedWindow( source_window, WINDOW_AUTOSIZE ); - imshow( source_window, src ); - - createTrackbar( " Threshold:", "Source", &thresh, max_thresh, thresh_callback ); - thresh_callback( 0, 0 ); - - waitKey(0); - return(0); -} - -/* @function thresh_callback */ -void thresh_callback(int, void* ) -{ - Mat threshold_output; - vector > contours; - vector hierarchy; - - /// Detect edges using Threshold - threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY ); - /// Find contours - findContours( threshold_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) ); - - /// Find the rotated rectangles and ellipses for each contour - vector minRect( contours.size() ); - vector minEllipse( contours.size() ); - - for( int i = 0; i < contours.size(); i++ ) - { minRect[i] = minAreaRect( Mat(contours[i]) ); - if( contours[i].size() > 5 ) - { minEllipse[i] = fitEllipse( Mat(contours[i]) ); } - } - - /// Draw contours + rotated rects + ellipses - Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 ); - for( int i = 0; i< contours.size(); i++ ) - { - Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) ); - // contour - drawContours( drawing, contours, i, color, 1, 8, vector(), 0, Point() ); - // ellipse - ellipse( drawing, minEllipse[i], color, 2, 8 ); - // rotated rectangle - Point2f rect_points[4]; minRect[i].points( rect_points ); - for( int j = 0; j < 4; j++ ) - line( drawing, rect_points[j], rect_points[(j+1)%4], color, 1, 8 ); - } - - /// Show in a window - namedWindow( "Contours", WINDOW_AUTOSIZE ); - imshow( "Contours", drawing ); -} -@endcode Explanation ----------- Result ------ -1. Here it is: - - ---------- ---------- - |BRE_0| |BRE_1| - ---------- ---------- - - +Here it is: +![](images/Bounding_Rotated_Ellipses_Source_Image.jpg) +![](images/Bounding_Rotated_Ellipses_Result.jpg) diff --git a/doc/tutorials/imgproc/shapedescriptors/find_contours/find_contours.markdown b/doc/tutorials/imgproc/shapedescriptors/find_contours/find_contours.markdown index df6e7ccd22..b552f9d0d9 100644 --- a/doc/tutorials/imgproc/shapedescriptors/find_contours/find_contours.markdown +++ b/doc/tutorials/imgproc/shapedescriptors/find_contours/find_contours.markdown @@ -17,81 +17,14 @@ Code This tutorial code's is shown lines below. You can also download it from [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp) -@code{.cpp} -#include "opencv2/highgui.hpp" -#include "opencv2/imgproc.hpp" -#include -#include -#include +@includelineno samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp -using namespace cv; -using namespace std; - -Mat src; Mat src_gray; -int thresh = 100; -int max_thresh = 255; -RNG rng(12345); - -/// Function header -void thresh_callback(int, void* ); - -/* @function main */ -int main( int argc, char** argv ) -{ - /// Load source image and convert it to gray - src = imread( argv[1], 1 ); - - /// Convert image to gray and blur it - cvtColor( src, src_gray, COLOR_BGR2GRAY ); - blur( src_gray, src_gray, Size(3,3) ); - - /// Create Window - char* source_window = "Source"; - namedWindow( source_window, WINDOW_AUTOSIZE ); - imshow( source_window, src ); - - createTrackbar( " Canny thresh:", "Source", &thresh, max_thresh, thresh_callback ); - thresh_callback( 0, 0 ); - - waitKey(0); - return(0); -} - -/* @function thresh_callback */ -void thresh_callback(int, void* ) -{ - Mat canny_output; - vector > contours; - vector hierarchy; - - /// Detect edges using canny - Canny( src_gray, canny_output, thresh, thresh*2, 3 ); - /// Find contours - findContours( canny_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) ); - - /// Draw contours - Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 ); - for( int i = 0; i< contours.size(); i++ ) - { - Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) ); - drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() ); - } - - /// Show in a window - namedWindow( "Contours", WINDOW_AUTOSIZE ); - imshow( "Contours", drawing ); -} -@endcode Explanation ----------- Result ------ -1. Here it is: - - -------------- -------------- - |contour_0| |contour_1| - -------------- -------------- - - +Here it is: +![](images/Find_Contours_Original_Image.jpg) +![](images/Find_Contours_Result.jpg) diff --git a/doc/tutorials/imgproc/shapedescriptors/moments/moments.markdown b/doc/tutorials/imgproc/shapedescriptors/moments/moments.markdown index f2b4e3f736..daf34e0d5d 100644 --- a/doc/tutorials/imgproc/shapedescriptors/moments/moments.markdown +++ b/doc/tutorials/imgproc/shapedescriptors/moments/moments.markdown @@ -18,102 +18,15 @@ Code This tutorial code's is shown lines below. You can also download it from [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ShapeDescriptors/moments_demo.cpp) -@code{.cpp} -#include "opencv2/highgui.hpp" -#include "opencv2/imgproc.hpp" -#include -#include -#include +@includelineno samples/cpp/tutorial_code/ShapeDescriptors/moments_demo.cpp -using namespace cv; -using namespace std; - -Mat src; Mat src_gray; -int thresh = 100; -int max_thresh = 255; -RNG rng(12345); - -/// Function header -void thresh_callback(int, void* ); - -/* @function main */ -int main( int argc, char** argv ) -{ - /// Load source image and convert it to gray - src = imread( argv[1], 1 ); - - /// Convert image to gray and blur it - cvtColor( src, src_gray, COLOR_BGR2GRAY ); - blur( src_gray, src_gray, Size(3,3) ); - - /// Create Window - char* source_window = "Source"; - namedWindow( source_window, WINDOW_AUTOSIZE ); - imshow( source_window, src ); - - createTrackbar( " Canny thresh:", "Source", &thresh, max_thresh, thresh_callback ); - thresh_callback( 0, 0 ); - - waitKey(0); - return(0); -} - -/* @function thresh_callback */ -void thresh_callback(int, void* ) -{ - Mat canny_output; - vector > contours; - vector hierarchy; - - /// Detect edges using canny - Canny( src_gray, canny_output, thresh, thresh*2, 3 ); - /// Find contours - findContours( canny_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) ); - - /// Get the moments - vector mu(contours.size() ); - for( int i = 0; i < contours.size(); i++ ) - { mu[i] = moments( contours[i], false ); } - - /// Get the mass centers: - vector mc( contours.size() ); - for( int i = 0; i < contours.size(); i++ ) - { mc[i] = Point2f( mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 ); } - - /// Draw contours - Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 ); - for( int i = 0; i< contours.size(); i++ ) - { - Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) ); - drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() ); - circle( drawing, mc[i], 4, color, -1, 8, 0 ); - } - - /// Show in a window - namedWindow( "Contours", WINDOW_AUTOSIZE ); - imshow( "Contours", drawing ); - - /// Calculate the area with the moments 00 and compare with the result of the OpenCV function - printf("\t Info: Area and Contour Length \n"); - for( int i = 0; i< contours.size(); i++ ) - { - printf(" * Contour[%d] - Area (M_00) = %.2f - Area OpenCV: %.2f - Length: %.2f \n", i, mu[i].m00, contourArea(contours[i]), arcLength( contours[i], true ) ); - Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) ); - drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() ); - circle( drawing, mc[i], 4, color, -1, 8, 0 ); - } -} -@endcode Explanation ----------- Result ------ -1. Here it is: - - --------- --------- --------- - |MU_0| |MU_1| |MU_2| - --------- --------- --------- - - +Here it is: +![](images/Moments_Source_Image.jpg) +![](images/Moments_Result1.jpg) +![](images/Moments_Result2.jpg) diff --git a/doc/tutorials/imgproc/shapedescriptors/point_polygon_test/point_polygon_test.markdown b/doc/tutorials/imgproc/shapedescriptors/point_polygon_test/point_polygon_test.markdown index 8dbc1a120f..db9780a6ee 100644 --- a/doc/tutorials/imgproc/shapedescriptors/point_polygon_test/point_polygon_test.markdown +++ b/doc/tutorials/imgproc/shapedescriptors/point_polygon_test/point_polygon_test.markdown @@ -16,91 +16,14 @@ Code This tutorial code's is shown lines below. You can also download it from [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ShapeDescriptors/pointPolygonTest_demo.cpp) -@code{.cpp} -#include "opencv2/highgui.hpp" -#include "opencv2/imgproc.hpp" -#include -#include -#include +@includelineno samples/cpp/tutorial_code/ShapeDescriptors/pointPolygonTest_demo.cpp -using namespace cv; -using namespace std; - -/* @function main */ -int main( int argc, char** argv ) -{ - /// Create an image - const int r = 100; - Mat src = Mat::zeros( Size( 4*r, 4*r ), CV_8UC1 ); - - /// Create a sequence of points to make a contour: - vector vert(6); - - vert[0] = Point( 1.5*r, 1.34*r ); - vert[1] = Point( 1*r, 2*r ); - vert[2] = Point( 1.5*r, 2.866*r ); - vert[3] = Point( 2.5*r, 2.866*r ); - vert[4] = Point( 3*r, 2*r ); - vert[5] = Point( 2.5*r, 1.34*r ); - - /// Draw it in src - for( int j = 0; j < 6; j++ ) - { line( src, vert[j], vert[(j+1)%6], Scalar( 255 ), 3, 8 ); } - - /// Get the contours - vector > contours; vector hierarchy; - Mat src_copy = src.clone(); - - findContours( src_copy, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE); - - /// Calculate the distances to the contour - Mat raw_dist( src.size(), CV_32FC1 ); - - for( int j = 0; j < src.rows; j++ ) - { for( int i = 0; i < src.cols; i++ ) - { raw_dist.at(j,i) = pointPolygonTest( contours[0], Point2f(i,j), true ); } - } - - double minVal; double maxVal; - minMaxLoc( raw_dist, &minVal, &maxVal, 0, 0, Mat() ); - minVal = abs(minVal); maxVal = abs(maxVal); - - /// Depicting the distances graphically - Mat drawing = Mat::zeros( src.size(), CV_8UC3 ); - - for( int j = 0; j < src.rows; j++ ) - { for( int i = 0; i < src.cols; i++ ) - { - if( raw_dist.at(j,i) < 0 ) - { drawing.at(j,i)[0] = 255 - (int) abs(raw_dist.at(j,i))*255/minVal; } - else if( raw_dist.at(j,i) > 0 ) - { drawing.at(j,i)[2] = 255 - (int) raw_dist.at(j,i)*255/maxVal; } - else - { drawing.at(j,i)[0] = 255; drawing.at(j,i)[1] = 255; drawing.at(j,i)[2] = 255; } - } - } - - /// Create Window and show your results - char* source_window = "Source"; - namedWindow( source_window, WINDOW_AUTOSIZE ); - imshow( source_window, src ); - namedWindow( "Distance", WINDOW_AUTOSIZE ); - imshow( "Distance", drawing ); - - waitKey(0); - return(0); -} -@endcode Explanation ----------- Result ------ -1. Here it is: - - ---------- ---------- - |PPT_0| |PPT_1| - ---------- ---------- - - +Here it is: +![](images/Point_Polygon_Test_Source_Image.png) +![](images/Point_Polygon_Test_Result.jpg) diff --git a/doc/tutorials/imgproc/threshold/threshold.markdown b/doc/tutorials/imgproc/threshold/threshold.markdown index 1800b670b9..7b50046650 100644 --- a/doc/tutorials/imgproc/threshold/threshold.markdown +++ b/doc/tutorials/imgproc/threshold/threshold.markdown @@ -12,7 +12,9 @@ Cool Theory ----------- @note The explanation below belongs to the book **Learning OpenCV** by Bradski and Kaehler. What is -Thresholding? ----------------------- + +Thresholding? +------------- - The simplest segmentation method - Application example: Separate out regions of an image corresponding to objects which we want to @@ -25,7 +27,7 @@ Thresholding? ----------------------- identify them (i.e. we can assign them a value of \f$0\f$ (black), \f$255\f$ (white) or any value that suits your needs). - ![image](images/Threshold_Tutorial_Theory_Example.jpg) + ![](images/Threshold_Tutorial_Theory_Example.jpg) ### Types of Thresholding @@ -36,7 +38,7 @@ Thresholding? ----------------------- with pixels with intensity values \f$src(x,y)\f$. The plot below depicts this. The horizontal blue line represents the threshold \f$thresh\f$ (fixed). - ![image](images/Threshold_Tutorial_Theory_Base_Figure.png) + ![](images/Threshold_Tutorial_Theory_Base_Figure.png) #### Threshold Binary @@ -47,7 +49,7 @@ Thresholding? ----------------------- - So, if the intensity of the pixel \f$src(x,y)\f$ is higher than \f$thresh\f$, then the new pixel intensity is set to a \f$MaxVal\f$. Otherwise, the pixels are set to \f$0\f$. - ![image](images/Threshold_Tutorial_Theory_Binary.png) + ![](images/Threshold_Tutorial_Theory_Binary.png) #### Threshold Binary, Inverted @@ -58,7 +60,7 @@ Thresholding? ----------------------- - If the intensity of the pixel \f$src(x,y)\f$ is higher than \f$thresh\f$, then the new pixel intensity is set to a \f$0\f$. Otherwise, it is set to \f$MaxVal\f$. - ![image](images/Threshold_Tutorial_Theory_Binary_Inverted.png) + ![](images/Threshold_Tutorial_Theory_Binary_Inverted.png) #### Truncate @@ -69,7 +71,7 @@ Thresholding? ----------------------- - The maximum intensity value for the pixels is \f$thresh\f$, if \f$src(x,y)\f$ is greater, then its value is *truncated*. See figure below: - ![image](images/Threshold_Tutorial_Theory_Truncate.png) + ![](images/Threshold_Tutorial_Theory_Truncate.png) #### Threshold to Zero @@ -79,7 +81,7 @@ Thresholding? ----------------------- - If \f$src(x,y)\f$ is lower than \f$thresh\f$, the new pixel value will be set to \f$0\f$. - ![image](images/Threshold_Tutorial_Theory_Zero.png) + ![](images/Threshold_Tutorial_Theory_Zero.png) #### Threshold to Zero, Inverted @@ -89,97 +91,19 @@ Thresholding? ----------------------- - If \f$src(x,y)\f$ is greater than \f$thresh\f$, the new pixel value will be set to \f$0\f$. - ![image](images/Threshold_Tutorial_Theory_Zero_Inverted.png) + ![](images/Threshold_Tutorial_Theory_Zero_Inverted.png) Code ---- The tutorial code's is shown lines below. You can also download it from [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ImgProc/Threshold.cpp) -@code{.cpp} -#include "opencv2/imgproc.hpp" -#include "opencv2/highgui.hpp" -#include -#include - -using namespace cv; - -/// Global variables - -int threshold_value = 0; -int threshold_type = 3;; -int const max_value = 255; -int const max_type = 4; -int const max_BINARY_value = 255; - -Mat src, src_gray, dst; -char* window_name = "Threshold Demo"; - -char* trackbar_type = "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted"; -char* trackbar_value = "Value"; - -/// Function headers -void Threshold_Demo( int, void* ); - -/* - * @function main - */ -int main( int argc, char** argv ) -{ - /// Load an image - src = imread( argv[1], 1 ); - - /// Convert the image to Gray - cvtColor( src, src_gray, COLOR_RGB2GRAY ); - - /// Create a window to display results - namedWindow( window_name, WINDOW_AUTOSIZE ); - - /// Create Trackbar to choose type of Threshold - createTrackbar( trackbar_type, - window_name, &threshold_type, - max_type, Threshold_Demo ); - - createTrackbar( trackbar_value, - window_name, &threshold_value, - max_value, Threshold_Demo ); - - /// Call the function to initialize - Threshold_Demo( 0, 0 ); - - /// Wait until user finishes program - while(true) - { - int c; - c = waitKey( 20 ); - if( (char)c == 27 ) - { break; } - } - -} - - -/* - * @function Threshold_Demo - */ -void Threshold_Demo( int, void* ) -{ - /* 0: Binary - 1: Binary Inverted - 2: Threshold Truncated - 3: Threshold to Zero - 4: Threshold to Zero Inverted - */ - - threshold( src_gray, dst, threshold_value, max_BINARY_value,threshold_type ); - - imshow( window_name, dst ); -} -@endcode +@includelineno samples/cpp/tutorial_code/ImgProc/Threshold.cpp + Explanation ----------- -1. Let's check the general structure of the program: +-# Let's check the general structure of the program: - Load an image. If it is RGB we convert it to Grayscale. For this, remember that we can use the function @ref cv::cvtColor : @code{.cpp} @@ -241,23 +165,21 @@ Explanation Results ------- -1. After compiling this program, run it giving a path to an image as argument. For instance, for an +-# After compiling this program, run it giving a path to an image as argument. For instance, for an input image as: - ![image](images/Threshold_Tutorial_Original_Image.jpg) + ![](images/Threshold_Tutorial_Original_Image.jpg) -2. First, we try to threshold our image with a *binary threhold inverted*. We expect that the +-# First, we try to threshold our image with a *binary threhold inverted*. We expect that the pixels brighter than the \f$thresh\f$ will turn dark, which is what actually happens, as we can see in the snapshot below (notice from the original image, that the doggie's tongue and eyes are particularly bright in comparison with the image, this is reflected in the output image). - ![image](images/Threshold_Tutorial_Result_Binary_Inverted.jpg) + ![](images/Threshold_Tutorial_Result_Binary_Inverted.jpg) -3. Now we try with the *threshold to zero*. With this, we expect that the darkest pixels (below the +-# Now we try with the *threshold to zero*. With this, we expect that the darkest pixels (below the threshold) will become completely black, whereas the pixels with value greater than the threshold will keep its original value. This is verified by the following snapshot of the output image: - ![image](images/Threshold_Tutorial_Result_Zero.jpg) - - + ![](images/Threshold_Tutorial_Result_Zero.jpg) diff --git a/doc/tutorials/introduction/android_binary_package/O4A_SDK.markdown b/doc/tutorials/introduction/android_binary_package/O4A_SDK.markdown index ab9cfbff31..d123c697f6 100644 --- a/doc/tutorials/introduction/android_binary_package/O4A_SDK.markdown +++ b/doc/tutorials/introduction/android_binary_package/O4A_SDK.markdown @@ -107,19 +107,19 @@ Manual OpenCV4Android SDK setup ### Get the OpenCV4Android SDK -1. Go to the [OpenCV download page on +-# Go to the [OpenCV download page on SourceForge](http://sourceforge.net/projects/opencvlibrary/files/opencv-android/) and download the latest available version. Currently it's [OpenCV-2.4.9-android-sdk.zip](http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.9/OpenCV-2.4.9-android-sdk.zip/download). -2. Create a new folder for Android with OpenCV development. For this tutorial we have unpacked +-# Create a new folder for Android with OpenCV development. For this tutorial we have unpacked OpenCV SDK to the `C:\Work\OpenCV4Android\` directory. @note Better to use a path without spaces in it. Otherwise you may have problems with ndk-build. -3. Unpack the SDK archive into the chosen directory. +-# Unpack the SDK archive into the chosen directory. - You can unpack it using any popular archiver (e.g with 7-Zip_): + You can unpack it using any popular archiver (e.g with 7-Zip): - ![image](images/android_package_7zip.png) + ![](images/android_package_7zip.png) On Unix you can use the following command: @code{.bash} @@ -128,15 +128,15 @@ Manual OpenCV4Android SDK setup ### Import OpenCV library and samples to the Eclipse -1. Start Eclipse and choose your workspace location. +-# Start Eclipse and choose your workspace location. We recommend to start working with OpenCV for Android from a new clean workspace. A new Eclipse workspace can for example be created in the folder where you have unpacked OpenCV4Android SDK package: - ![image](images/eclipse_1_choose_workspace.png) + ![](images/eclipse_1_choose_workspace.png) -2. Import OpenCV library and samples into workspace. +-# Import OpenCV library and samples into workspace. OpenCV library is packed as a ready-for-use [Android Library Project](http://developer.android.com/guide/developing/projects/index.html#LibraryProjects). You @@ -146,33 +146,34 @@ Manual OpenCV4Android SDK setup already references OpenCV library. Follow the steps below to import OpenCV and samples into the workspace: - @note OpenCV samples are indeed **dependent** on OpenCV library project so don't forget to import it to your workspace as well. - - Right click on the Package Explorer window and choose Import... option from the context - menu: + - Right click on the Package Explorer window and choose Import... option from the context + menu: + + ![](images/eclipse_5_import_command.png) - ![image](images/eclipse_5_import_command.png) + - In the main panel select General --\> Existing Projects into Workspace and press Next + button: - - In the main panel select General --\> Existing Projects into Workspace and press Next - button: + ![](images/eclipse_6_import_existing_projects.png) - ![image](images/eclipse_6_import_existing_projects.png) + - In the Select root directory field locate your OpenCV package folder. Eclipse should + automatically locate OpenCV library and samples: - - In the Select root directory field locate your OpenCV package folder. Eclipse should - automatically locate OpenCV library and samples: + ![](images/eclipse_7_select_projects.png) - ![image](images/eclipse_7_select_projects.png) + - Click Finish button to complete the import operation. - - Click Finish button to complete the import operation. + @note OpenCV samples are indeed **dependent** on OpenCV library project so don't forget to import it to your workspace as well. After clicking Finish button Eclipse will load all selected projects into workspace, and you have to wait some time while it is building OpenCV samples. Just give a minute to Eclipse to complete initialization. - ![image](images/eclipse_cdt_cfg4.png) + ![](images/eclipse_cdt_cfg4.png) Once Eclipse completes build you will have the clean workspace without any build errors: - ![image](images/eclipse_10_crystal_clean.png) + ![](images/eclipse_10_crystal_clean.png) @anchor tutorial_O4A_SDK_samples ### Running OpenCV Samples @@ -205,7 +206,7 @@ Well, running samples from Eclipse is very simple: @note Android Emulator can take several minutes to start. So, please, be patient. \* On the first run Eclipse will ask you about the running mode for your application: - ![image](images/eclipse_11_run_as.png) + ![](images/eclipse_11_run_as.png) - Select the Android Application option and click OK button. Eclipse will install and run the sample. @@ -214,7 +215,7 @@ Well, running samples from Eclipse is very simple: Manager](https://docs.google.com/a/itseez.com/presentation/d/1EO_1kijgBg_BsjNp2ymk-aarg-0K279_1VZRcPplSuk/present#slide=id.p) package installed. In this case you will see the following message: - ![image](images/android_emulator_opencv_manager_fail.png) + ![](images/android_emulator_opencv_manager_fail.png) To get rid of the message you will need to install OpenCV Manager and the appropriate OpenCV binary pack. Simply tap Yes if you have *Google Play Market* installed on your @@ -226,12 +227,15 @@ Well, running samples from Eclipse is very simple: @code{.sh} /platform-tools/adb install /apk/OpenCV_2.4.9_Manager_2.18_armv7a-neon.apk @endcode + @note armeabi, armv7a-neon, arm7a-neon-android8, mips and x86 stand for platform targets: - armeabi is for ARM v5 and ARM v6 architectures with Android API 8+, - armv7a-neon is for NEON-optimized ARM v7 with Android API 9+, - arm7a-neon-android8 is for NEON-optimized ARM v7 with Android API 8, - mips is for MIPS architecture with Android API 9+, - x86 is for Intel x86 CPUs with Android API 9+. + + @note If using hardware device for testing/debugging, run the following command to learn its CPU architecture: @code{.sh} @@ -241,6 +245,7 @@ Well, running samples from Eclipse is very simple: Click Edit in the context menu of the selected device. In the window, which then pop-ups, find the CPU field. + @note You may also see section `Manager Selection` for details. When done, you will be able to run OpenCV samples on your device/emulator seamlessly. @@ -248,7 +253,7 @@ Well, running samples from Eclipse is very simple: - Here is Sample - image-manipulations sample, running on top of stock camera-preview of the emulator. - ![image](images/emulator_canny.png) + ![](images/emulator_canny.png) What's next ----------- diff --git a/doc/tutorials/introduction/android_binary_package/android_dev_intro.markdown b/doc/tutorials/introduction/android_binary_package/android_dev_intro.markdown index 2da472b8b2..1146772c14 100644 --- a/doc/tutorials/introduction/android_binary_package/android_dev_intro.markdown +++ b/doc/tutorials/introduction/android_binary_package/android_dev_intro.markdown @@ -19,16 +19,16 @@ Development for Android significantly differs from development for other platfor starting programming for Android we recommend you make sure that you are familiar with the following key topis: -1. [Java](http://en.wikipedia.org/wiki/Java_(programming_language)) programming language that is +-# [Java](http://en.wikipedia.org/wiki/Java_(programming_language)) programming language that is the primary development technology for Android OS. Also, you can find [Oracle docs on Java](http://docs.oracle.com/javase/) useful. -2. [Java Native Interface (JNI)](http://en.wikipedia.org/wiki/Java_Native_Interface) that is a +-# [Java Native Interface (JNI)](http://en.wikipedia.org/wiki/Java_Native_Interface) that is a technology of running native code in Java virtual machine. Also, you can find [Oracle docs on JNI](http://docs.oracle.com/javase/7/docs/technotes/guides/jni/) useful. -3. [Android +-# [Android Activity](http://developer.android.com/training/basics/activity-lifecycle/starting.html) and its lifecycle, that is an essential Android API class. -4. OpenCV development will certainly require some knowlege of the [Android +-# OpenCV development will certainly require some knowlege of the [Android Camera](http://developer.android.com/guide/topics/media/camera.html) specifics. Quick environment setup for Android development @@ -44,14 +44,15 @@ environment setup automatically and you can skip the rest of the guide. If you are a beginner in Android development then we also recommend you to start with TADP. -@note *NVIDIA*'s Tegra Android Development Pack includes some special features for *NVIDIA*’s Tegra -platform_ but its use is not limited to *Tegra* devices only. \* You need at least *1.6 Gb* free +@note *NVIDIA*'s Tegra Android Development Pack includes some special features for *NVIDIA*’s [Tegra +platform](http://www.nvidia.com/object/tegra-3-processor.html) +but its use is not limited to *Tegra* devices only. \* You need at least *1.6 Gb* free disk space for the install. - TADP will download Android SDK platforms and Android NDK from Google's server, so Internet connection is required for the installation. - TADP may ask you to flash your development kit at the end of installation process. Just skip - this step if you have no Tegra Development Kit_. + this step if you have no [Tegra Development Kit](http://developer.nvidia.com/mobile/tegra-hardware-sales-inquiries). - (UNIX) TADP will ask you for *root* in the middle of installation, so you need to be a member of *sudo* group. @@ -62,7 +63,7 @@ Manual environment setup for Android development You need the following software to be installed in order to develop for Android in Java: -1. **Sun JDK 6** (Sun JDK 7 is also possible) +-# **Sun JDK 6** (Sun JDK 7 is also possible) Visit [Java SE Downloads page](http://www.oracle.com/technetwork/java/javase/downloads/) and download an installer for your OS. @@ -71,30 +72,32 @@ You need the following software to be installed in order to develop for Android guide](http://source.android.com/source/initializing.html#installing-the-jdk) for Ubuntu and Mac OS (only JDK sections are applicable for OpenCV) -@note OpenJDK is not suitable for Android development, since Android SDK supports only Sun JDK. If you use Ubuntu, after installation of Sun JDK you should run the following command to set Sun java environment: - @code{.bash} - sudo update-java-alternatives --set java-6-sun - @endcode -1. **Android SDK** + @note OpenJDK is not suitable for Android development, since Android SDK supports only Sun JDK. If you use Ubuntu, after installation of Sun JDK you should run the following command to set Sun java environment: + @code{.bash} + sudo update-java-alternatives --set java-6-sun + @endcode + +-# **Android SDK** Get the latest Android SDK from Here is Google's [install guide](http://developer.android.com/sdk/installing.html) for the SDK. -@note You can choose downloading **ADT Bundle package** that in addition to Android SDK Tools -includes Eclipse + ADT + NDK/CDT plugins, Android Platform-tools, the latest Android platform and -the latest Android system image for the emulator - this is the best choice for those who is setting -up Android development environment the first time! + @note You can choose downloading **ADT Bundle package** that in addition to Android SDK Tools + includes Eclipse + ADT + NDK/CDT plugins, Android Platform-tools, the latest Android platform and + the latest Android system image for the emulator - this is the best choice for those who is setting + up Android development environment the first time! -@note If you are running x64 version of Ubuntu Linux, then you need ia32 shared libraries for use on amd64 and ia64 systems to be installed. You can install them with the following command: - @code{.bash} - sudo apt-get install ia32-libs - @endcode - For Red Hat based systems the following command might be helpful: - @code{.bash} - sudo yum install libXtst.i386 - @endcode -1. **Android SDK components** + @note If you are running x64 version of Ubuntu Linux, then you need ia32 shared libraries for use on amd64 and ia64 systems to be installed. You can install them with the following command: + @code{.bash} + sudo apt-get install ia32-libs + @endcode + For Red Hat based systems the following command might be helpful: + @code{.bash} + sudo yum install libXtst.i386 + @endcode + +-# **Android SDK components** You need the following SDK components to be installed: @@ -110,13 +113,13 @@ up Android development environment the first time! successful compilation the **target** platform should be set to Android 3.0 (API 11) or higher. It will not prevent them from running on Android 2.2. - ![image](images/android_sdk_and_avd_manager.png) + ![](images/android_sdk_and_avd_manager.png) See [Adding Platforms and Packages](http://developer.android.com/sdk/installing/adding-packages.html) for help with installing/updating SDK components. -2. **Eclipse IDE** +-# **Eclipse IDE** Check the [Android SDK System Requirements](http://developer.android.com/sdk/requirements.html) document for a list of Eclipse versions that are compatible with the Android SDK. For OpenCV @@ -126,7 +129,7 @@ up Android development environment the first time! If you have no Eclipse installed, you can get it from the [official site](http://www.eclipse.org/downloads/). -3. **ADT plugin for Eclipse** +-# **ADT plugin for Eclipse** These instructions are copied from [Android Developers site](http://developer.android.com/sdk/installing/installing-adt.html), check it out in case of @@ -135,33 +138,34 @@ up Android development environment the first time! Assuming that you have Eclipse IDE installed, as described above, follow these steps to download and install the ADT plugin: - 1. Start Eclipse, then select Help --\> Install New Software... - 2. Click Add (in the top-right corner). - 3. In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following - URL for the Location: + -# Start Eclipse, then select Help --\> Install New Software... + -# Click Add (in the top-right corner). + -# In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following + URL for the Location: + + -# Click OK - + @note If you have trouble acquiring the plugin, try using "http" in the Location URL, instead of "https" (https is preferred for security reasons). - 4. Click OK + -# In the Available Software dialog, select the checkbox next to Developer Tools and click Next. -@note If you have trouble acquiring the plugin, try using "http" in the Location URL, instead of "https" (https is preferred for security reasons). - 1. In the Available Software dialog, select the checkbox next to Developer Tools and click - Next. - 2. In the next window, you'll see a list of the tools to be downloaded. Click Next. + -# In the next window, you'll see a list of the tools to be downloaded. Click Next. -@note If you also plan to develop native C++ code with Android NDK don't forget to enable NDK Plugins installations as well. - ![image](images/eclipse_inst_adt.png) + @note If you also plan to develop native C++ code with Android NDK don't forget to enable NDK Plugins installations as well. -1. Read and accept the license agreements, then click Finish. + ![](images/eclipse_inst_adt.png) -@note If you get a security warning saying that the authenticity or validity of the software can't be established, click OK. - 1. When the installation completes, restart Eclipse. + -# Read and accept the license agreements, then click Finish. + + @note If you get a security warning saying that the authenticity or validity of the software can't be established, click OK. + + -# When the installation completes, restart Eclipse. ### Native development in C++ You need the following software to be installed in order to develop for Android in C++: -1. **Android NDK** +-# **Android NDK** To compile C++ code for Android platform you need Android Native Development Kit (*NDK*). @@ -170,17 +174,18 @@ You need the following software to be installed in order to develop for Android extract the archive to some folder on your computer. Here are [installation instructions](http://developer.android.com/tools/sdk/ndk/index.html#Installing). -@note Before start you can read official Android NDK documentation which is in the Android NDK -archive, in the folder `docs/`. The main article about using Android NDK build system is in the -`ANDROID-MK.html` file. Some additional information you can find in the `APPLICATION-MK.html`, -`NDK-BUILD.html` files, and `CPU-ARM-NEON.html`, `CPLUSPLUS-SUPPORT.html`, `PREBUILTS.html`. \#. -**CDT plugin for Eclipse** + @note Before start you can read official Android NDK documentation which is in the Android NDK + archive, in the folder `docs/`. The main article about using Android NDK build system is in the + `ANDROID-MK.html` file. Some additional information you can find in the `APPLICATION-MK.html`, + `NDK-BUILD.html` files, and `CPU-ARM-NEON.html`, `CPLUSPLUS-SUPPORT.html`, `PREBUILTS.html`. -If you selected for installation the NDK plugins component of Eclipse ADT plugin (see the picture -above) your Eclipse IDE should already have CDT plugin (that means C/C++ Development Tooling). -There are several possible ways to integrate compilation of C++ code by Android NDK into Eclipse -compilation process. We recommend the approach based on Eclipse CDT(C/C++ Development Tooling) -Builder. +-# **CDT plugin for Eclipse** + + If you selected for installation the NDK plugins component of Eclipse ADT plugin (see the picture + above) your Eclipse IDE should already have CDT plugin (that means C/C++ Development Tooling). + There are several possible ways to integrate compilation of C++ code by Android NDK into Eclipse + compilation process. We recommend the approach based on Eclipse CDT(C/C++ Development Tooling) + Builder. Android application structure ----------------------------- @@ -244,6 +249,7 @@ APP_STL := gnustl_static APP_CPPFLAGS := -frtti -fexceptions APP_ABI := all @endcode + @note We recommend setting APP_ABI := all for all targets. If you want to specify the target explicitly, use armeabi for ARMv5/ARMv6, armeabi-v7a for ARMv7, x86 for Intel Atom or mips for MIPS. @@ -260,18 +266,18 @@ We strongly reccomend using cmd.exe (standard Windows console) instead of Cygwin not really supported and we are unlikely to help you in case you encounter some problems with it. So, use it only if you're capable of handling the consequences yourself. -1. Open console and go to the root folder of an Android application +-# Open console and go to the root folder of an Android application @code{.bash} cd / @endcode -2. Run the following command +-# Run the following command @code{.bash} /ndk-build @endcode -@note On Windows we recommend to use ndk-build.cmd in standard Windows console (cmd.exe) rather than the similar bash script in Cygwin shell. - ![image](images/ndk_build.png) + @note On Windows we recommend to use ndk-build.cmd in standard Windows console (cmd.exe) rather than the similar bash script in Cygwin shell. + ![](images/ndk_build.png) -1. After executing this command the C++ part of the source code is compiled. +-# After executing this command the C++ part of the source code is compiled. After that the Java part of the application can be (re)compiled (using either *Eclipse* or *Ant* build tool). @@ -299,8 +305,8 @@ Builder. OpenCV for Android package since version 2.4.2 contains sample projects pre-configured CDT Builders. For your own projects follow the steps below. -1. Define the NDKROOT environment variable containing the path to Android NDK in your system (e.g. - "X:\\\\Apps\\\\android-ndk-r8" or "/opt/android-ndk-r8"). +-# Define the NDKROOT environment variable containing the path to Android NDK in your system (e.g. + "X:\\Apps\\android-ndk-r8" or "/opt/android-ndk-r8"). **On Windows** an environment variable can be set via My Computer -\> Properties -\> Advanced -\> Environment variables. On Windows 7 it's also @@ -309,71 +315,68 @@ OpenCV for Android package since version 2.4.2 contains sample projects **On Linux** and **MacOS** an environment variable can be set via appending a "export VAR_NAME=VAR_VALUE" line to the `"~/.bashrc"` file and logging off and then on. -@note It's also possible to define the NDKROOT environment variable within Eclipse IDE, but it -should be done for every new workspace you create. If you prefer this option better than setting -system environment variable, open Eclipse menu -Window -\> Preferences -\> C/C++ -\> Build -\> Environment, press the Add... button and set variable -name to NDKROOT and value to local Android NDK path. \#. After that you need to **restart Eclipse** -to apply the changes. + @note It's also possible to define the NDKROOT environment variable within Eclipse IDE, but it + should be done for every new workspace you create. If you prefer this option better than setting + system environment variable, open Eclipse menu + Window -\> Preferences -\> C/C++ -\> Build -\> Environment, press the Add... button and set variable + name to NDKROOT and value to local Android NDK path. \#. After that you need to **restart Eclipse** + to apply the changes. -1. Open Eclipse and load the Android app project to configure. -2. Add C/C++ Nature to the project via Eclipse menu - New -\> Other -\> C/C++ -\> Convert to a C/C++ Project. - - ![image](images/eclipse_cdt_cfg1.png) +-# Open Eclipse and load the Android app project to configure. +-# Add C/C++ Nature to the project via Eclipse menu + New -\> Other -\> C/C++ -\> Convert to a C/C++ Project. + ![](images/eclipse_cdt_cfg1.png) And: + ![](images/eclipse_cdt_cfg2.png) - ![image](images/eclipse_cdt_cfg2.png) - -3. Select the project(s) to convert. Specify "Project type" = Makefile project, "Toolchains" = +-# Select the project(s) to convert. Specify "Project type" = Makefile project, "Toolchains" = Other Toolchain. + ![](images/eclipse_cdt_cfg3.png) - ![image](images/eclipse_cdt_cfg3.png) - -4. Open Project Properties -\> C/C++ Build, uncheck Use default build command, replace "Build +-# Open Project Properties -\> C/C++ Build, uncheck Use default build command, replace "Build command" text from "make" to "${NDKROOT}/ndk-build.cmd" on Windows, "${NDKROOT}/ndk-build" on Linux and MacOS. - ![image](images/eclipse_cdt_cfg4.png) + ![](images/eclipse_cdt_cfg4.png) -5. Go to Behaviour tab and change "Workbench build type" section like shown below: +-# Go to Behaviour tab and change "Workbench build type" section like shown below: - ![image](images/eclipse_cdt_cfg5.png) + ![](images/eclipse_cdt_cfg5.png) -6. Press OK and make sure the ndk-build is successfully invoked when building the project. +-# Press OK and make sure the ndk-build is successfully invoked when building the project. - ![image](images/eclipse_cdt_cfg6.png) + ![](images/eclipse_cdt_cfg6.png) -7. If you open your C++ source file in Eclipse editor, you'll see syntax error notifications. They +-# If you open your C++ source file in Eclipse editor, you'll see syntax error notifications. They are not real errors, but additional CDT configuring is required. - ![image](images/eclipse_cdt_cfg7.png) + ![](images/eclipse_cdt_cfg7.png) -8. Open Project Properties -\> C/C++ General -\> Paths and Symbols and add the following +-# Open Project Properties -\> C/C++ General -\> Paths and Symbols and add the following **Include** paths for **C++**: - + @code # for NDK r8 and prior: - \f${NDKROOT}/platforms/android-9/arch-arm/usr/include - \f${NDKROOT}/sources/cxx-stl/gnu-libstdc++/include - \f${NDKROOT}/sources/cxx-stl/gnu-libstdc++/libs/armeabi-v7a/include - \f${ProjDirPath}/../../sdk/native/jni/include + ${NDKROOT}/platforms/android-9/arch-arm/usr/include + ${NDKROOT}/sources/cxx-stl/gnu-libstdc++/include + ${NDKROOT}/sources/cxx-stl/gnu-libstdc++/libs/armeabi-v7a/include + ${ProjDirPath}/../../sdk/native/jni/include # for NDK r8b and later: - \f${NDKROOT}/platforms/android-9/arch-arm/usr/include - \f${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.6/include - \f${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include - \f${ProjDirPath}/../../sdk/native/jni/include - + ${NDKROOT}/platforms/android-9/arch-arm/usr/include + ${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.6/include + ${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include + ${ProjDirPath}/../../sdk/native/jni/include + @endcode The last path should be changed to the correct absolute or relative path to OpenCV4Android SDK location. This should clear the syntax error notifications in Eclipse C++ editor. - ![image](images/eclipse_cdt_cfg8.png) + ![](images/eclipse_cdt_cfg8.png) Debugging and Testing --------------------- @@ -386,18 +389,18 @@ hardware device for testing and debugging an Android project. AVD (*Android Virtual Device*) is not probably the most convenient way to test an OpenCV-dependent application, but sure the most uncomplicated one to configure. -1. Assuming you already have *Android SDK* and *Eclipse IDE* installed, in Eclipse go +-# Assuming you already have *Android SDK* and *Eclipse IDE* installed, in Eclipse go Window -\> AVD Manager. -2. Press the New button in AVD Manager window. -3. Create new Android Virtual Device window will let you select some properties for your new +-# Press the New button in AVD Manager window. +-# Create new Android Virtual Device window will let you select some properties for your new device, like target API level, size of SD-card and other. - ![image](images/AVD_create.png) + ![](images/AVD_create.png) -4. When you click the Create AVD button, your new AVD will be availible in AVD Manager. -5. Press Start to launch the device. Be aware that any AVD (a.k.a. Emulator) is usually much slower +-# When you click the Create AVD button, your new AVD will be availible in AVD Manager. +-# Press Start to launch the device. Be aware that any AVD (a.k.a. Emulator) is usually much slower than a hardware Android device, so it may take up to several minutes to start. -6. Go Run -\> Run/Debug in Eclipse IDE to run your application in regular or debugging mode. +-# Go Run -\> Run/Debug in Eclipse IDE to run your application in regular or debugging mode. Device Chooser will let you choose among the running devices or to start a new one. ### Hardware Device @@ -412,86 +415,77 @@ instructions](http://developer.android.com/tools/device.html) for more informati #### Windows host computer -1. Enable USB debugging on the Android device (via Settings menu). -2. Attach the Android device to your PC with a USB cable. -3. Go to Start Menu and **right-click** on Computer. Select Manage in the context menu. You may be +-# Enable USB debugging on the Android device (via Settings menu). +-# Attach the Android device to your PC with a USB cable. +-# Go to Start Menu and **right-click** on Computer. Select Manage in the context menu. You may be asked for Administrative permissions. -4. Select Device Manager in the left pane and find an unknown device in the list. You may try +-# Select Device Manager in the left pane and find an unknown device in the list. You may try unplugging it and then plugging back in order to check whether it's your exact equipment appears in the list. - ![image](images/usb_device_connect_01.png) + ![](images/usb_device_connect_01.png) -5. Try your luck installing Google USB drivers without any modifications: **right-click** on the +-# Try your luck installing Google USB drivers without any modifications: **right-click** on the unknown device, select Properties menu item --\> Details tab --\> Update Driver button. - ![image](images/usb_device_connect_05.png) + ![](images/usb_device_connect_05.png) -6. Select Browse computer for driver software. +-# Select Browse computer for driver software. - ![image](images/usb_device_connect_06.png) + ![](images/usb_device_connect_06.png) -7. Specify the path to `/extras/google/usb_driver/` folder. +-# Specify the path to `/extras/google/usb_driver/` folder. - ![image](images/usb_device_connect_07.png) + ![](images/usb_device_connect_07.png) -8. If you get the prompt to install unverified drivers and report about success - you've finished +-# If you get the prompt to install unverified drivers and report about success - you've finished with USB driver installation. - ![image](images/usb_device_connect_08.png) - - \` \` - + ![](images/usb_device_connect_08.png) - ![image](images/usb_device_connect_09.png) + ![](images/usb_device_connect_09.png) -9. Otherwise (getting the failure like shown below) follow the next steps. +-# Otherwise (getting the failure like shown below) follow the next steps. - ![image](images/usb_device_connect_12.png) + ![](images/usb_device_connect_12.png) -10. Again **right-click** on the unknown device, select Properties --\> Details --\> Hardware Ids - and copy the line like USB\\VID_XXXX&PID_XXXX&MI_XX. +-# Again **right-click** on the unknown device, select Properties --\> Details --\> Hardware Ids + and copy the line like `USB\VID_XXXX&PID_XXXX&MI_XX`. - ![image](images/usb_device_connect_02.png) + ![](images/usb_device_connect_02.png) -11. Now open file `/extras/google/usb_driver/android_winusb.inf`. Select either +-# Now open file `/extras/google/usb_driver/android_winusb.inf`. Select either Google.NTx86 or Google.NTamd64 section depending on your host system architecture. - ![image](images/usb_device_connect_03.png) - -12. There should be a record like existing ones for your device and you need to add one manually. - - ![image](images/usb_device_connect_04.png) - -13. Save the `android_winusb.inf` file and try to install the USB driver again. + ![](images/usb_device_connect_03.png) - ![image](images/usb_device_connect_05.png) +-# There should be a record like existing ones for your device and you need to add one manually. - \` \` + ![](images/usb_device_connect_04.png) - ![image](images/usb_device_connect_06.png) +-# Save the `android_winusb.inf` file and try to install the USB driver again. - \` \` + ![](images/usb_device_connect_05.png) - ![image](images/usb_device_connect_07.png) + ![](images/usb_device_connect_06.png) -14. This time installation should go successfully. + ![](images/usb_device_connect_07.png) - ![image](images/usb_device_connect_08.png) +-# This time installation should go successfully. - \` \` + ![](images/usb_device_connect_08.png) - ![image](images/usb_device_connect_09.png) + ![](images/usb_device_connect_09.png) -15. And an unknown device is now recognized as an Android phone. +-# And an unknown device is now recognized as an Android phone. - ![image](images/usb_device_connect_10.png) + ![](images/usb_device_connect_10.png) -16. Successful device USB connection can be verified in console via adb devices command. +-# Successful device USB connection can be verified in console via adb devices command. - ![image](images/usb_device_connect_11.png) + ![](images/usb_device_connect_11.png) -17. Now, in Eclipse go Run -\> Run/Debug to run your application in regular or debugging mode. +-# Now, in Eclipse go Run -\> Run/Debug to run your application in regular or debugging mode. Device Chooser will let you choose among the devices. #### Linux host computer @@ -507,7 +501,7 @@ SUBSYSTEM=="usb", ATTR{idVendor}=="1004", MODE="0666", GROUP="plugdev" Then restart your adb server (even better to restart the system), plug in your Android device and execute adb devices command. You will see the list of attached devices: -![image](images/usb_device_connect_ubuntu.png) +![](images/usb_device_connect_ubuntu.png) #### Mac OS host computer diff --git a/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.markdown b/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.markdown index fb96928d22..d9b0e4f992 100644 --- a/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.markdown +++ b/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.markdown @@ -38,17 +38,17 @@ OpenCV. You can get more information here: `Android OpenCV Manager` and in these Using async initialization is a **recommended** way for application development. It uses the OpenCV Manager to access OpenCV libraries externally installed in the target system. -1. Add OpenCV library project to your workspace. Use menu +-# Add OpenCV library project to your workspace. Use menu File -\> Import -\> Existing project in your workspace. Press Browse button and locate OpenCV4Android SDK (`OpenCV-2.4.9-android-sdk/sdk`). - ![image](images/eclipse_opencv_dependency0.png) + ![](images/eclipse_opencv_dependency0.png) -2. In application project add a reference to the OpenCV Java SDK in +-# In application project add a reference to the OpenCV Java SDK in Project -\> Properties -\> Android -\> Library -\> Add select OpenCV Library - 2.4.9. - ![image](images/eclipse_opencv_dependency1.png) + ![](images/eclipse_opencv_dependency1.png) In most cases OpenCV Manager may be installed automatically from Google Play. For the case, when Google Play is not available, i.e. emulator, developer board, etc, you can install it manually using @@ -101,18 +101,18 @@ designed mostly for development purposes. This approach is deprecated for the pr release package is recommended to communicate with OpenCV Manager via the async initialization described above. -1. Add the OpenCV library project to your workspace the same way as for the async initialization +-# Add the OpenCV library project to your workspace the same way as for the async initialization above. Use menu File -\> Import -\> Existing project in your workspace, press Browse button and select OpenCV SDK path (`OpenCV-2.4.9-android-sdk/sdk`). - ![image](images/eclipse_opencv_dependency0.png) + ![](images/eclipse_opencv_dependency0.png) -2. In the application project add a reference to the OpenCV4Android SDK in +-# In the application project add a reference to the OpenCV4Android SDK in Project -\> Properties -\> Android -\> Library -\> Add select OpenCV Library - 2.4.9; - ![image](images/eclipse_opencv_dependency1.png) + ![](images/eclipse_opencv_dependency1.png) -3. If your application project **doesn't have a JNI part**, just copy the corresponding OpenCV +-# If your application project **doesn't have a JNI part**, just copy the corresponding OpenCV native libs from `/sdk/native/libs/` to your project directory to folder `libs/`. @@ -126,7 +126,7 @@ described above. @endcode The result should look like the following: @code{.make} - include \f$(CLEAR_VARS) + include $(CLEAR_VARS) # OpenCV OPENCV_CAMERA_MODULES:=on @@ -139,7 +139,7 @@ described above. Eclipse will automatically include all the libraries from the `libs` folder to the application package (APK). -4. The last step of enabling OpenCV in your application is Java initialization code before calling +-# The last step of enabling OpenCV in your application is Java initialization code before calling OpenCV API. It can be done, for example, in the static section of the Activity class: @code{.java} static { @@ -166,23 +166,23 @@ described above. To build your own Android application, using OpenCV as native part, the following steps should be taken: -1. You can use an environment variable to specify the location of OpenCV package or just hardcode +-# You can use an environment variable to specify the location of OpenCV package or just hardcode absolute or relative path in the `jni/Android.mk` of your projects. -2. The file `jni/Android.mk` should be written for the current application using the common rules +-# The file `jni/Android.mk` should be written for the current application using the common rules for this file. For detailed information see the Android NDK documentation from the Android NDK archive, in the file `/docs/ANDROID-MK.html`. -3. The following line: +-# The following line: @code{.make} include C:\Work\OpenCV4Android\OpenCV-2.4.9-android-sdk\sdk\native\jni\OpenCV.mk @endcode Should be inserted into the `jni/Android.mk` file **after** this line: @code{.make} - include \f$(CLEAR_VARS) + include $(CLEAR_VARS) @endcode -4. Several variables can be used to customize OpenCV stuff, but you **don't need** to use them when +-# Several variables can be used to customize OpenCV stuff, but you **don't need** to use them when your application uses the async initialization via the OpenCV Manager API. @note These variables should be set **before** the "include .../OpenCV.mk" line: @@ -202,7 +202,7 @@ taken: Perform static linking with OpenCV. By default dynamic link is used and the project JNI lib depends on libopencv_java.so. -5. The file `Application.mk` should exist and should contain lines: +-# The file `Application.mk` should exist and should contain lines: @code{.make} APP_STL := gnustl_static APP_CPPFLAGS := -frtti -fexceptions @@ -221,7 +221,7 @@ taken: APP_PLATFORM := android-9 @endcode -6. Either use @ref tutorial_android_dev_intro_ndk "manual" ndk-build invocation or +-# Either use @ref tutorial_android_dev_intro_ndk "manual" ndk-build invocation or @ref tutorial_android_dev_intro_eclipse "setup Eclipse CDT Builder" to build native JNI lib before (re)building the Java part and creating an APK. @@ -232,18 +232,18 @@ Hello OpenCV Sample Here are basic steps to guide you trough the process of creating a simple OpenCV-centric application. It will be capable of accessing camera output, processing it and displaying the result. -1. Open Eclipse IDE, create a new clean workspace, create a new Android project +-# Open Eclipse IDE, create a new clean workspace, create a new Android project File --\> New --\> Android Project -2. Set name, target, package and minSDKVersion accordingly. The minimal SDK version for build with +-# Set name, target, package and minSDKVersion accordingly. The minimal SDK version for build with OpenCV4Android SDK is 11. Minimal device API Level (for application manifest) is 8. -3. Allow Eclipse to create default activity. Lets name the activity HelloOpenCvActivity. -4. Choose Blank Activity with full screen layout. Lets name the layout HelloOpenCvLayout. -5. Import OpenCV library project to your workspace. -6. Reference OpenCV library within your project properties. +-# Allow Eclipse to create default activity. Lets name the activity HelloOpenCvActivity. +-# Choose Blank Activity with full screen layout. Lets name the layout HelloOpenCvLayout. +-# Import OpenCV library project to your workspace. +-# Reference OpenCV library within your project properties. - ![image](images/dev_OCV_reference.png) + ![](images/dev_OCV_reference.png) -7. Edit your layout file as xml file and pass the following layout there: +-# Edit your layout file as xml file and pass the following layout there: @code{.xml} @endcode -8. Add the following permissions to the `AndroidManifest.xml` file: +-# Add the following permissions to the `AndroidManifest.xml` file: @code{.xml} @@ -272,14 +272,14 @@ application. It will be capable of accessing camera output, processing it and di @endcode -9. Set application theme in AndroidManifest.xml to hide title and system buttons. +-# Set application theme in AndroidManifest.xml to hide title and system buttons. @code{.xml} @endcode -10. Add OpenCV library initialization to your activity. Fix errors by adding requited imports. +-# Add OpenCV library initialization to your activity. Fix errors by adding requited imports. @code{.java} private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override @@ -305,7 +305,7 @@ application. It will be capable of accessing camera output, processing it and di OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback); } @endcode -11. Defines that your activity implements CvCameraViewListener2 interface and fix activity related +-# Defines that your activity implements CvCameraViewListener2 interface and fix activity related errors by defining missed methods. For this activity define onCreate, onDestroy and onPause and implement them according code snippet bellow. Fix errors by adding requited imports. @code{.java} @@ -346,7 +346,7 @@ application. It will be capable of accessing camera output, processing it and di return inputFrame.rgba(); } @endcode -12. Run your application on device or emulator. +-# Run your application on device or emulator. Lets discuss some most important steps. Every Android application with UI must implement Activity and View. By the first steps we create blank activity and default view layout. The simplest diff --git a/doc/tutorials/introduction/clojure_dev_intro/clojure_dev_intro.markdown b/doc/tutorials/introduction/clojure_dev_intro/clojure_dev_intro.markdown index b190458825..5af960843c 100644 --- a/doc/tutorials/introduction/clojure_dev_intro/clojure_dev_intro.markdown +++ b/doc/tutorials/introduction/clojure_dev_intro/clojure_dev_intro.markdown @@ -32,9 +32,11 @@ tutorial](http://docs.opencv.org/2.4.4-beta/doc/tutorials/introduction/desktop_j If you are in hurry, here is a minimum quick start guide to install OpenCV on Mac OS X: -NOTE 1: I'm assuming you already installed [xcode](https://developer.apple.com/xcode/), +@note +I'm assuming you already installed [xcode](https://developer.apple.com/xcode/), [jdk](http://www.oracle.com/technetwork/java/javase/downloads/index.html) and [Cmake](http://www.cmake.org/cmake/resources/software.html). + @code{.bash} cd ~/ mkdir opt @@ -60,9 +62,9 @@ cycle of your CLJ projects. The available [installation guide](https://github.com/technomancy/leiningen#installation) is very easy to be followed: -1. [Download the script](https://raw.github.com/technomancy/leiningen/stable/bin/lein) -2. Place it on your $PATH (cf. \~/bin is a good choice if it is on your path.) -3. Set the script to be executable. (i.e. chmod 755 \~/bin/lein). +-# [Download the script](https://raw.github.com/technomancy/leiningen/stable/bin/lein) +-# Place it on your $PATH (cf. \~/bin is a good choice if it is on your path.) +-# Set the script to be executable. (i.e. chmod 755 \~/bin/lein). If you work on Windows, follow [this instruction](https://github.com/technomancy/leiningen#windows) @@ -171,9 +173,9 @@ Your directories layout should look like the following: tree . |__ native -|   |__ macosx -|   |__ x86_64 -|   |__ libopencv_java247.dylib +| |__ macosx +| |__ x86_64 +| |__ libopencv_java247.dylib | |__ opencv-247.jar |__ opencv-native-247.jar @@ -215,13 +217,13 @@ simple-sample/ |__ LICENSE |__ README.md |__ doc -|   |__ intro.md +| |__ intro.md | |__ project.clj |__ resources |__ src -|   |__ simple_sample -|   |__ core.clj +| |__ simple_sample +| |__ core.clj |__ test |__ simple_sample |__ core_test.clj @@ -299,7 +301,9 @@ nil Then you can start interacting with OpenCV by just referencing the fully qualified names of its classes. -NOTE 2: [Here](http://docs.opencv.org/java/) you can find the full OpenCV Java API. +@note +[Here](http://docs.opencv.org/java/) you can find the full OpenCV Java API. + @code{.clojure} user=> (org.opencv.core.Point. 0 0) # @@ -409,6 +413,7 @@ class SimpleSample { } @endcode + ### Add injections to the project Before start coding, we'd like to eliminate the boring need of interactively loading the native @@ -454,6 +459,7 @@ We're going to mimic almost verbatim the original OpenCV java tutorial to: - change the value of every element of the second row to 1 - change the value of every element of the 6th column to 5 - print the content of the obtained matrix + @code{.clojure} user=> (def m (Mat. 5 10 CvType/CV_8UC1 (Scalar. 0 0))) #'user/m @@ -473,6 +479,7 @@ user=> (println (.dump m)) 0, 0, 0, 0, 0, 5, 0, 0, 0, 0] nil @endcode + If you are accustomed to a functional language all those abused and mutating nouns are going to irritate your preference for verbs. Even if the CLJ interop syntax is very handy and complete, there is still an impedance mismatch between any OOP language and any FP language (bein Scala a mixed @@ -483,6 +490,7 @@ To exit the REPL type (exit), ctr-D or (quit) at the REPL prompt. user=> (exit) Bye for now! @endcode + ### Interactively load and blur an image In the next sample you will learn how to interactively load and blur and image from the REPL by @@ -500,7 +508,7 @@ main argument to both the GaussianBlur and the imwrite methods. First we want to add an image file to a newly create directory for storing static resources of the project. -![image](images/lena.png) +![](images/lena.png) @code{.bash} mkdir -p resources/images cp ~/opt/opencv/doc/tutorials/introduction/desktop_java/images/lena.png resource/images/ @@ -554,7 +562,7 @@ Bye for now! @endcode Following is the new blurred image of Lena. -![image](images/blurred.png) +![](images/blurred.png) Next Steps ---------- @@ -577,4 +585,3 @@ the gap. Copyright © 2013 Giacomo (Mimmo) Cosenza aka Magomimmo Distributed under the BSD 3-clause License, the same of OpenCV. - diff --git a/doc/tutorials/introduction/crosscompilation/arm_crosscompile_with_cmake.markdown b/doc/tutorials/introduction/crosscompilation/arm_crosscompile_with_cmake.markdown index 09c2134587..1b9dc30ea5 100644 --- a/doc/tutorials/introduction/crosscompilation/arm_crosscompile_with_cmake.markdown +++ b/doc/tutorials/introduction/crosscompilation/arm_crosscompile_with_cmake.markdown @@ -49,10 +49,11 @@ In Linux it can be achieved with the following command in Terminal: cd ~/ git clone https://github.com/Itseez/opencv.git @endcode + Building OpenCV --------------- -1. Create a build directory, make it current and run the following command: +-# Create a build directory, make it current and run the following command: @code{.bash} cmake [] -DCMAKE_TOOLCHAIN_FILE=/platforms/linux/arm-gnueabi.toolchain.cmake @endcode @@ -69,13 +70,15 @@ Building OpenCV cmake -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../.. @endcode -2. Run make in build (\) directory: + +-# Run make in build (\) directory: @code{.bash} make @endcode + @note - Optionally you can strip symbols info from the created library via install/strip make target. - This option produces smaller binary (\~ twice smaller) but makes further debugging harder. +Optionally you can strip symbols info from the created library via install/strip make target. +This option produces smaller binary (\~ twice smaller) but makes further debugging harder. ### Enable hardware optimizations @@ -86,5 +89,4 @@ extensions. TBB is supported on multi core ARM SoCs also. Add -DWITH_TBB=ON and -DBUILD_TBB=ON to enable it. Cmake scripts download TBB sources from official project site -[](http://threadingbuildingblocks.org/) and build it. - + and build it. diff --git a/doc/tutorials/introduction/desktop_java/java_dev_intro.markdown b/doc/tutorials/introduction/desktop_java/java_dev_intro.markdown index 50b3d7f44f..9e8048d168 100644 --- a/doc/tutorials/introduction/desktop_java/java_dev_intro.markdown +++ b/doc/tutorials/introduction/desktop_java/java_dev_intro.markdown @@ -33,7 +33,9 @@ from the [OpenCV SourceForge repository](http://sourceforge.net/projects/opencvl @note Windows users can find the prebuilt files needed for Java development in the `opencv/build/java/` folder inside the package. For other OSes it's required to build OpenCV from -sources. Another option to get OpenCV sources is to clone [OpenCV git +sources. + +Another option to get OpenCV sources is to clone [OpenCV git repository](https://github.com/Itseez/opencv/). In order to build OpenCV with Java bindings you need JDK (Java Development Kit) (we recommend [Oracle/Sun JDK 6 or 7](http://www.oracle.com/technetwork/java/javase/downloads/)), [Apache Ant](http://ant.apache.org/) @@ -67,7 +69,7 @@ Examine the output of CMake and ensure java is one of the modules "To be built". If not, it's likely you're missing a dependency. You should troubleshoot by looking through the CMake output for any Java-related tools that aren't found and installing them. -![image](images/cmake_output.png) +![](images/cmake_output.png) @note If CMake can't find Java in your system set the JAVA_HOME environment variable with the path to installed JDK before running it. E.g.: @code{.bash} @@ -141,7 +143,7 @@ folder. The command should initiate [re]building and running the sample. You should see on the screen something like this: - ![image](images/ant_output.png) + ![](images/ant_output.png) SBT project for Java and Scala ------------------------------ @@ -203,7 +205,7 @@ eclipse # Running "eclipse" from within the sbt console @endcode You should see something like this: -![image](images/sbt_eclipse.png) +![](images/sbt_eclipse.png) You can now import the SBT project to Eclipse using Import ... -\> Existing projects into workspace. Whether you actually do this is optional for the guide; we'll be using SBT to build the project, so @@ -225,7 +227,7 @@ sbt run @endcode You should see something like this: -![image](images/sbt_run.png) +![](images/sbt_run.png) ### Running SBT samples @@ -241,7 +243,7 @@ sbt eclipse @endcode Next, create the directory `src/main/resources` and download this Lena image into it: -![image](images/lena.png) +![](images/lena.png) Make sure it's called `"lena.png"`. Items in the resources directory are available to the Java application at runtime. @@ -315,11 +317,11 @@ sbt run @endcode You should see something like this: -![image](images/sbt_run_face.png) +![](images/sbt_run_face.png) It should also write the following image to `faceDetection.png`: -![image](images/faceDetection.png) +![](images/faceDetection.png) You're done! Now you have a sample Java application working with OpenCV, so you can start the work on your own. We wish you good luck and many years of joyful life! diff --git a/doc/tutorials/introduction/display_image/display_image.markdown b/doc/tutorials/introduction/display_image/display_image.markdown index 4a397f9b14..680b61d84a 100644 --- a/doc/tutorials/introduction/display_image/display_image.markdown +++ b/doc/tutorials/introduction/display_image/display_image.markdown @@ -21,6 +21,8 @@ Download the source code from Explanation ----------- +@dontinclude cpp/tutorial_code/introduction/display_image/display_image.cpp + In OpenCV 2 we have multiple modules. Each one takes care of a different area or approach towards image processing. You could already observe this in the structure of the user guide of these tutorials itself. Before you use any of them you first need to include the header files where the @@ -31,36 +33,25 @@ You'll almost always end up using the: - *core* section, as here are defined the basic building blocks of the library - *highgui* module, as this contains the functions for input and output operations -@includelineno cpp/tutorial_code/introduction/display_image/display_image.cpp - -lines - 1-6 +@until We also include the *iostream* to facilitate console line output and input. To avoid data structure and function name conflicts with other libraries, OpenCV has its own namespace: *cv*. To avoid the need appending prior each of these the *cv::* keyword you can import the namespace in the whole file by using the lines: -@includelineno cpp/tutorial_code/introduction/display_image/display_image.cpp - -lines - 8-9 +@line using namespace cv This is true for the STL library too (used for console I/O). Now, let's analyze the *main* function. We start up assuring that we acquire a valid image name argument from the command line. Otherwise take a picture by default: "HappyFish.jpg". -@includelineno cpp/tutorial_code/introduction/display_image/display_image.cpp - -lines - 13-17 +@skip string +@until } Then create a *Mat* object that will store the data of the loaded image. -@includelineno cpp/tutorial_code/introduction/display_image/display_image.cpp - -lines - 19 +@skipline Mat Now we call the @ref cv::imread function which loads the image name specified by the first argument (*argv[1]*). The second argument specifies the format in what we want the image. This may be: @@ -69,10 +60,7 @@ Now we call the @ref cv::imread function which loads the image name specified by - IMREAD_GRAYSCALE ( 0) loads the image as an intensity one - IMREAD_COLOR (\>0) loads the image in the RGB format -@includelineno cpp/tutorial_code/introduction/display_image/display_image.cpp - -lines - 20 +@skipline image = imread @note OpenCV offers support for the image formats Windows bitmap (bmp), portable image formats (pbm, @@ -94,30 +82,18 @@ the image it contains from a size point of view. It may be: would like the image to keep its aspect ratio (*WINDOW_KEEPRATIO*) or not (*WINDOW_FREERATIO*). -@includelineno cpp/tutorial_code/introduction/display_image/display_image.cpp - - - lines - 28 +@skipline namedWindow Finally, to update the content of the OpenCV window with a new image use the @ref cv::imshow function. Specify the OpenCV window name to update and the image to use during this operation: -@includelineno cpp/tutorial_code/introduction/display_image/display_image.cpp - - - lines - 29 +@skipline imshow Because we want our window to be displayed until the user presses a key (otherwise the program would end far too quickly), we use the @ref cv::waitKey function whose only parameter is just how long should it wait for a user input (measured in milliseconds). Zero means to wait forever. -@includelineno cpp/tutorial_code/introduction/display_image/display_image.cpp - - - lines - 31 +@skipline waitKey Result ------ @@ -130,11 +106,10 @@ Result @endcode - You should get a nice window as the one shown below: - ![image](images/Display_Image_Tutorial_Result.jpg) + ![](images/Display_Image_Tutorial_Result.jpg) \htmlonly
\endhtmlonly - diff --git a/doc/tutorials/introduction/ios_install/ios_install.markdown b/doc/tutorials/introduction/ios_install/ios_install.markdown index 35b5ae456d..00faf685f5 100644 --- a/doc/tutorials/introduction/ios_install/ios_install.markdown +++ b/doc/tutorials/introduction/ios_install/ios_install.markdown @@ -21,13 +21,13 @@ git clone https://github.com/Itseez/opencv.git Building OpenCV from Source, using CMake and Command Line --------------------------------------------------------- -1. Make symbolic link for Xcode to let OpenCV build scripts find the compiler, header files etc. +-# Make symbolic link for Xcode to let OpenCV build scripts find the compiler, header files etc. @code{.bash} cd / sudo ln -s /Applications/Xcode.app/Contents/Developer Developer @endcode -2. Build OpenCV framework: +-# Build OpenCV framework: @code{.bash} cd ~/ python opencv/platforms/ios/build_framework.py ios diff --git a/doc/tutorials/introduction/java_eclipse/java_eclipse.markdown b/doc/tutorials/introduction/java_eclipse/java_eclipse.markdown index bdb791eac8..56116f615e 100644 --- a/doc/tutorials/introduction/java_eclipse/java_eclipse.markdown +++ b/doc/tutorials/introduction/java_eclipse/java_eclipse.markdown @@ -17,51 +17,51 @@ are more or less the same for other versions. Now, we will define OpenCV as a user library in Eclipse, so we can reuse the configuration for any project. Launch Eclipse and select Window --\> Preferences from the menu. -![image](images/1-window-preferences.png) +![](images/1-window-preferences.png) Navigate under Java --\> Build Path --\> User Libraries and click New.... -![image](images/2-user-library-new.png) +![](images/2-user-library-new.png) Enter a name, e.g. OpenCV-2.4.6, for your new library. -![image](images/3-library-name.png) +![](images/3-library-name.png) Now select your new user library and click Add External JARs.... -![image](images/4-add-external-jars.png) +![](images/4-add-external-jars.png) Browse through `C:\OpenCV-2.4.6\build\java\` and select opencv-246.jar. After adding the jar, extend the opencv-246.jar and select Native library location and press Edit.... -![image](images/5-native-library.png) +![](images/5-native-library.png) Select External Folder... and browse to select the folder `C:\OpenCV-2.4.6\build\java\x64`. If you have a 32-bit system you need to select the x86 folder instead of x64. -![image](images/6-external-folder.png) +![](images/6-external-folder.png) Your user library configuration should look like this: -![image](images/7-user-library-final.png) +![](images/7-user-library-final.png) Testing the configuration on a new Java project ----------------------------------------------- Now start creating a new Java project. -![image](images/7_5-new-java-project.png) +![](images/7_5-new-java-project.png) On the Java Settings step, under Libraries tab, select Add Library... and select OpenCV-2.4.6, then click Finish. -![image](images/8-add-library.png) +![](images/8-add-library.png) -![image](images/9-select-user-lib.png) +![](images/9-select-user-lib.png) Libraries should look like this: -![image](images/10-new-project-created.png) +![](images/10-new-project-created.png) Now you have created and configured a new Java project it is time to test it. Create a new java file. Here is a starter code for your convenience: @@ -82,7 +82,7 @@ public class Hello @endcode When you run the code you should see 3x3 identity matrix as output. -![image](images/11-the-code.png) +![](images/11-the-code.png) That is it, whenever you start a new project just add the OpenCV user library that you have defined to your project and you are good to go. Enjoy your powerful, less painful development environment :) diff --git a/doc/tutorials/introduction/linux_eclipse/linux_eclipse.markdown b/doc/tutorials/introduction/linux_eclipse/linux_eclipse.markdown index 46b24f0c59..2e575c17eb 100644 --- a/doc/tutorials/introduction/linux_eclipse/linux_eclipse.markdown +++ b/doc/tutorials/introduction/linux_eclipse/linux_eclipse.markdown @@ -4,45 +4,45 @@ Using OpenCV with Eclipse (plugin CDT) {#tutorial_linux_eclipse} Prerequisites ------------- Two ways, one by forming a project directly, and another by CMake Prerequisites -1. Having installed [Eclipse](http://www.eclipse.org/) in your workstation (only the CDT plugin for +-# Having installed [Eclipse](http://www.eclipse.org/) in your workstation (only the CDT plugin for C/C++ is needed). You can follow the following steps: - Go to the Eclipse site - Download [Eclipse IDE for C/C++ Developers](http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/heliossr2) . Choose the link according to your workstation. -2. Having installed OpenCV. If not yet, go @ref tutorial_linux_install "here". +-# Having installed OpenCV. If not yet, go @ref tutorial_linux_install "here". Making a project ---------------- -1. Start Eclipse. Just run the executable that comes in the folder. -2. Go to **File -\> New -\> C/C++ Project** +-# Start Eclipse. Just run the executable that comes in the folder. +-# Go to **File -\> New -\> C/C++ Project** - ![image](images/a0.png) + ![](images/a0.png) -3. Choose a name for your project (i.e. DisplayImage). An **Empty Project** should be okay for this +-# Choose a name for your project (i.e. DisplayImage). An **Empty Project** should be okay for this example. - ![image](images/a1.png) + ![](images/a1.png) -4. Leave everything else by default. Press **Finish**. -5. Your project (in this case DisplayImage) should appear in the **Project Navigator** (usually at +-# Leave everything else by default. Press **Finish**. +-# Your project (in this case DisplayImage) should appear in the **Project Navigator** (usually at the left side of your window). - ![image](images/a3.png) + ![](images/a3.png) -6. Now, let's add a source file using OpenCV: +-# Now, let's add a source file using OpenCV: - Right click on **DisplayImage** (in the Navigator). **New -\> Folder** . - ![image](images/a4.png) + ![](images/a4.png) - Name your folder **src** and then hit **Finish** - Right click on your newly created **src** folder. Choose **New source file**: - Call it **DisplayImage.cpp**. Hit **Finish** - ![image](images/a7.png) + ![](images/a7.png) -7. So, now you have a project with a empty .cpp file. Let's fill it with some sample code (in other +-# So, now you have a project with a empty .cpp file. Let's fill it with some sample code (in other words, copy and paste the snippet below): @code{.cpp} #include @@ -68,7 +68,7 @@ Making a project return 0; } @endcode -8. We are only missing one final step: To tell OpenCV where the OpenCV headers and libraries are. +-# We are only missing one final step: To tell OpenCV where the OpenCV headers and libraries are. For this, do the following: - Go to **Project--\>Properties** @@ -78,7 +78,7 @@ Making a project include the path of the folder where opencv was installed. In our example, this is /usr/local/include/opencv. - ![image](images/a9.png) + ![](images/a9.png) @note If you do not know where your opencv files are, open the **Terminal** and type: @code{.bash} @@ -103,7 +103,7 @@ Making a project opencv_core opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_features2d opencv_calib3d opencv_objdetect opencv_contrib opencv_legacy opencv_flann - ![image](images/a10.png) + ![](images/a10.png) If you don't know where your libraries are (or you are just psychotic and want to make sure the path is fine), type in **Terminal**: @@ -120,7 +120,7 @@ Making a project In the Console you should get something like - ![image](images/a12.png) + ![](images/a12.png) If you check in your folder, there should be an executable there. @@ -138,21 +138,21 @@ Assuming that the image to use as the argument would be located in \/images/HappyLittleFish.png. We can still do this, but let's do it from Eclipse: -1. Go to **Run-\>Run Configurations** -2. Under C/C++ Application you will see the name of your executable + Debug (if not, click over +-# Go to **Run-\>Run Configurations** +-# Under C/C++ Application you will see the name of your executable + Debug (if not, click over C/C++ Application a couple of times). Select the name (in this case **DisplayImage Debug**). -3. Now, in the right side of the window, choose the **Arguments** Tab. Write the path of the image +-# Now, in the right side of the window, choose the **Arguments** Tab. Write the path of the image file we want to open (path relative to the workspace/DisplayImage folder). Let's use **HappyLittleFish.png**: - ![image](images/a14.png) + ![](images/a14.png) -4. Click on the **Apply** button and then in Run. An OpenCV window should pop up with the fish +-# Click on the **Apply** button and then in Run. An OpenCV window should pop up with the fish image (or whatever you used). - ![image](images/a15.jpg) + ![](images/a15.jpg) -5. Congratulations! You are ready to have fun with OpenCV using Eclipse. +-# Congratulations! You are ready to have fun with OpenCV using Eclipse. ### V2: Using CMake+OpenCV with Eclipse (plugin CDT) @@ -170,25 +170,25 @@ int main ( int argc, char **argv ) return 0; } @endcode -1. Create a build directory, say, under *foo*: mkdir /build. Then cd build. -2. Put a `CmakeLists.txt` file in build: +-# Create a build directory, say, under *foo*: mkdir /build. Then cd build. +-# Put a `CmakeLists.txt` file in build: @code{.bash} PROJECT( helloworld_proj ) FIND_PACKAGE( OpenCV REQUIRED ) ADD_EXECUTABLE( helloworld helloworld.cxx ) TARGET_LINK_LIBRARIES( helloworld \f${OpenCV_LIBS} ) @endcode -1. Run: cmake-gui .. and make sure you fill in where opencv was built. -2. Then click configure and then generate. If it's OK, **quit cmake-gui** -3. Run `make -j4` (the -j4 is optional, it just tells the compiler to build in 4 threads). Make +-# Run: cmake-gui .. and make sure you fill in where opencv was built. +-# Then click configure and then generate. If it's OK, **quit cmake-gui** +-# Run `make -j4` (the -j4 is optional, it just tells the compiler to build in 4 threads). Make sure it builds. -4. Start eclipse. Put the workspace in some directory but **not** in foo or `foo\build` -5. Right click in the Project Explorer section. Select Import And then open the C/C++ filter. +-# Start eclipse. Put the workspace in some directory but **not** in foo or `foo\build` +-# Right click in the Project Explorer section. Select Import And then open the C/C++ filter. Choose *Existing Code* as a Makefile Project. -6. Name your project, say *helloworld*. Browse to the Existing Code location `foo\build` (where +-# Name your project, say *helloworld*. Browse to the Existing Code location `foo\build` (where you ran your cmake-gui from). Select *Linux GCC* in the *"Toolchain for Indexer Settings"* and press *Finish*. -7. Right click in the Project Explorer section. Select Properties. Under C/C++ Build, set the +-# Right click in the Project Explorer section. Select Properties. Under C/C++ Build, set the *build directory:* from something like `${workspace_loc:/helloworld}` to `${workspace_loc:/helloworld}/build` since that's where you are building to. @@ -196,4 +196,4 @@ TARGET_LINK_LIBRARIES( helloworld \f${OpenCV_LIBS} ) `make VERBOSE=1 -j4` which tells the compiler to produce detailed symbol files for debugging and also to compile in 4 parallel threads. -8. Done! +-# Done! diff --git a/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.markdown b/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.markdown index a327817b45..4f4adbed88 100644 --- a/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.markdown +++ b/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.markdown @@ -1,13 +1,12 @@ Using OpenCV with gcc and CMake {#tutorial_linux_gcc_cmake} =============================== -@note We assume that you have successfully installed OpenCV in your workstation. .. container:: -enumeratevisibleitemswithsquare +@note We assume that you have successfully installed OpenCV in your workstation. - The easiest way of using OpenCV in your code is to use [CMake](http://www.cmake.org/). A few advantages (taken from the Wiki): - 1. No need to change anything when porting between Linux and Windows - 2. Can easily be combined with other tools by CMake( i.e. Qt, ITK and VTK ) + -# No need to change anything when porting between Linux and Windows + -# Can easily be combined with other tools by CMake( i.e. Qt, ITK and VTK ) - If you are not familiar with CMake, checkout the [tutorial](http://www.cmake.org/cmake/help/cmake_tutorial.html) on its website. @@ -75,5 +74,4 @@ giving an image location as an argument, i.e.: @endcode You should get a nice window as the one shown below: -![image](images/GCC_CMake_Example_Tutorial.jpg) - +![](images/GCC_CMake_Example_Tutorial.jpg) diff --git a/doc/tutorials/introduction/linux_install/linux_install.markdown b/doc/tutorials/introduction/linux_install/linux_install.markdown index 8af137f9a2..b1868f82d7 100644 --- a/doc/tutorials/introduction/linux_install/linux_install.markdown +++ b/doc/tutorials/introduction/linux_install/linux_install.markdown @@ -49,7 +49,7 @@ git clone https://github.com/Itseez/opencv_contrib.git Building OpenCV from Source Using CMake --------------------------------------- -1. Create a temporary directory, which we denote as \, where you want to put +-# Create a temporary directory, which we denote as \, where you want to put the generated Makefiles, project files as well the object files and output binaries and enter there. @@ -59,7 +59,7 @@ Building OpenCV from Source Using CMake mkdir build cd build @endcode -2. Configuring. Run cmake [\] \ +-# Configuring. Run cmake [\] \ For example @code{.bash} @@ -73,14 +73,14 @@ Building OpenCV from Source Using CMake - run: “Configure” - run: “Generate” -3. Description of some parameters - - build type: CMAKE_BUILD_TYPE=Release\\Debug +-# Description of some parameters + - build type: `CMAKE_BUILD_TYPE=Release\Debug` - to build with modules from opencv_contrib set OPENCV_EXTRA_MODULES_PATH to \ - set BUILD_DOCS for building documents - set BUILD_EXAMPLES to build all examples -4. [optional] Building python. Set the following python parameters: +-# [optional] Building python. Set the following python parameters: - PYTHON2(3)_EXECUTABLE = \ - PYTHON_INCLUDE_DIR = /usr/include/python\ - PYTHON_INCLUDE_DIR2 = /usr/include/x86_64-linux-gnu/python\ @@ -88,18 +88,18 @@ Building OpenCV from Source Using CMake - PYTHON2(3)_NUMPY_INCLUDE_DIRS = /usr/lib/python\/dist-packages/numpy/core/include/ -5. [optional] Building java. +-# [optional] Building java. - Unset parameter: BUILD_SHARED_LIBS - It is useful also to unset BUILD_EXAMPLES, BUILD_TESTS, BUILD_PERF_TESTS - as they all will be statically linked with OpenCV and can take a lot of memory. -6. Build. From build directory execute make, recomend to do it in several threads +-# Build. From build directory execute make, recomend to do it in several threads For example @code{.bash} make -j7 # runs 7 jobs in parallel @endcode -7. [optional] Building documents. Enter \ and run make with target +-# [optional] Building documents. Enter \ and run make with target "html_docs" For example @@ -107,11 +107,11 @@ Building OpenCV from Source Using CMake cd ~/opencv/build/doc/ make -j7 html_docs @endcode -8. To install libraries, from build directory execute +-# To install libraries, from build directory execute @code{.bash} sudo make install @endcode -9. [optional] Running tests +-# [optional] Running tests - Get the required test data from [OpenCV extra repository](https://github.com/Itseez/opencv_extra). diff --git a/doc/tutorials/introduction/load_save_image/load_save_image.markdown b/doc/tutorials/introduction/load_save_image/load_save_image.markdown index 48555b623a..3754d6075c 100644 --- a/doc/tutorials/introduction/load_save_image/load_save_image.markdown +++ b/doc/tutorials/introduction/load_save_image/load_save_image.markdown @@ -55,9 +55,9 @@ int main( int argc, char** argv ) Explanation ----------- -1. We begin by loading an image using @ref cv::imread , located in the path given by *imageName*. +-# We begin by loading an image using @ref cv::imread , located in the path given by *imageName*. For this example, assume you are loading a RGB image. -2. Now we are going to convert our image from BGR to Grayscale format. OpenCV has a really nice +-# Now we are going to convert our image from BGR to Grayscale format. OpenCV has a really nice function to do this kind of transformations: @code{.cpp} cvtColor( image, gray_image, COLOR_BGR2GRAY ); @@ -70,7 +70,7 @@ Explanation this case we use **COLOR_BGR2GRAY** (because of @ref cv::imread has BGR default channel order in case of color images). -3. So now we have our new *gray_image* and want to save it on disk (otherwise it will get lost +-# So now we have our new *gray_image* and want to save it on disk (otherwise it will get lost after the program ends). To save it, we will use a function analagous to @ref cv::imread : @ref cv::imwrite @code{.cpp} @@ -79,7 +79,7 @@ Explanation Which will save our *gray_image* as *Gray_Image.jpg* in the folder *images* located two levels up of my current location. -4. Finally, let's check out the images. We create two windows and use them to show the original +-# Finally, let's check out the images. We create two windows and use them to show the original image as well as the new one: @code{.cpp} namedWindow( imageName, WINDOW_AUTOSIZE ); @@ -88,18 +88,18 @@ Explanation imshow( imageName, image ); imshow( "Gray image", gray_image ); @endcode -5. Add the *waitKey(0)* function call for the program to wait forever for an user key press. +-# Add the *waitKey(0)* function call for the program to wait forever for an user key press. Result ------ When you run your program you should get something like this: -![image](images/Load_Save_Image_Result_1.jpg) +![](images/Load_Save_Image_Result_1.jpg) And if you check in your folder (in my case *images*), you should have a newly .jpg file named *Gray_Image.jpg*: -![image](images/Load_Save_Image_Result_2.jpg) +![](images/Load_Save_Image_Result_2.jpg) Congratulations, you are done with this tutorial! diff --git a/doc/tutorials/introduction/windows_install/windows_install.markdown b/doc/tutorials/introduction/windows_install/windows_install.markdown index c0a14a4986..c8808b493a 100644 --- a/doc/tutorials/introduction/windows_install/windows_install.markdown +++ b/doc/tutorials/introduction/windows_install/windows_install.markdown @@ -14,15 +14,15 @@ technologies we integrate into our library. .. _Windows_Install_Prebuild: Installation by Using the Pre-built Libraries {#tutorial_windows_install_prebuilt} ============================================= -1. Launch a web browser of choice and go to our [page on +-# Launch a web browser of choice and go to our [page on Sourceforge](http://sourceforge.net/projects/opencvlibrary/files/opencv-win/). -2. Choose a build you want to use and download it. -3. Make sure you have admin rights. Unpack the self-extracting archive. -4. You can check the installation at the chosen path as you can see below. +-# Choose a build you want to use and download it. +-# Make sure you have admin rights. Unpack the self-extracting archive. +-# You can check the installation at the chosen path as you can see below. - ![image](images/OpenCV_Install_Directory.png) + ![](images/OpenCV_Install_Directory.png) -5. To finalize the installation go to the @ref tutorial_windows_install_path section. +-# To finalize the installation go to the @ref tutorial_windows_install_path section. Installation by Making Your Own Libraries from the Source Files {#tutorial_windows_install_build} =============================================================== @@ -97,18 +97,18 @@ libraries). If you do not need the support for some of these you can just freely ### Building the library -1. Make sure you have a working IDE with a valid compiler. In case of the Microsoft Visual Studio +-# Make sure you have a working IDE with a valid compiler. In case of the Microsoft Visual Studio just install it and make sure it starts up. -2. Install [CMake](http://www.cmake.org/cmake/resources/software.html). Simply follow the wizard, no need to add it to the path. The default install +-# Install [CMake](http://www.cmake.org/cmake/resources/software.html). Simply follow the wizard, no need to add it to the path. The default install options are OK. -3. Download and install an up-to-date version of msysgit from its [official +-# Download and install an up-to-date version of msysgit from its [official site](http://code.google.com/p/msysgit/downloads/list). There is also the portable version, which you need only to unpack to get access to the console version of Git. Supposing that for some of us it could be quite enough. -4. Install [TortoiseGit](http://code.google.com/p/tortoisegit/wiki/Download). Choose the 32 or 64 bit version according to the type of OS you work in. +-# Install [TortoiseGit](http://code.google.com/p/tortoisegit/wiki/Download). Choose the 32 or 64 bit version according to the type of OS you work in. While installing, locate your msysgit (if it doesn't do that automatically). Follow the wizard -- the default options are OK for the most part. -5. Choose a directory in your file system, where you will download the OpenCV libraries to. I +-# Choose a directory in your file system, where you will download the OpenCV libraries to. I recommend creating a new one that has short path and no special charachters in it, for example `D:/OpenCV`. For this tutorial I'll suggest you do so. If you use your own path and know, what you're doing -- it's OK. @@ -118,7 +118,7 @@ libraries). If you do not need the support for some of these you can just freely -# Push the OK button and be patient as the repository is quite a heavy download. It will take some time depending on your Internet connection. -6. In this section I will cover installing the 3rd party libraries. +-# In this section I will cover installing the 3rd party libraries. -# Download the [Python libraries](http://www.python.org/downloads/) and install it with the default options. You will need a couple other python extensions. Luckily installing all these may be automated by a nice tool called [Setuptools](http://pypi.python.org/pypi/setuptools#downloads). Download and install @@ -131,9 +131,9 @@ libraries). If you do not need the support for some of these you can just freely Script sub-folder. Here just pass to the *easy_install.exe* as argument the name of the program you want to install. Add the *sphinx* argument. - ![image](images/cmsdstartwindows.jpg) + ![](images/cmsdstartwindows.jpg) - ![image](images/Sphinx_Install.png) + ![](images/Sphinx_Install.png) @note The *CD* navigation command works only inside a drive. For example if you are somewhere in the @@ -152,7 +152,7 @@ libraries). If you do not need the support for some of these you can just freely sure you select for the *"Install missing packages on-the-fly"* the *Yes* option, as you can see on the image below. Again this will take quite some time so be patient. - ![image](images/MiktexInstall.png) + ![](images/MiktexInstall.png) -# For the [Intel Threading Building Blocks (*TBB*)](http://threadingbuildingblocks.org/file.php?fid=77) download the source files and extract @@ -161,7 +161,7 @@ libraries). If you do not need the support for some of these you can just freely the story is the same. For exctracting the archives I recommend using the [7-Zip](http://www.7-zip.org/) application. - ![image](images/IntelTBB.png) + ![](images/IntelTBB.png) -# For the [Intel IPP Asynchronous C/C++](http://software.intel.com/en-us/intel-ipp-preview) download the source files and set environment variable **IPP_ASYNC_ROOT**. It should point to @@ -182,14 +182,14 @@ libraries). If you do not need the support for some of these you can just freely Downloads](http://qt.nokia.com/downloads) page. Download the source files (not the installers!!!): - ![image](images/qtDownloadThisPackage.png) + ![](images/qtDownloadThisPackage.png) Extract it into a nice and short named directory like `D:/OpenCV/dep/qt/` . Then you need to build it. Start up a *Visual* *Studio* *Command* *Prompt* (*2010*) by using the start menu search (or navigate through the start menu All Programs --\> Microsoft Visual Studio 2010 --\> Visual Studio Tools --\> Visual Studio Command Prompt (2010)). - ![image](images/visualstudiocommandprompt.jpg) + ![](images/visualstudiocommandprompt.jpg) Now navigate to the extracted folder and enter inside it by using this console window. You should have a folder containing files like *Install*, *Make* and so on. Use the *dir* command @@ -216,25 +216,25 @@ libraries). If you do not need the support for some of these you can just freely Visual Studio Add-in*. After this you can make and build Qt applications without using the *Qt Creator*. Everything is nicely integrated into Visual Studio. -7. Now start the *CMake (cmake-gui)*. You may again enter it in the start menu search or get it +-# Now start the *CMake (cmake-gui)*. You may again enter it in the start menu search or get it from the All Programs --\> CMake 2.8 --\> CMake (cmake-gui). First, select the directory for the source files of the OpenCV library (1). Then, specify a directory where you will build the binary files for OpenCV (2). - ![image](images/CMakeSelectBin.jpg) + ![](images/CMakeSelectBin.jpg) Press the Configure button to specify the compiler (and *IDE*) you want to use. Note that in case you can choose between different compilers for making either 64 bit or 32 bit libraries. Select the one you use in your application development. - ![image](images/CMake_Configure_Windows.jpg) + ![](images/CMake_Configure_Windows.jpg) CMake will start out and based on your system variables will try to automatically locate as many packages as possible. You can modify the packages to use for the build in the WITH --\> WITH_X menu points (where *X* is the package abbreviation). Here are a list of current packages you can turn on or off: - ![image](images/CMakeBuildWithWindowsGUI.jpg) + ![](images/CMakeBuildWithWindowsGUI.jpg) Select all the packages you want to use and press again the *Configure* button. For an easier overview of the build options make sure the *Grouped* option under the binary directory @@ -242,9 +242,9 @@ libraries). If you do not need the support for some of these you can just freely directories. In case of these CMake will throw an error in its output window (located at the bottom of the GUI) and set its field values, to not found constants. For example: - ![image](images/CMakePackageNotFoundWindows.jpg) + ![](images/CMakePackageNotFoundWindows.jpg) - ![image](images/CMakeOutputPackageNotFound.jpg) + ![](images/CMakeOutputPackageNotFound.jpg) For these you need to manually set the queried directories or files path. After this press again the *Configure* button to see if the value entered by you was accepted or not. Do this until all @@ -254,7 +254,7 @@ libraries). If you do not need the support for some of these you can just freely option will make sure that they are categorized inside directories in the *Solution Explorer*. It is a must have feature, if you ask me. - ![image](images/CMakeBuildOptionsOpenCV.jpg) + ![](images/CMakeBuildOptionsOpenCV.jpg) Furthermore, you need to select what part of OpenCV you want to build. @@ -286,24 +286,24 @@ libraries). If you do not need the support for some of these you can just freely IDE at the startup. Now you need to build both the *Release* and the *Debug* binaries. Use the drop-down menu on your IDE to change to another of these after building for one of them. - ![image](images/ChangeBuildVisualStudio.jpg) + ![](images/ChangeBuildVisualStudio.jpg) In the end you can observe the built binary files inside the bin directory: - ![image](images/OpenCVBuildResultWindows.jpg) + ![](images/OpenCVBuildResultWindows.jpg) For the documentation you need to explicitly issue the build commands on the *doc* project for the PDF files and on the *doc_html* for the HTML ones. Each of these will call *Sphinx* to do all the hard work. You can find the generated documentation inside the `Build/Doc/_html` for the HTML pages and within the `Build/Doc` the PDF manuals. - ![image](images/WindowsBuildDoc.png) + ![](images/WindowsBuildDoc.png) To collect the header and the binary files, that you will use during your own projects, into a separate directory (simillary to how the pre-built binaries ship) you need to explicitely build the *Install* project. - ![image](images/WindowsBuildInstall.png) + ![](images/WindowsBuildInstall.png) This will create an *Install* directory inside the *Build* one collecting all the built binaries into a single place. Use this only after you built both the *Release* and *Debug* versions. @@ -314,7 +314,7 @@ libraries). If you do not need the support for some of these you can just freely If everything is okay the *contours.exe* output should resemble the following image (if built with Qt support): - ![image](images/WindowsQtContoursOutput.png) + ![](images/WindowsQtContoursOutput.png) @note If you use the GPU module (CUDA libraries) make sure you also upgrade to the latest drivers of @@ -353,9 +353,9 @@ following new entry (right click in the application to bring up the menu): %OPENCV_DIR%\bin @endcode -![image](images/PathEditorOpenCVInsertNew.png) +![](images/PathEditorOpenCVInsertNew.png) -![image](images/PathEditorOpenCVSetPath.png) +![](images/PathEditorOpenCVSetPath.png) Save it to the registry and you are done. If you ever change the location of your build directories or want to try out your applicaton with a different build all you will need to do is to update the diff --git a/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.markdown b/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.markdown index 8d5e1f7a21..753fc7ac8f 100644 --- a/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.markdown +++ b/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.markdown @@ -1,13 +1,13 @@ How to build applications with OpenCV inside the "Microsoft Visual Studio" {#tutorial_windows_visual_studio_Opencv} ========================================================================== -Everything I describe here will apply to the C\\C++ interface of OpenCV. I start out from the +Everything I describe here will apply to the `C\C++` interface of OpenCV. I start out from the assumption that you have read and completed with success the @ref tutorial_windows_install tutorial. Therefore, before you go any further make sure you have an OpenCV directory that contains the OpenCV header files plus binaries and you have set the environment variables as described here @ref tutorial_windows_install_path. -![image](images/OpenCV_Install_Directory.jpg) +![](images/OpenCV_Install_Directory.jpg) The OpenCV libraries, distributed by us, on the Microsoft Windows operating system are in a Dynamic Linked Libraries (*DLL*). These have the advantage that all the content of the @@ -58,7 +58,7 @@ create a new solution inside Visual studio by going through the File --\> New -- selection. Choose *Win32 Console Application* as type. Enter its name and select the path where to create it. Then in the upcoming dialog make sure you create an empty project. -![image](images/NewProjectVisualStudio.jpg) +![](images/NewProjectVisualStudio.jpg) The *local* method ------------------ @@ -75,7 +75,7 @@ you can view and modify them by using the *Property Manger*. You can bring up th View --\> Property Pages. Expand it and you can see the existing rule packages (called *Proporty Sheets*). -![image](images/PropertyPageExample.jpg) +![](images/PropertyPageExample.jpg) The really useful stuff of these is that you may create a rule package *once* and you can later just add it to your new projects. Create it once and reuse it later. We want to create a new *Property @@ -83,7 +83,7 @@ Sheet* that will contain all the rules that the compiler and linker needs to kno need a separate one for the Debug and the Release Builds. Start up with the Debug one as shown in the image below: -![image](images/AddNewPropertySheet.jpg) +![](images/AddNewPropertySheet.jpg) Use for example the *OpenCV_Debug* name. Then by selecting the sheet Right Click --\> Properties. In the following I will show to set the OpenCV rules locally, as I find unnecessary to pollute @@ -93,7 +93,7 @@ group, you should add any .c/.cpp file to the project. @code{.bash} \f$(OPENCV_DIR)\..\..\include @endcode -![image](images/PropertySheetOpenCVInclude.jpg) +![](images/PropertySheetOpenCVInclude.jpg) When adding third party libraries settings it is generally a good idea to use the power behind the environment variables. The full location of the OpenCV library may change on each system. Moreover, @@ -111,15 +111,15 @@ directory: $(OPENCV_DIR)\lib @endcode -![image](images/PropertySheetOpenCVLib.jpg) +![](images/PropertySheetOpenCVLib.jpg) Then you need to specify the libraries in which the linker should look into. To do this go to the Linker --\> Input and under the *"Additional Dependencies"* entry add the name of all modules which you want to use: -![image](images/PropertySheetOpenCVLibrariesDebugSmple.jpg) +![](images/PropertySheetOpenCVLibrariesDebugSmple.jpg) -![image](images/PropertySheetOpenCVLibrariesDebug.jpg) +![](images/PropertySheetOpenCVLibrariesDebug.jpg) The names of the libraries are as follow: @code{.bash} @@ -150,19 +150,19 @@ click ok to save and do the same with a new property inside the Release rule sec omit the *d* letters from the library names and to save the property sheets with the save icon above them. -![image](images/PropertySheetOpenCVLibrariesRelease.jpg) +![](images/PropertySheetOpenCVLibrariesRelease.jpg) You can find your property sheets inside your projects directory. At this point it is a wise decision to back them up into some special directory, to always have them at hand in the future, whenever you create an OpenCV project. Note that for Visual Studio 2010 the file extension is *props*, while for 2008 this is *vsprops*. -![image](images/PropertySheetInsideFolder.jpg) +![](images/PropertySheetInsideFolder.jpg) Next time when you make a new OpenCV project just use the "Add Existing Property Sheet..." menu entry inside the Property Manager to easily add the OpenCV build rules. -![image](images/PropertyPageAddExisting.jpg) +![](images/PropertyPageAddExisting.jpg) The *global* method ------------------- @@ -175,12 +175,12 @@ by using for instance: a Property page. In Visual Studio 2008 you can find this under the: Tools --\> Options --\> Projects and Solutions --\> VC++ Directories. -![image](images/VCDirectories2008.jpg) +![](images/VCDirectories2008.jpg) In Visual Studio 2010 this has been moved to a global property sheet which is automatically added to every project you create: -![image](images/VCDirectories2010.jpg) +![](images/VCDirectories2010.jpg) The process is the same as described in case of the local approach. Just add the include directories by using the environment variable *OPENCV_DIR*. @@ -210,7 +210,7 @@ OpenCV logo](samples/data/opencv-logo.png). Before starting up the application m the image file in your current working directory. Modify the image file name inside the code to try it out on other images too. Run it and voil á: -![image](images/SuccessVisualStudioWindows.jpg) +![](images/SuccessVisualStudioWindows.jpg) Command line arguments with Visual Studio ----------------------------------------- @@ -230,7 +230,7 @@ with the console window on the Microsoft Windows many people come to use it almo adding the same argument again and again while you are testing your application is, somewhat, a cumbersome task. Luckily, in the Visual Studio there is a menu to automate all this: -![image](images/VisualStudioCommandLineArguments.jpg) +![](images/VisualStudioCommandLineArguments.jpg) Specify here the name of the inputs and while you start your application from the Visual Studio enviroment you have automatic argument passing. In the next introductionary tutorial you'll see an diff --git a/doc/tutorials/introduction/windows_visual_studio_image_watch/windows_visual_studio_image_watch.markdown b/doc/tutorials/introduction/windows_visual_studio_image_watch/windows_visual_studio_image_watch.markdown index 2bb2d0ce54..93baedd281 100644 --- a/doc/tutorials/introduction/windows_visual_studio_image_watch/windows_visual_studio_image_watch.markdown +++ b/doc/tutorials/introduction/windows_visual_studio_image_watch/windows_visual_studio_image_watch.markdown @@ -10,10 +10,10 @@ Prerequisites This tutorial assumes that you have the following available: -1. Visual Studio 2012 Professional (or better) with Update 1 installed. Update 1 can be downloaded +-# Visual Studio 2012 Professional (or better) with Update 1 installed. Update 1 can be downloaded [here](http://www.microsoft.com/en-us/download/details.aspx?id=35774). -2. An OpenCV installation on your Windows machine (Tutorial: @ref tutorial_windows_install). -3. Ability to create and build OpenCV projects in Visual Studio (Tutorial: @ref tutorial_windows_visual_studio_Opencv). +-# An OpenCV installation on your Windows machine (Tutorial: @ref tutorial_windows_install). +-# Ability to create and build OpenCV projects in Visual Studio (Tutorial: @ref tutorial_windows_visual_studio_Opencv). Installation ------------ @@ -98,13 +98,13 @@ Launch the program in the debugger (Debug --\> Start Debugging, or hit *F5*). Wh hit, the program is paused and Visual Studio displays a yellow instruction pointer at the breakpoint: -![image](images/breakpoint.png) +![](images/breakpoint.png) Now you can inspect the state of you program. For example, you can bring up the *Locals* window (Debug --\> Windows --\> Locals), which will show the names and values of the variables in the current scope: -![image](images/vs_locals.png) +![](images/vs_locals.png) Note that the built-in *Locals* window will display text only. This is where the Image Watch plug-in comes in. Image Watch is like another *Locals* window, but with an image viewer built into it. To @@ -114,7 +114,7 @@ had Image Watch open, and where it was located between debugging sessions. This to do this once--the next time you start debugging, Image Watch will be back where you left it. Here's what the docked Image Watch window looks like at our breakpoint: -![image](images/toolwindow.jpg) +![](images/toolwindow.jpg) The radio button at the top left (*Locals/Watch*) selects what is shown in the *Image List* below: *Locals* lists all OpenCV image objects in the current scope (this list is automatically populated). @@ -128,7 +128,7 @@ If an image has a thumbnail, left-clicking on that image will select it for deta *Image Viewer* on the right. The viewer lets you pan (drag mouse) and zoom (mouse wheel). It also displays the pixel coordinate and value at the current mouse position. -![image](images/viewer.jpg) +![](images/viewer.jpg) Note that the second image in the list, *edges*, is shown as "invalid". This indicates that some data members of this image object have corrupt or invalid values (for example, a negative image @@ -146,18 +146,18 @@ Now assume you want to do a visual sanity check of the *cv::Canny()* implementat *edges* image into the viewer by selecting it in the *Image List* and zoom into a region with a clearly defined edge: -![image](images/edges_zoom.png) +![](images/edges_zoom.png) Right-click on the *Image Viewer* to bring up the view context menu and enable Link Views (a check box next to the menu item indicates whether the option is enabled). -![image](images/viewer_context_menu.png) +![](images/viewer_context_menu.png) The Link Views feature keeps the view region fixed when flipping between images of the same size. To see how this works, select the input image from the image list--you should now see the corresponding zoomed-in region in the input image: -![image](images/input_zoom.png) +![](images/input_zoom.png) You may also switch back and forth between viewing input and edges with your up/down cursor keys. That way you can easily verify that the detected edges line up nicely with the data in the input @@ -168,12 +168,12 @@ More ... Image watch has a number of more advanced features, such as -1. pinning images to a *Watch* list for inspection across scopes or between debugging sessions -2. clamping, thresholding, or diff'ing images directly inside the Watch window -3. comparing an in-memory image against a reference image from a file +-# pinning images to a *Watch* list for inspection across scopes or between debugging sessions +-# clamping, thresholding, or diff'ing images directly inside the Watch window +-# comparing an in-memory image against a reference image from a file Please refer to the online [Image Watch Documentation](http://go.microsoft.com/fwlink/?LinkId=285461) for details--you also can get to the documentation page by clicking on the *Help* link in the Image Watch window: -![image](images/help_button.jpg) +![](images/help_button.jpg) diff --git a/doc/tutorials/ios/hello/hello.markdown b/doc/tutorials/ios/hello/hello.markdown index e0cf331449..51dd8cca72 100644 --- a/doc/tutorials/ios/hello/hello.markdown +++ b/doc/tutorials/ios/hello/hello.markdown @@ -9,46 +9,45 @@ In this tutorial we will learn how to: - Link OpenCV framework with Xcode - How to write simple Hello World application using OpenCV and Xcode. -*Linking OpenCV iOS* --------------------- +Linking OpenCV iOS +------------------ Follow this step by step guide to link OpenCV to iOS. -1. Create a new XCode project. -2. Now we need to link *opencv2.framework* with Xcode. Select the project Navigator in the left +-# Create a new XCode project. +-# Now we need to link *opencv2.framework* with Xcode. Select the project Navigator in the left hand panel and click on project name. -3. Under the TARGETS click on Build Phases. Expand Link Binary With Libraries option. -4. Click on Add others and go to directory where *opencv2.framework* is located and click open -5. Now you can start writing your application. +-# Under the TARGETS click on Build Phases. Expand Link Binary With Libraries option. +-# Click on Add others and go to directory where *opencv2.framework* is located and click open +-# Now you can start writing your application. -![image](images/linking_opencv_ios.png) +![](images/linking_opencv_ios.png) -*Hello OpenCV iOS Application* ------------------------------- +Hello OpenCV iOS Application +---------------------------- Now we will learn how to write a simple Hello World Application in Xcode using OpenCV. - Link your project with OpenCV as shown in previous section. - Open the file named *NameOfProject-Prefix.pch* ( replace NameOfProject with name of your project) and add the following lines of code. -@code{.cpp} -#ifdef __cplusplus -#import -#endif -@endcode -![image](images/header_directive.png) + @code{.m} + #ifdef __cplusplus + #import + #endif + @endcode + ![](images/header_directive.png) - Add the following lines of code to viewDidLoad method in ViewController.m. -@code{.cpp} -UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Hello!" message:@"Welcome to OpenCV" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil]; -[alert show]; -@endcode -![image](images/view_did_load.png) + @code{.m} + UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Hello!" message:@"Welcome to OpenCV" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil]; + [alert show]; + @endcode + ![](images/view_did_load.png) - You are good to run the project. -*Output* --------- - -![image](images/output.png) +Output +------ +![](images/output.png) diff --git a/doc/tutorials/ios/image_manipulation/image_manipulation.markdown b/doc/tutorials/ios/image_manipulation/image_manipulation.markdown index f87f2ea04e..8abf0375ab 100644 --- a/doc/tutorials/ios/image_manipulation/image_manipulation.markdown +++ b/doc/tutorials/ios/image_manipulation/image_manipulation.markdown @@ -6,14 +6,14 @@ Goal In this tutorial we will learn how to do basic image processing using OpenCV in iOS. -*Introduction* --------------- +Introduction +------------ In *OpenCV* all the image processing operations are usually carried out on the *Mat* structure. In iOS however, to render an image on screen it have to be an instance of the *UIImage* class. To convert an *OpenCV Mat* to an *UIImage* we use the *Core Graphics* framework available in iOS. Below is the code needed to covert back and forth between Mat's and UIImage's. -@code{.cpp} +@code{.m} - (cv::Mat)cvMatFromUIImage:(UIImage *)image { CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage); @@ -37,7 +37,7 @@ is the code needed to covert back and forth between Mat's and UIImage's. return cvMat; } @endcode -@code{.cpp} +@code{.m} - (cv::Mat)cvMatGrayFromUIImage:(UIImage *)image { CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage); @@ -63,12 +63,12 @@ is the code needed to covert back and forth between Mat's and UIImage's. @endcode After the processing we need to convert it back to UIImage. The code below can handle both gray-scale and color image conversions (determined by the number of channels in the *if* statement). -@code{.cpp} +@code{.m} cv::Mat greyMat; cv::cvtColor(inputMat, greyMat, COLOR_BGR2GRAY); @endcode After the processing we need to convert it back to UIImage. -@code{.cpp} +@code{.m} -(UIImage *)UIImageFromCVMat:(cv::Mat)cvMat { NSData *data = [NSData dataWithBytes:cvMat.data length:cvMat.elemSize()*cvMat.total()]; @@ -106,10 +106,11 @@ After the processing we need to convert it back to UIImage. return finalImage; } @endcode -*Output* + +Output -------- -![image](images/output.jpg) +![](images/output.jpg) Check out an instance of running code with more Image Effects on [YouTube](http://www.youtube.com/watch?v=Ko3K_xdhJ1I) . @@ -119,4 +120,3 @@ Check out an instance of running code with more Image Effects on
\endhtmlonly - diff --git a/doc/tutorials/ios/video_processing/video_processing.markdown b/doc/tutorials/ios/video_processing/video_processing.markdown index 826e2ea3f3..2776219335 100644 --- a/doc/tutorials/ios/video_processing/video_processing.markdown +++ b/doc/tutorials/ios/video_processing/video_processing.markdown @@ -14,11 +14,11 @@ Including OpenCV library in your iOS project The OpenCV library comes as a so-called framework, which you can directly drag-and-drop into your XCode project. Download the latest binary from -\<\>. Alternatively follow this +. Alternatively follow this guide @ref tutorial_ios_install to compile the framework manually. Once you have the framework, just drag-and-drop into XCode: -![image](images/xcode_hello_ios_framework_drag_and_drop.png) +![](images/xcode_hello_ios_framework_drag_and_drop.png) Also you have to locate the prefix header that is used for all header files in the project. The file is typically located at "ProjectName/Supporting Files/ProjectName-Prefix.pch". There, you have add @@ -54,7 +54,7 @@ First, we create a simple iOS project, for example Single View Application. Then an UIImageView and UIButton to start the camera and display the video frames. The storyboard could look like that: -![image](images/xcode_hello_ios_viewcontroller_layout.png) +![](images/xcode_hello_ios_viewcontroller_layout.png) Make sure to add and connect the IBOutlets and IBActions to the corresponding ViewController: @code{.objc} @@ -127,7 +127,7 @@ should have at least the following frameworks in your project: - UIKit - Foundation - ![image](images/xcode_hello_ios_frameworks_add_dependencies.png) + ![](images/xcode_hello_ios_frameworks_add_dependencies.png) #### Processing frames diff --git a/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.markdown b/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.markdown index 63ff8fb772..9b2de2c1e3 100644 --- a/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.markdown +++ b/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.markdown @@ -23,26 +23,28 @@ In which sense is the hyperplane obtained optimal? Let's consider the following For a linearly separable set of 2D-points which belong to one of two classes, find a separating straight line. -![image](images/separating-lines.png) +![](images/separating-lines.png) @note In this example we deal with lines and points in the Cartesian plane instead of hyperplanes and vectors in a high dimensional space. This is a simplification of the problem.It is important to understand that this is done only because our intuition is better built from examples that are easy to imagine. However, the same concepts apply to tasks where the examples to classify lie in a space -whose dimension is higher than two. In the above picture you can see that there exists multiple +whose dimension is higher than two. + +In the above picture you can see that there exists multiple lines that offer a solution to the problem. Is any of them better than the others? We can intuitively define a criterion to estimate the worth of the lines: -A line is bad if it passes too close to the points because it will be noise sensitive and it will -not generalize correctly. Therefore, our goal should be to find the line passing as far as -possible from all points. +- A line is bad if it passes too close to the points because it will be noise sensitive and it will + not generalize correctly. Therefore, our goal should be to find the line passing as far as + possible from all points. Then, the operation of the SVM algorithm is based on finding the hyperplane that gives the largest minimum distance to the training examples. Twice, this distance receives the important name of **margin** within SVM's theory. Therefore, the optimal separating hyperplane *maximizes* the margin of the training data. -![image](images/optimal-hyperplane.png) +![](images/optimal-hyperplane.png) How is the optimal hyperplane computed? --------------------------------------- @@ -55,7 +57,9 @@ where \f$\beta\f$ is known as the *weight vector* and \f$\beta_{0}\f$ as the *bi @sa A more in depth description of this and hyperplanes you can find in the section 4.5 (*Seperating Hyperplanes*) of the book: *Elements of Statistical Learning* by T. Hastie, R. Tibshirani and J. H. -Friedman. The optimal hyperplane can be represented in an infinite number of different ways by +Friedman. + +The optimal hyperplane can be represented in an infinite number of different ways by scaling of \f$\beta\f$ and \f$\beta_{0}\f$. As a matter of convention, among all the possible representations of the hyperplane, the one chosen is @@ -99,7 +103,7 @@ Source Code Explanation ----------- -1. **Set up the training data** +-# **Set up the training data** The training data of this exercise is formed by a set of labeled 2D-points that belong to one of two different classes; one of the classes consists of one point and the other of three points. @@ -115,7 +119,7 @@ Explanation Mat labelsMat (4, 1, CV_32FC1, labels); @endcode -2. **Set up SVM's parameters** +-# **Set up SVM's parameters** In this tutorial we have introduced the theory of SVMs in the most simple case, when the training examples are spread into two classes that are linearly separable. However, SVMs can be @@ -149,7 +153,7 @@ Explanation less number of steps even if the optimal hyperplane has not been computed yet. This parameter is defined in a structure @ref cv::cvTermCriteria . -3. **Train the SVM** +-# **Train the SVM** We call the method [CvSVM::train](http://docs.opencv.org/modules/ml/doc/support_vector_machines.html#cvsvm-train) @@ -159,7 +163,7 @@ Explanation SVM.train(trainingDataMat, labelsMat, Mat(), Mat(), params); @endcode -4. **Regions classified by the SVM** +-# **Regions classified by the SVM** The method @ref cv::ml::SVM::predict is used to classify an input sample using a trained SVM. In this example we have used this method in order to color the space depending on the prediction done @@ -183,7 +187,7 @@ Explanation } @endcode -5. **Support vectors** +-# **Support vectors** We use here a couple of methods to obtain information about the support vectors. The method @ref cv::ml::SVM::getSupportVectors obtain all of the support @@ -209,4 +213,4 @@ Results optimal separating hyperplane. - Finally the support vectors are shown using gray rings around the training examples. -![image](images/svm_intro_result.png) +![](images/svm_intro_result.png) diff --git a/doc/tutorials/ml/non_linear_svms/non_linear_svms.markdown b/doc/tutorials/ml/non_linear_svms/non_linear_svms.markdown index b7b512b6d4..48139c04e1 100644 --- a/doc/tutorials/ml/non_linear_svms/non_linear_svms.markdown +++ b/doc/tutorials/ml/non_linear_svms/non_linear_svms.markdown @@ -61,11 +61,13 @@ region. The following picture shows non-linearly separable training data from tw separating hyperplane and the distances to their correct regions of the samples that are misclassified. -![image](images/sample-errors-dist.png) +![](images/sample-errors-dist.png) @note Only the distances of the samples that are misclassified are shown in the picture. The distances of the rest of the samples are zero since they lay already in their correct decision -region. The red and blue lines that appear on the picture are the margins to each one of the +region. + +The red and blue lines that appear on the picture are the margins to each one of the decision regions. It is very **important** to realize that each of the \f$\xi_{i}\f$ goes from a misclassified training sample to the margin of its appropriate region. @@ -93,13 +95,10 @@ or [download it from here ](samples/cpp/tutorial_code/ml/non_linear_svms/non_lin @includelineno cpp/tutorial_code/ml/non_linear_svms/non_linear_svms.cpp -lines - 1-12, 23-24, 27- - Explanation ----------- -1. **Set up the training data** +-# **Set up the training data** The training data of this exercise is formed by a set of labeled 2D-points that belong to one of two different classes. To make the exercise more appealing, the training data is generated @@ -140,7 +139,7 @@ Explanation rng.fill(c, RNG::UNIFORM, Scalar(1), Scalar(HEIGHT)); @endcode -2. **Set up SVM's parameters** +-# **Set up SVM's parameters** @sa In the previous tutorial @ref tutorial_introduction_to_svm there is an explanation of the atributes of the @@ -161,12 +160,13 @@ Explanation of obtaining a solution close to the one intuitively expected. However, we recommend to get a better insight of the problem by making adjustments to this parameter. - @note Here there are just very few points in the overlapping region between classes, giving a smaller value to **FRAC_LINEAR_SEP** the density of points can be incremented and the impact of the parameter **CvSVM::C_SVC** explored deeply. - - *Termination Criteria of the algorithm*. The maximum number of iterations has to be - increased considerably in order to solve correctly a problem with non-linearly separable - training data. In particular, we have increased in five orders of magnitude this value. + @note Here there are just very few points in the overlapping region between classes, giving a smaller value to **FRAC_LINEAR_SEP** the density of points can be incremented and the impact of the parameter **CvSVM::C_SVC** explored deeply. + + - *Termination Criteria of the algorithm*. The maximum number of iterations has to be + increased considerably in order to solve correctly a problem with non-linearly separable + training data. In particular, we have increased in five orders of magnitude this value. -3. **Train the SVM** +-# **Train the SVM** We call the method @ref cv::ml::SVM::train to build the SVM model. Watch out that the training process may take a quite long time. Have patiance when your run the program. @@ -175,7 +175,7 @@ Explanation svm.train(trainData, labels, Mat(), Mat(), params); @endcode -4. **Show the Decision Regions** +-# **Show the Decision Regions** The method @ref cv::ml::SVM::predict is used to classify an input sample using a trained SVM. In this example we have used this method in order to color the space depending on the prediction done @@ -195,7 +195,7 @@ Explanation } @endcode -5. **Show the training data** +-# **Show the training data** The method @ref cv::circle is used to show the samples that compose the training data. The samples of the class labeled with 1 are shown in light green and in light blue the samples of the class @@ -220,7 +220,7 @@ Explanation } @endcode -6. **Support vectors** +-# **Support vectors** We use here a couple of methods to obtain information about the support vectors. The method @ref cv::ml::SVM::getSupportVectors obtain all support vectors. @@ -250,7 +250,7 @@ Results and some blue points lay on the green one. - Finally the support vectors are shown using gray rings around the training examples. -![image](images/svm_non_linear_result.png) +![](images/svm_non_linear_result.png) You may observe a runtime instance of this on the [YouTube here](https://www.youtube.com/watch?v=vFv2yPcSo-Q). diff --git a/doc/tutorials/objdetect/cascade_classifier/cascade_classifier.markdown b/doc/tutorials/objdetect/cascade_classifier/cascade_classifier.markdown index fd4b39e3a8..382046fe34 100644 --- a/doc/tutorials/objdetect/cascade_classifier/cascade_classifier.markdown +++ b/doc/tutorials/objdetect/cascade_classifier/cascade_classifier.markdown @@ -113,16 +113,16 @@ Explanation Result ------ -1. Here is the result of running the code above and using as input the video stream of a build-in +-# Here is the result of running the code above and using as input the video stream of a build-in webcam: - ![image](images/Cascade_Classifier_Tutorial_Result_Haar.jpg) + ![](images/Cascade_Classifier_Tutorial_Result_Haar.jpg) Remember to copy the files *haarcascade_frontalface_alt.xml* and *haarcascade_eye_tree_eyeglasses.xml* in your current directory. They are located in *opencv/data/haarcascades* -2. This is the result of using the file *lbpcascade_frontalface.xml* (LBP trained) for the face +-# This is the result of using the file *lbpcascade_frontalface.xml* (LBP trained) for the face detection. For the eyes we keep using the file used in the tutorial. - ![image](images/Cascade_Classifier_Tutorial_Result_LBP.jpg) + ![](images/Cascade_Classifier_Tutorial_Result_LBP.jpg) diff --git a/doc/tutorials/photo/hdr_imaging/hdr_imaging.markdown b/doc/tutorials/photo/hdr_imaging/hdr_imaging.markdown index 7d5eb8dbc0..15a7079e2e 100644 --- a/doc/tutorials/photo/hdr_imaging/hdr_imaging.markdown +++ b/doc/tutorials/photo/hdr_imaging/hdr_imaging.markdown @@ -26,40 +26,43 @@ be implemented using different algorithms so take a look at the reference manual Exposure sequence ----------------- -![image](images/memorial.png) +![](images/memorial.png) -### Source Code +Source Code +----------- @includelineno cpp/tutorial_code/photo/hdr_imaging/hdr_imaging.cpp -### Explanation - -1. **Load images and exposure times** -@code{.cpp} -vector images; -vector times; -loadExposureSeq(argv[1], images, times); -@endcode -Firstly we load input images and exposure times from user-defined folder. The folder should -contain images and *list.txt* - file that contains file names and inverse exposure times. - -For our image sequence the list is following: -@code{.none} -memorial00.png 0.03125 -memorial01.png 0.0625 -... -memorial15.png 1024 -@endcode -2. **Estimate camera response** -@code{.cpp} -Mat response; -Ptr calibrate = createCalibrateDebevec(); -calibrate->process(images, response, times); -@endcode -It is necessary to know camera response function (CRF) for a lot of HDR construction algorithms. -We use one of the calibration algorithms to estimate inverse CRF for all 256 pixel values. - -3. **Make HDR image** +Explanation +----------- + +-# **Load images and exposure times** + @code{.cpp} + vector images; + vector times; + loadExposureSeq(argv[1], images, times); + @endcode + Firstly we load input images and exposure times from user-defined folder. The folder should + contain images and *list.txt* - file that contains file names and inverse exposure times. + + For our image sequence the list is following: + @code{.none} + memorial00.png 0.03125 + memorial01.png 0.0625 + ... + memorial15.png 1024 + @endcode + +-# **Estimate camera response** + @code{.cpp} + Mat response; + Ptr calibrate = createCalibrateDebevec(); + calibrate->process(images, response, times); + @endcode + It is necessary to know camera response function (CRF) for a lot of HDR construction algorithms. + We use one of the calibration algorithms to estimate inverse CRF for all 256 pixel values. + +-# **Make HDR image** @code{.cpp} Mat hdr; Ptr merge_debevec = createMergeDebevec(); @@ -68,45 +71,43 @@ merge_debevec->process(images, hdr, times, response); We use Debevec's weighting scheme to construct HDR image using response calculated in the previous item. -4. **Tonemap HDR image** -@code{.cpp} -Mat ldr; -Ptr tonemap = createTonemapDurand(2.2f); -tonemap->process(hdr, ldr); -@endcode -Since we want to see our results on common LDR display we have to map our HDR image to 8-bit range -preserving most details. It is the main goal of tonemapping methods. We use tonemapper with -bilateral filtering and set 2.2 as the value for gamma correction. - -5. **Perform exposure fusion** -@code{.cpp} -Mat fusion; -Ptr merge_mertens = createMergeMertens(); -merge_mertens->process(images, fusion); -@endcode -There is an alternative way to merge our exposures in case when we don't need HDR image. This -process is called exposure fusion and produces LDR image that doesn't require gamma correction. It -also doesn't use exposure values of the photographs. - -6. **Write results** -@code{.cpp} -imwrite("fusion.png", fusion * 255); -imwrite("ldr.png", ldr * 255); -imwrite("hdr.hdr", hdr); -@endcode -Now it's time to look at the results. Note that HDR image can't be stored in one of common image -formats, so we save it to Radiance image (.hdr). Also all HDR imaging functions return results in -[0, 1] range so we should multiply result by 255. - -### Results - -Tonemapped image ----------------- - -![image](images/ldr.png) - -Exposure fusion ---------------- - -![image](images/fusion.png) - +-# **Tonemap HDR image** + @code{.cpp} + Mat ldr; + Ptr tonemap = createTonemapDurand(2.2f); + tonemap->process(hdr, ldr); + @endcode + Since we want to see our results on common LDR display we have to map our HDR image to 8-bit range + preserving most details. It is the main goal of tonemapping methods. We use tonemapper with + bilateral filtering and set 2.2 as the value for gamma correction. + +-# **Perform exposure fusion** + @code{.cpp} + Mat fusion; + Ptr merge_mertens = createMergeMertens(); + merge_mertens->process(images, fusion); + @endcode + There is an alternative way to merge our exposures in case when we don't need HDR image. This + process is called exposure fusion and produces LDR image that doesn't require gamma correction. It + also doesn't use exposure values of the photographs. + +-# **Write results** + @code{.cpp} + imwrite("fusion.png", fusion * 255); + imwrite("ldr.png", ldr * 255); + imwrite("hdr.hdr", hdr); + @endcode + Now it's time to look at the results. Note that HDR image can't be stored in one of common image + formats, so we save it to Radiance image (.hdr). Also all HDR imaging functions return results in + [0, 1] range so we should multiply result by 255. + +Results +------- + +### Tonemapped image + +![](images/ldr.png) + +### Exposure fusion + +![](images/fusion.png) diff --git a/doc/tutorials/tutorials.markdown b/doc/tutorials/tutorials.markdown index 1d5ce58db6..886143d42a 100644 --- a/doc/tutorials/tutorials.markdown +++ b/doc/tutorials/tutorials.markdown @@ -75,8 +75,3 @@ As always, we would be happy to hear your comments and receive your contribution These tutorials show how to use Viz module effectively. -- @subpage tutorial_table_of_content_general - - These tutorials - are the bottom of the iceberg as they link together multiple of the modules presented above in - order to solve complex problems. diff --git a/doc/tutorials/video/background_subtraction/background_subtraction.markdown b/doc/tutorials/video/background_subtraction/background_subtraction.markdown index 4ec35ac5cc..bf4f3bd89c 100644 --- a/doc/tutorials/video/background_subtraction/background_subtraction.markdown +++ b/doc/tutorials/video/background_subtraction/background_subtraction.markdown @@ -9,12 +9,12 @@ How to Use Background Subtraction Methods {#tutorial_background_subtraction} general, everything that can be considered as background given the characteristics of the observed scene. - ![image](images/Background_Subtraction_Tutorial_Scheme.png) + ![](images/Background_Subtraction_Tutorial_Scheme.png) - Background modeling consists of two main steps: - 1. Background Initialization; - 2. Background Update. + -# Background Initialization; + -# Background Update. In the first step, an initial model of the background is computed, while in the second step that model is updated in order to adapt to possible changes in the scene. @@ -28,11 +28,11 @@ Goals In this tutorial you will learn how to: -1. Read data from videos by using @ref cv::VideoCapture or image sequences by using @ref +-# Read data from videos by using @ref cv::VideoCapture or image sequences by using @ref cv::imread ; -2. Create and update the background model by using @ref cv::BackgroundSubtractor class; -3. Get and show the foreground mask by using @ref cv::imshow ; -4. Save the output by using @ref cv::imwrite to quantitatively evaluate the results. +-# Create and update the background model by using @ref cv::BackgroundSubtractor class; +-# Get and show the foreground mask by using @ref cv::imshow ; +-# Save the output by using @ref cv::imwrite to quantitatively evaluate the results. Code ---- @@ -40,201 +40,28 @@ Code In the following you can find the source code. We will let the user chose to process either a video file or a sequence of images. -- - - Two different methods are used to generate two foreground masks: - 1. @ref cv::bgsegm::BackgroundSubtractorMOG - 2. @ref cv::bgsegm::BackgroundSubtractorMOG2 +Two different methods are used to generate two foreground masks: +-# @ref cv::bgsegm::BackgroundSubtractorMOG +-# @ref cv::BackgroundSubtractorMOG2 The results as well as the input data are shown on the screen. -@code{.cpp} -//opencv -#include -#include -//C -#include -//C++ -#include -#include - -using namespace cv; -using namespace std; - -//global variables -Mat frame; //current frame -Mat fgMaskMOG; //fg mask generated by MOG method -Mat fgMaskMOG2; //fg mask fg mask generated by MOG2 method -Ptr pMOG; //MOG Background subtractor -Ptr pMOG2; //MOG2 Background subtractor -int keyboard; - -//function declarations -void help(); -void processVideo(char* videoFilename); -void processImages(char* firstFrameFilename); - -void help() -{ - cout - << "--------------------------------------------------------------------------" << endl - << "This program shows how to use background subtraction methods provided by " << endl - << " OpenCV. You can process both videos (-vid) and images (-img)." << endl - << endl - << "Usage:" << endl - << "./bs {-vid