Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
ViewController.mm
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 */
30
31#ifndef DOXYGEN_SHOULD_SKIP_THIS
32
33#import "ViewController.h"
34#ifdef __cplusplus
35#import <visp3/visp.h>
36#endif
37
38@interface ViewController ()
39@end
40
41@implementation ViewController
42#pragma mark - Example of a function that uses ViSP
43- (void)processViSPHomography{
44
45 std::vector<vpPoint> oP(4), aP(4), bP(4);
46 double L = 0.1;
47
48 oP[0].setWorldCoordinates( -L,-L, 0);
49 oP[1].setWorldCoordinates(2*L,-L, 0);
50 oP[2].setWorldCoordinates( L, 3*L, 0);
51 oP[3].setWorldCoordinates( -L, 4*L, 0);
52
53 vpHomogeneousMatrix bMo(0,0, 1, 0, 0, 0) ;
54 vpHomogeneousMatrix aMb(0.2, 0, 0.1, 0,vpMath::rad(20), 0);
55 vpHomogeneousMatrix aMo = aMb*bMo ;
56
57 // Normalized coordinates of points in the image frame
58 std::vector<double> xa(4), ya(4), xb(4), yb(4);
59
60 for(int i=0 ; i < 4; i++){
61 oP[i].project(aMo);
62 xa[i] = oP[i].get_x();
63 ya[i] = oP[i].get_y();
64 oP[i].project(bMo);
65 xb[i] = oP[i].get_x();
66 yb[i] = oP[i].get_y();
67 }
68
69 vpHomography aHb ;
70
71 // Compute the homography
72 vpHomography::DLT(xb, yb, xa, ya, aHb, true);
73
74 std::cout << "Homography:\n" << aHb << std::endl;
75
76 vpRotationMatrix aRb;
77 vpTranslationVector atb;
78 vpColVector n;
79
80 // Compute the 3D transformation
81 aHb.computeDisplacement(aRb, atb, n);
82
83 std::cout << "atb: " << atb.t() << std::endl;
84
85 // Compute coordinates in pixels of point 3
86 vpImagePoint iPa, iPb;
87 vpCameraParameters cam;
88 vpMeterPixelConversion::convertPoint(cam, xb[3], yb[3], iPb);
89 vpMeterPixelConversion::convertPoint(cam, xa[3], ya[3], iPa);
90
91 std::cout << "Ground truth:" << std::endl;
92 std::cout << " Point 3 in pixels in frame b: " << iPb << std::endl;
93 std::cout << " Point 3 in pixels in frame a: " << iPa << std::endl;
94
95 // Estimate the position in pixel of point 3 from the homography
96 vpMatrix H = cam.get_K() * aHb * cam.get_K_inverse();
97
98 // Project the position in pixel of point 3 from the homography
99 std::cout << "Estimation from homography:" << std::endl;
100 std::cout << " Point 3 in pixels in frame a: " << vpHomography::project(cam, aHb, iPb) << std::endl;
101}
102- (void)viewDidLoad {
103 [super viewDidLoad];
104 // Do any additional setup after loading the view, typically from a nib.
105 [self processViSPHomography];
106}
107- (void)didReceiveMemoryWarning {
108 [super didReceiveMemoryWarning];
109 // Dispose of any resources that can be recreated.
110}
111@end
112
113#endif
static void DLT(const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, vpHomography &aHb, bool normalization=true)
void computeDisplacement(vpRotationMatrix &aRb, vpTranslationVector &atb, vpColVector &n)
static vpImagePoint project(const vpCameraParameters &cam, const vpHomography &bHa, const vpImagePoint &iPa)
static double rad(double deg)
Definition vpMath.h:129
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)