1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package org.openimaj.demos.video.utils;
31
32 import java.awt.event.MouseEvent;
33 import java.awt.event.MouseListener;
34
35 import javax.swing.JFrame;
36
37 import org.openimaj.feature.local.list.LocalFeatureList;
38 import org.openimaj.image.DisplayUtilities;
39 import org.openimaj.image.FImage;
40 import org.openimaj.image.Image;
41 import org.openimaj.image.feature.local.engine.ipd.InterestPointImageExtractorProperties;
42 import org.openimaj.image.feature.local.interest.InterestPointData;
43 import org.openimaj.image.feature.local.keypoints.InterestPointKeypoint;
44 import org.openimaj.image.processing.convolution.FGaussianConvolve;
45 import org.openimaj.image.processing.resize.ResizeProcessor;
46 import org.openimaj.image.processor.SinglebandImageProcessor;
47 import org.openimaj.math.geometry.point.Point2dImpl;
48 import org.openimaj.math.geometry.shape.Circle;
49
50
51
52
53
54
55
56
57 public class FeatureClickListener<S,T extends Image<S,T> & SinglebandImageProcessor.Processable<Float,FImage,T> > implements MouseListener {
58
59 private LocalFeatureList<InterestPointKeypoint<InterestPointData>> points = null;
60 private T image;
61 private JFrame frame = null;
62 private ResizeProcessor r = new ResizeProcessor(100,100);
63
64 @Override
65 public synchronized void mouseClicked(MouseEvent e) {
66 if(this.points == null) return;
67 double dist = Double.MAX_VALUE;
68 Circle foundShape = null;
69 InterestPointKeypoint<InterestPointData> foundPoint = null;
70 Point2dImpl clickPoint = new Point2dImpl(e.getPoint().x,e.getPoint().y);
71 for(InterestPointKeypoint<InterestPointData> point : points){
72 Circle ellipse = new Circle(point.location.x, point.location.y, point.scale);
73 if(ellipse.isInside(clickPoint)){
74
75 double pdist = point.scale;
76 if(pdist < dist){
77 foundShape = ellipse;
78 foundPoint = point;
79 dist = pdist;
80 }
81 }
82 }
83 if(foundShape!=null){
84
85 FGaussianConvolve blur = new FGaussianConvolve (foundPoint.scale);
86 InterestPointImageExtractorProperties<S, T> extract = new InterestPointImageExtractorProperties<S,T>(image.process(blur),foundPoint.location);
87 if(frame== null){
88 frame = DisplayUtilities.display(extract.image.process(r));
89 }
90 else{
91 frame.dispose();
92 frame = DisplayUtilities.display(extract.image.process(r));
93 }
94 }
95 }
96
97 @Override
98 public void mousePressed(MouseEvent e) {
99
100
101 }
102
103 @Override
104 public void mouseReleased(MouseEvent e) {
105
106
107 }
108
109 @Override
110 public void mouseEntered(MouseEvent e) {
111
112
113 }
114
115 @Override
116 public void mouseExited(MouseEvent e) {
117
118
119 }
120
121
122
123
124
125 public LocalFeatureList<InterestPointKeypoint<InterestPointData>> getPoints() {
126 return points;
127 }
128
129
130
131
132
133
134 public synchronized void setImage(LocalFeatureList<InterestPointKeypoint<InterestPointData>> kpl,T image) {
135 this.image = image;
136 this.points = kpl;
137 }
138
139
140
141
142 public T getImage() {
143 return image;
144 }
145
146 }