39 #include <visp3/vision/vpPlanarObjectDetector.h>
41 #if (VISP_HAVE_OPENCV_VERSION >= 0x020000) && \
42 (VISP_HAVE_OPENCV_VERSION < 0x030000) // Require opencv >= 2.0.0 and < 3.0.0
44 #include <visp3/core/vpColor.h>
45 #include <visp3/core/vpDisplay.h>
46 #include <visp3/core/vpException.h>
47 #include <visp3/core/vpImageConvert.h>
48 #include <visp3/core/vpImagePoint.h>
49 #include <visp3/core/vpImageTools.h>
60 : fern(), homography(), H(), dst_corners(), isCorrect(false), ref_corners(), modelROI(), currentImagePoints(),
61 refImagePoints(), minNbMatching(10)
74 : fern(), homography(), H(), dst_corners(), isCorrect(false), ref_corners(), modelROI(), currentImagePoints(),
75 refImagePoints(), minNbMatching(10)
77 load(_dataFile, _objectName);
105 std::vector<vpImagePoint> ptsx(nbpt);
106 std::vector<vpImagePoint> ptsy(nbpt);
107 for (
unsigned int i = 0; i < nbpt; i++) {
108 ptsx[i] = ptsy[i] = ip[i];
111 for (
unsigned int i = 0; i < nbpt; i++) {
112 for (
unsigned int j = 0; j < nbpt - 1; j++) {
113 if (ptsx[j].get_j() > ptsx[j + 1].get_j()) {
114 double tmp = ptsx[j + 1].
get_j();
115 ptsx[j + 1].set_j(ptsx[j].get_j());
120 for (
unsigned int i = 0; i < nbpt; i++) {
121 for (
unsigned int j = 0; j < nbpt - 1; j++) {
122 if (ptsy[j].get_i() > ptsy[j + 1].get_i()) {
123 double tmp = ptsy[j + 1].get_i();
124 ptsy[j + 1].set_i(ptsy[j].get_i());
167 unsigned int _height,
unsigned int _width)
224 for (
unsigned int i = 0; i < refPts.size(); ++i) {
228 for (
unsigned int i = 0; i < curPts.size(); ++i) {
233 if (curPts.size() < 4) {
234 for (
unsigned int i = 0; i < 3; i += 1) {
235 for (
unsigned int j = 0; j < 3; j += 1) {
247 std::vector<unsigned char> mask;
248 H = cv::findHomography(cv::Mat(refPts), cv::Mat(curPts), mask, cv::RANSAC, 10);
251 const cv::Mat_<double> &H_tmp =
H;
253 for (
unsigned int i = 0; i < 4; i++) {
256 double w = 1. / (H_tmp(2, 0) * pt.x + H_tmp(2, 1) * pt.y + H_tmp(2, 2));
257 dst_corners[i] = cv::Point2f((
float)((H_tmp(0, 0) * pt.x + H_tmp(0, 1) * pt.y + H_tmp(0, 2)) * w),
258 (
float)((H_tmp(1, 0) * pt.x + H_tmp(1, 1) * pt.y + H_tmp(1, 2)) * w));
261 double *ptr = (
double *)H_tmp.data;
262 for (
unsigned int i = 0; i < 9; i++) {
263 this->
homography[(
unsigned int)(i / 3)][i % 3] = *(ptr++);
272 for (
unsigned int i = 0; i < mask.size(); i += 1) {
275 ip.
set_i(curPts[i].y);
276 ip.
set_j(curPts[i].x);
278 ip.
set_i(refPts[i].y);
279 ip.
set_j(refPts[i].x);
305 unsigned int height,
unsigned int width)
308 vpTRACE(
"Bad size for the subimage");
350 for (
unsigned int i = 0; i <
dst_corners.size(); i++) {
384 display(Icurrent, displayKpts);
430 std::vector<vpImagePoint> corners;
432 for (
unsigned int i = 0; i <
dst_corners.size(); i++) {
434 corners.push_back(ip);
449 ip.y = (float)_modelROI.y;
450 ip.x = (
float)_modelROI.x;
453 ip.y = (float)(_modelROI.y + _modelROI.height);
454 ip.x = (float)_modelROI.x;
457 ip.y = (float)(_modelROI.y + _modelROI.height);
458 ip.x = (float)(_modelROI.x + _modelROI.width);
461 ip.y = (float)_modelROI.y;
462 ip.x = (
float)(_modelROI.x + _modelROI.width);
486 #elif !defined(VISP_BUILD_SHARED_LIBS)
489 void dummy_vpPlanarObjectDetector(){};