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#import "ImageConversion.h"
35#ifdef __cplusplus
36#import <visp3/visp.h>
37#endif
38
39#ifndef DOXYGEN_SHOULD_SKIP_THIS
40@interface ViewController ()
41@end
42
43@implementation ViewController
44
45// Define the different process we want to apply to the input image
46NSArray *process = [[NSArray alloc]initWithObjects:@"load image", @"convert to gray", @"compute gradient",
47#if defined(VISP_HAVE_OPENCV)
48 @"canny detector",
49#endif
50 nil];
51
52@synthesize myImageView;
53#endif
54
55- (void)viewDidLoad {
56
57 [super viewDidLoad];
58
59 // create an image
60 UIImage *myScreenShot = [UIImage imageNamed:@"monkey.png"];
61
62 // image view instance to display the image
63 self.myImageView = [[UIImageView alloc] initWithImage:myScreenShot];
64
65 // set the frame for the image view
66 CGRect myFrame = CGRectMake(0.0f, 0.0f, self.myImageView.frame.size.width*2, self.myImageView.frame.size.height*2);
67 [self.myImageView setFrame:myFrame];
68
69 // add the image view to the current view
70 [self.view addSubview:self.myImageView];
71
72 // create buttons
73 CGFloat posx=140, posy=350;
74 CGFloat padding = 50;
75 CGSize button_size = CGSizeMake( 150, 25 );
76 for (int i=0; i<[process count]; i++) {
77 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
78 [button addTarget:self action:@selector(checkButtonClick:) forControlEvents:UIControlEventTouchUpInside];
79 [button setTitle:[process objectAtIndex: i] forState:UIControlStateNormal];
80
81 button.frame = CGRectMake(posx, posy+i*padding, button_size.width, button_size.height);
82 [button setBackgroundColor:[UIColor blueColor]];
83 [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
84 button.layer.cornerRadius = 10;
85 [self.view addSubview:button];
86 }
87}
88
89- (void) checkButtonClick:(UIButton *)paramSender{
90
91 UIButton *myButton = paramSender;
92
93 //check which button was tapped
94 if([myButton.currentTitle isEqualToString:[process objectAtIndex: 0]]){
95 // load image
96 NSLog(@"Clicked on \"%@\" button ", [process objectAtIndex: 0]);
97
98 [myImageView setImage:[UIImage imageNamed:@"monkey.png"]];
99 }
100 else if([myButton.currentTitle isEqualToString:[process objectAtIndex: 1]]){
101 // convert to gray
102 NSLog(@"Clicked on \"%@\" button ", [process objectAtIndex: 1]);
103
104 UIImage *img = [UIImage imageNamed:@"monkey.png"];
105 vpImage<unsigned char> gray = [ImageConversion vpImageGrayFromUIImage:img];
106 [myImageView setImage:[ImageConversion UIImageFromVpImageGray:gray]];
107 }
108 else if([myButton.currentTitle isEqualToString:[process objectAtIndex: 2]]){
109 // compute gradient
110 NSLog(@"Clicked on \"%@\" button ", [process objectAtIndex: 2]);
111
112 UIImage *img = [UIImage imageNamed:@"monkey.png"];
113 vpImage<unsigned char> gray = [ImageConversion vpImageGrayFromUIImage:img];
114 vpImage<double> dIx;
115 vpImageFilter::getGradX(gray, dIx);
116 vpImageConvert::convert(dIx, gray);
117
118 [myImageView setImage:[ImageConversion UIImageFromVpImageGray:gray]];
119 }
120 else if([myButton.currentTitle isEqualToString:[process objectAtIndex: 3]]){
121 // canny detector
122 NSLog(@"Clicked on \"%@\" button ", [process objectAtIndex: 3]);
123
124 UIImage *img = [UIImage imageNamed:@"monkey.png"];
125 vpImage<unsigned char> gray = [ImageConversion vpImageGrayFromUIImage:img];
126 vpImage<unsigned char> canny;
127 vpImageFilter::canny(gray, canny, 5, 15, 3);
128 [myImageView setImage:[ImageConversion UIImageFromVpImageGray:canny]];
129 }
130}
131
132- (void)didReceiveMemoryWarning {
133 [super didReceiveMemoryWarning];
134 // Dispose of any resources that can be recreated.
135}
136
137@end
138
139#endif