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