Visual Servoing Platform  version 3.4.1 under development (2021-04-20)
ImageDisplay+withContext.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 #import "ImageDisplay+withContext.h"
34 
36 
38 // UIColor *color = <the color of the line>
39 // int tickness = <the tickness of the lines on the AprilTag contour>
40 + (void)displayLineWithContext:(CGContextRef)context :(std::vector<vpImagePoint>)polygon :(UIColor*)color :(int)tickness
41 {
42 
43  CGContextSetLineWidth(context, tickness);
44  CGContextSetStrokeColorWithColor(context, [color CGColor]);
45  for (size_t j = 0; j < polygon.size(); j++) {
46 
47  CGContextMoveToPoint(context, polygon[j].get_u(), polygon[j].get_v());
48  CGContextAddLineToPoint(context, polygon[(j+1)%polygon.size()].get_u(), polygon[(j+1)%polygon.size()].get_v());
49 
50  CGContextStrokePath(context);
51  }
52 
53  return;
54 }
56 
58 // vpHomogeneousMatrix cMo = <Homegeneous transformation>
59 // vpCameraParameters cam = <Camera parameters>
60 // double size = <Size of the frame in meter>
61 // int tickness = <the tickness of the lines describing the frame>
62 + (void)displayFrameWithContext:(CGContextRef)context :(const vpHomogeneousMatrix &)cMo :(const vpCameraParameters &)cam
63  :(double) size :(int)tickness
64 {
65 
66  vpPoint o( 0.0, 0.0, 0.0);
67  vpPoint x(size, 0.0, 0.0);
68  vpPoint y( 0.0, size, 0.0);
69  vpPoint z( 0.0, 0.0, size);
70 
71  o.track(cMo);
72  x.track(cMo);
73  y.track(cMo);
74  z.track(cMo);
75 
76  vpImagePoint ipo, ip1;
77  vpMeterPixelConversion::convertPoint (cam, o.p[0], o.p[1], ipo);
78 
79  // Draw red line on top of original image
80  vpMeterPixelConversion::convertPoint (cam, x.p[0], x.p[1], ip1);
81  CGContextSetLineWidth(context, tickness);
82  CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
83  CGContextMoveToPoint(context, ipo.get_u(), ipo.get_v());
84  CGContextAddLineToPoint(context, ip1.get_u(), ip1.get_v());
85  CGContextStrokePath(context);
86 
87  // Draw green line on top of original image
88  vpMeterPixelConversion::convertPoint ( cam, y.p[0], y.p[1], ip1) ;
89  context = UIGraphicsGetCurrentContext();
90  CGContextSetLineWidth(context, tickness);
91  CGContextSetStrokeColorWithColor(context, [[UIColor greenColor] CGColor]);
92  CGContextMoveToPoint(context, ipo.get_u(), ipo.get_v());
93  CGContextAddLineToPoint(context, ip1.get_u(), ip1.get_v());
94  CGContextStrokePath(context);
95 
96  // Draw blue line on top of original image
97  vpMeterPixelConversion::convertPoint ( cam, z.p[0], z.p[1], ip1) ;
98  context = UIGraphicsGetCurrentContext();
99  CGContextSetLineWidth(context, tickness);
100  CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]);
101  CGContextMoveToPoint(context, ipo.get_u(), ipo.get_v());
102  CGContextAddLineToPoint(context, ip1.get_u(), ip1.get_v());
103  CGContextStrokePath(context);
104 
105  return;
106 }
108 
110 + (void)displayText:(NSString*)text :(double)x :(double)y :(int)width :(int)height :(UIColor*)color :(UIColor*)bgColor{
111 
112  CGRect rect = CGRectMake(x,y,width,height);
113 
114  NSDictionary *attributes =
115  @{
116  NSForegroundColorAttributeName : color,
117  NSFontAttributeName : [UIFont boldSystemFontOfSize:50],
118  NSBackgroundColorAttributeName: bgColor
119  };
120 
121  [text drawInRect:CGRectIntegral(rect) withAttributes:attributes];
122 
123  return;
124 }
126 
127 @end
128 
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)
void track(const vpHomogeneousMatrix &cMo)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:81
double get_u() const
Definition: vpImagePoint.h:262
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:87
vpColVector p
Definition: vpTracker.h:73
double get_v() const
Definition: vpImagePoint.h:273