|
| 1 | +// This file is part of OpenCV project. |
| 2 | +// It is subject to the license terms in the LICENSE file found in the top-level directory |
| 3 | +// of this distribution and at http://opencv.org/license.html. |
| 4 | + |
| 5 | +#ifndef OPENCV_RAPID_HPP_ |
| 6 | +#define OPENCV_RAPID_HPP_ |
| 7 | + |
| 8 | +#include <opencv2/core.hpp> |
| 9 | +#include <opencv2/imgproc.hpp> |
| 10 | + |
| 11 | +/** |
| 12 | +@defgroup rapid silhouette based 3D object tracking |
| 13 | +
|
| 14 | +implements "RAPID-a video rate object tracker" @cite harris1990rapid with the dynamic control point extraction of @cite drummond2002real |
| 15 | +*/ |
| 16 | + |
| 17 | +namespace cv |
| 18 | +{ |
| 19 | +namespace rapid |
| 20 | +{ |
| 21 | +//! @addtogroup rapid |
| 22 | +//! @{ |
| 23 | + |
| 24 | +/** |
| 25 | + * Debug draw markers of matched correspondences onto a lineBundle |
| 26 | + * @param bundle the lineBundle |
| 27 | + * @param srcLocations the according source locations |
| 28 | + * @param newLocations matched source locations |
| 29 | + * @param colors colors for the markers. Defaults to white. |
| 30 | + */ |
| 31 | +CV_EXPORTS_W void drawCorrespondencies(InputOutputArray bundle, InputArray srcLocations, |
| 32 | + InputArray newLocations, InputArray colors = noArray()); |
| 33 | +/** |
| 34 | + * Debug draw search lines onto an image |
| 35 | + * @param img the output image |
| 36 | + * @param locations the source locations of a line bundle |
| 37 | + * @param color the line color |
| 38 | + */ |
| 39 | +CV_EXPORTS_W void drawSearchLines(InputOutputArray img, InputArray locations, const Scalar& color); |
| 40 | + |
| 41 | +/** |
| 42 | + * Draw a wireframe of a triangle mesh |
| 43 | + * @param img the output image |
| 44 | + * @param pts2d the 2d points obtained by @ref projectPoints |
| 45 | + * @param tris triangle face connectivity |
| 46 | + * @param color line color |
| 47 | + * @param type line type. See @ref LineTypes. |
| 48 | + * @param cullBackface enable back-face culling based on CCW order |
| 49 | + */ |
| 50 | +CV_EXPORTS_W void drawWireframe(InputOutputArray img, InputArray pts2d, InputArray tris, |
| 51 | + const Scalar& color, int type = LINE_8, bool cullBackface = false); |
| 52 | +/** |
| 53 | + * Extract control points from the projected silhouette of a mesh |
| 54 | + * |
| 55 | + * see @cite drummond2002real Sec 2.1, Step b |
| 56 | + * @param num number of control points |
| 57 | + * @param len search radius (used to restrict the ROI) |
| 58 | + * @param pts3d the 3D points of the mesh |
| 59 | + * @param rvec rotation between mesh and camera |
| 60 | + * @param tvec translation between mesh and camera |
| 61 | + * @param K camera intrinsic |
| 62 | + * @param imsize size of the video frame |
| 63 | + * @param tris triangle face connectivity |
| 64 | + * @param ctl2d the 2D locations of the control points |
| 65 | + * @param ctl3d matching 3D points of the mesh |
| 66 | + */ |
| 67 | +CV_EXPORTS_W void extractControlPoints(int num, int len, InputArray pts3d, InputArray rvec, InputArray tvec, |
| 68 | + InputArray K, const Size& imsize, InputArray tris, OutputArray ctl2d, |
| 69 | + OutputArray ctl3d); |
| 70 | +/** |
| 71 | + * Extract the line bundle from an image |
| 72 | + * @param len the search radius. The bundle will have `2*len + 1` columns. |
| 73 | + * @param ctl2d the search lines will be centered at this points and orthogonal to the contour defined by |
| 74 | + * them. The bundle will have as many rows. |
| 75 | + * @param img the image to read the pixel intensities values from |
| 76 | + * @param bundle line bundle image with size `ctl2d.rows() x (2 * len + 1)` and the same type as @p img |
| 77 | + * @param srcLocations the source pixel locations of @p bundle in @p img as CV_16SC2 |
| 78 | + */ |
| 79 | +CV_EXPORTS_W void extractLineBundle(int len, InputArray ctl2d, InputArray img, OutputArray bundle, |
| 80 | + OutputArray srcLocations); |
| 81 | + |
| 82 | +/** |
| 83 | + * Find corresponding image locations by searching for a maximal sobel edge along the search line (a single |
| 84 | + * row in the bundle) |
| 85 | + * @param bundle the line bundle |
| 86 | + * @param srcLocations the according source image location |
| 87 | + * @param newLocations image locations with maximal edge along the search line |
| 88 | + * @param response the sobel response for the selected point |
| 89 | + */ |
| 90 | +CV_EXPORTS_W void findCorrespondencies(InputArray bundle, InputArray srcLocations, OutputArray newLocations, |
| 91 | + OutputArray response = noArray()); |
| 92 | + |
| 93 | +/** |
| 94 | + * Filter corresponding 2d and 3d points based on mask |
| 95 | + * @param pts2d 2d points |
| 96 | + * @param pts3d 3d points |
| 97 | + * @param mask mask containing non-zero values for the elements to be retained |
| 98 | + */ |
| 99 | +CV_EXPORTS_W void filterCorrespondencies(InputOutputArray pts2d, InputOutputArray pts3d, InputArray mask); |
| 100 | + |
| 101 | +/** |
| 102 | + * High level function to execute a single rapid @cite harris1990rapid iteration |
| 103 | + * |
| 104 | + * 1. @ref extractControlPoints |
| 105 | + * 2. @ref extractLineBundle |
| 106 | + * 3. @ref findCorrespondencies |
| 107 | + * 4. @ref filterCorrespondencies |
| 108 | + * 5. @ref solvePnPRefineLM |
| 109 | + * |
| 110 | + * @param img the video frame |
| 111 | + * @param num number of search lines |
| 112 | + * @param len search line radius |
| 113 | + * @param pts3d the 3D points of the mesh |
| 114 | + * @param tris triangle face connectivity |
| 115 | + * @param K camera matrix |
| 116 | + * @param rvec rotation between mesh and camera. Input values are used as an initial solution. |
| 117 | + * @param tvec translation between mesh and camera. Input values are used as an initial solution. |
| 118 | + * @return ratio of search lines that could be extracted and matched |
| 119 | + */ |
| 120 | +CV_EXPORTS_W float rapid(InputArray img, int num, int len, InputArray pts3d, InputArray tris, InputArray K, |
| 121 | + InputOutputArray rvec, InputOutputArray tvec); |
| 122 | +//! @} |
| 123 | +} /* namespace rapid */ |
| 124 | +} /* namespace cv */ |
| 125 | + |
| 126 | +#endif /* OPENCV_RAPID_HPP_ */ |
0 commit comments