42 #include <visp/vpPlanarObjectDetector.h>
44 #if (VISP_HAVE_OPENCV_VERSION >= 0x020000) // Require opencv >= 2.0.0
46 #include <visp/vpImageConvert.h>
47 #include <visp/vpException.h>
48 #include <visp/vpImagePoint.h>
49 #include <visp/vpDisplay.h>
50 #include <visp/vpDisplayX.h>
51 #include <visp/vpColor.h>
52 #include <visp/vpImageTools.h>
83 load(_dataFile, _objectName);
120 std::vector < vpImagePoint > ptsx(nbpt);
121 std::vector < vpImagePoint > ptsy(nbpt);
122 for(
unsigned int i=0; i<nbpt; i++){
123 ptsx[i] = ptsy[i] = ip[i];
126 for(
unsigned int i=0; i<nbpt; i++){
127 for(
unsigned int j=0; j<nbpt-1; j++){
128 if(ptsx[j].get_j() > ptsx[j+1].get_j()){
129 double tmp = ptsx[j+1].
get_j();
130 ptsx[j+1].set_j(ptsx[j].get_j());
135 for(
unsigned int i=0; i<nbpt; i++){
136 for(
unsigned int j=0; j<nbpt-1; j++){
137 if(ptsy[j].get_i() > ptsy[j+1].get_i()){
138 double tmp = ptsy[j+1].get_i();
139 ptsy[j+1].set_i(ptsy[j].get_i());
188 unsigned int _height,
unsigned int _width)
251 for(
unsigned int i=0; i<refPts.size(); ++i){
255 for(
unsigned int i=0; i<curPts.size(); ++i){
260 if(curPts.size() < 4){
261 for (
unsigned int i = 0; i < 3; i += 1){
262 for (
unsigned int j = 0; j < 3; j += 1){
275 std::vector<unsigned char> mask;
276 H = cv::findHomography(cv::Mat(refPts), cv::Mat(curPts), mask, cv::RANSAC, 10);
280 const cv::Mat_<double>& H_tmp =
H;
282 for(
unsigned int i = 0; i < 4; i++ )
286 double w = 1./(H_tmp(2,0)*pt.x + H_tmp(2,1)*pt.y + H_tmp(2,2));
287 dst_corners[i] = cv::Point2f((
float)((H_tmp(0,0)*pt.x + H_tmp(0,1)*pt.y + H_tmp(0,2))*w),
288 (
float)((H_tmp(1,0)*pt.x + H_tmp(1,1)*pt.y + H_tmp(1,2))*w));
291 double* ptr = (
double*)H_tmp.data;
292 for(
unsigned int i=0; i<9; i++){
293 this->
homography[(
unsigned int)(i/3)][i%3] = *(ptr++);
304 for (
unsigned int i = 0; i < mask.size(); i += 1){
307 ip.
set_i(curPts[i].y);
308 ip.
set_j(curPts[i].x);
310 ip.
set_i(refPts[i].y);
311 ip.
set_j(refPts[i].x);
340 const vpImagePoint &iP,
const unsigned int height,
const unsigned int width)
344 vpTRACE(
"Bad size for the subimage");
346 "Bad size for the subimage"));
352 (
unsigned int)iP.
get_i(),
353 (
unsigned int)iP.
get_j(),
354 height, width, subImage);
378 (
unsigned int)rectangle.
getWidth()));
435 display(Icurrent, displayKpts);
484 std::vector<vpImagePoint>
487 std::vector <vpImagePoint> corners;
491 corners.push_back(ip);
507 ip.y = (float)_modelROI.y;
508 ip.x = (
float)_modelROI.x;
511 ip.y = (float)(_modelROI.y+_modelROI.height);
512 ip.x = (float)_modelROI.x;
515 ip.y = (float)(_modelROI.y+_modelROI.height);
516 ip.x = (float)(_modelROI.x+_modelROI.width);
519 ip.y = (float)_modelROI.y;
520 ip.x = (
float)(_modelROI.x+_modelROI.width);