Visual Servoing Platform  version 3.1.0
ImageDisplay.mm
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  *****************************************************************************/
32 
33 #ifndef DOXYGEN_SHOULD_SKIP_THIS
34 
35 #import <Foundation/Foundation.h>
36 
37 #import "ImageDisplay.h"
38 
39 @implementation ImageDisplay
40 
42 // UIImage *image = <the image you want to add a line to>
43 // vpImagePoint &ip1 = Line first point
44 // vpImagePoint &ip2 = Line second point
45 // UIColor *color = <the color of the line>
46 // int tickness = <the tickness of the lines on the AprilTag contour>
47 + (UIImage *)displayLine:(UIImage *)image :(vpImagePoint &)ip1 :(vpImagePoint &)ip2 :(UIColor*)color :(int)tickness
48 {
49  UIGraphicsBeginImageContext(image.size);
50 
51  // Draw the original image as the background
52  [image drawAtPoint:CGPointMake(0,0)];
53 
54  // Draw the line on top of original image
55  CGContextRef context = UIGraphicsGetCurrentContext();
56  CGContextSetLineWidth(context, tickness);
57  CGContextSetStrokeColorWithColor(context, [color CGColor]);
58 
59  CGContextMoveToPoint(context, ip1.get_u(), ip1.get_v());
60  CGContextAddLineToPoint(context, ip2.get_u(), ip2.get_v());
61 
62  CGContextStrokePath(context);
63 
64  // Create new image
65  UIImage *retImage = UIGraphicsGetImageFromCurrentImageContext();
66 
67  // Tidy up
68  UIGraphicsEndImageContext();
69  return retImage;
70 }
72 
74 // UIImage *image = <the image you want to add a line to>
75 // vpHomogeneousMatrix cMo = <Homegeneous transformation>
76 // vpCameraParameters cam = <Camera parameters>
77 // double size = <Size of the frame in meter>
78 // int tickness = <the tickness of the lines describing the frame>
79 + (UIImage *)displayFrame:(UIImage *)image :(const vpHomogeneousMatrix &)cMo :(const vpCameraParameters &)cam
80  :(double) size :(int)tickness
81 {
82  UIGraphicsBeginImageContext(image.size);
83 
84  // Draw the original image as the background
85  [image drawAtPoint:CGPointMake(0,0)];
86 
87  vpPoint o( 0.0, 0.0, 0.0);
88  vpPoint x(size, 0.0, 0.0);
89  vpPoint y( 0.0, size, 0.0);
90  vpPoint z( 0.0, 0.0, size);
91 
92  o.track(cMo);
93  x.track(cMo);
94  y.track(cMo);
95  z.track(cMo);
96 
97  vpImagePoint ipo, ip1;
98 
99  vpMeterPixelConversion::convertPoint (cam, o.p[0], o.p[1], ipo);
100 
101  // Draw red line on top of original image
102  vpMeterPixelConversion::convertPoint (cam, x.p[0], x.p[1], ip1);
103  CGContextRef context = UIGraphicsGetCurrentContext();
104  CGContextSetLineWidth(context, tickness);
105  CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
106  CGContextMoveToPoint(context, ipo.get_u(), ipo.get_v());
107  CGContextAddLineToPoint(context, ip1.get_u(), ip1.get_v());
108  CGContextStrokePath(context);
109 
110  // Draw green line on top of original image
111  vpMeterPixelConversion::convertPoint ( cam, y.p[0], y.p[1], ip1) ;
112  context = UIGraphicsGetCurrentContext();
113  CGContextSetLineWidth(context, tickness);
114  CGContextSetStrokeColorWithColor(context, [[UIColor greenColor] CGColor]);
115  CGContextMoveToPoint(context, ipo.get_u(), ipo.get_v());
116  CGContextAddLineToPoint(context, ip1.get_u(), ip1.get_v());
117  CGContextStrokePath(context);
118 
119  // Draw blue line on top of original image
120  vpMeterPixelConversion::convertPoint ( cam, z.p[0], z.p[1], ip1) ;
121  context = UIGraphicsGetCurrentContext();
122  CGContextSetLineWidth(context, tickness);
123  CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]);
124  CGContextMoveToPoint(context, ipo.get_u(), ipo.get_v());
125  CGContextAddLineToPoint(context, ip1.get_u(), ip1.get_v());
126  CGContextStrokePath(context);
127 
128  // Create new image
129  UIImage *retImage = UIGraphicsGetImageFromCurrentImageContext();
130 
131  // Tidy up
132  UIGraphicsEndImageContext();
133  return retImage;
134 }
136 
137 @end
138 
139 #endif
140 
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
Class that defines what is a point.
Definition: vpPoint.h:58
double get_u() const
Definition: vpImagePoint.h:263
Generic class defining intrinsic camera parameters.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
double get_v() const
Definition: vpImagePoint.h:274