Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
ImageDisplay.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 <Foundation/Foundation.h>
34
35#import "ImageDisplay.h"
36
37@implementation ImageDisplay
38
40// UIImage *image = <the image you want to add a line to>
41// vpImagePoint &ip1 = Line first point
42// vpImagePoint &ip2 = Line second point
43// UIColor *color = <the color of the line>
44// int tickness = <the tickness of the lines on the AprilTag contour>
45+ (UIImage *)displayLine:(UIImage *)image :(vpImagePoint &)ip1 :(vpImagePoint &)ip2 :(UIColor*)color :(int)tickness
46{
47 UIGraphicsBeginImageContext(image.size);
48
49 // Draw the original image as the background
50 [image drawAtPoint:CGPointMake(0,0)];
51
52 // Draw the line on top of original image
53 CGContextRef context = UIGraphicsGetCurrentContext();
54 CGContextSetLineWidth(context, tickness);
55 CGContextSetStrokeColorWithColor(context, [color CGColor]);
56
57 CGContextMoveToPoint(context, ip1.get_u(), ip1.get_v());
58 CGContextAddLineToPoint(context, ip2.get_u(), ip2.get_v());
59
60 CGContextStrokePath(context);
61
62 // Create new image
63 UIImage *retImage = UIGraphicsGetImageFromCurrentImageContext();
64
65 // Tidy up
66 UIGraphicsEndImageContext();
67 return retImage;
68}
70
72// UIImage *image = <the image you want to add a line to>
73// vpHomogeneousMatrix cMo = <Homegeneous transformation>
74// vpCameraParameters cam = <Camera parameters>
75// double size = <Size of the frame in meter>
76// int tickness = <the tickness of the lines describing the frame>
77+ (UIImage *)displayFrame:(UIImage *)image :(const vpHomogeneousMatrix &)cMo :(const vpCameraParameters &)cam
78 :(double) size :(int)tickness
79{
80 UIGraphicsBeginImageContext(image.size);
81
82 // Draw the original image as the background
83 [image drawAtPoint:CGPointMake(0,0)];
84
85 vpPoint o( 0.0, 0.0, 0.0);
86 vpPoint x(size, 0.0, 0.0);
87 vpPoint y( 0.0, size, 0.0);
88 vpPoint z( 0.0, 0.0, size);
89
90 o.track(cMo);
91 x.track(cMo);
92 y.track(cMo);
93 z.track(cMo);
94
95 vpImagePoint ipo, ip1;
96
97 vpMeterPixelConversion::convertPoint (cam, o.p[0], o.p[1], ipo);
98
99 // Draw red line on top of original image
100 vpMeterPixelConversion::convertPoint (cam, x.p[0], x.p[1], ip1);
101 CGContextRef context = UIGraphicsGetCurrentContext();
102 CGContextSetLineWidth(context, tickness);
103 CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
104 CGContextMoveToPoint(context, ipo.get_u(), ipo.get_v());
105 CGContextAddLineToPoint(context, ip1.get_u(), ip1.get_v());
106 CGContextStrokePath(context);
107
108 // Draw green line on top of original image
109 vpMeterPixelConversion::convertPoint ( cam, y.p[0], y.p[1], ip1) ;
110 context = UIGraphicsGetCurrentContext();
111 CGContextSetLineWidth(context, tickness);
112 CGContextSetStrokeColorWithColor(context, [[UIColor greenColor] CGColor]);
113 CGContextMoveToPoint(context, ipo.get_u(), ipo.get_v());
114 CGContextAddLineToPoint(context, ip1.get_u(), ip1.get_v());
115 CGContextStrokePath(context);
116
117 // Draw blue line on top of original image
118 vpMeterPixelConversion::convertPoint ( cam, z.p[0], z.p[1], ip1) ;
119 context = UIGraphicsGetCurrentContext();
120 CGContextSetLineWidth(context, tickness);
121 CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]);
122 CGContextMoveToPoint(context, ipo.get_u(), ipo.get_v());
123 CGContextAddLineToPoint(context, ip1.get_u(), ip1.get_v());
124 CGContextStrokePath(context);
125
126 // Create new image
127 UIImage *retImage = UIGraphicsGetImageFromCurrentImageContext();
128
129 // Tidy up
130 UIGraphicsEndImageContext();
131 return retImage;
132}
134
135@end
136
137#endif
Generic class defining intrinsic camera parameters.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
double get_u() const
double get_v() const
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)