File: KeyPoint.mm

package info (click to toggle)
opencv 4.10.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 282,092 kB
  • sloc: cpp: 1,178,079; xml: 682,621; python: 49,092; lisp: 31,150; java: 25,469; ansic: 11,039; javascript: 6,085; sh: 1,214; cs: 601; perl: 494; objc: 210; makefile: 173
file content (96 lines) | stat: -rw-r--r-- 3,251 bytes parent folder | download | duplicates (3)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
//  KeyPoint.m
//
//  Created by Giles Payne on 2019/12/25.
//

#import "KeyPoint.h"
#import "Point2f.h"

@implementation KeyPoint {
    cv::KeyPoint native;
}

- (cv::KeyPoint&)nativeRef {
    native.pt.x = self.pt.x;
    native.pt.y = self.pt.y;
    native.size = self.size;
    native.angle = self.angle;
    native.response = self.response;
    native.octave = self.octave;
    native.class_id = self.classId;
    return native;
}

- (instancetype)init {
    return [self initWithX:0 y:0 size:0];
}

- (instancetype)initWithX:(float)x y:(float)y size:(float)size angle:(float)angle response:(float)response octave:(int)octave classId:(int)classId {
    self = [super init];
    if (self != nil) {
        self.pt = [[Point2f alloc] initWithX:x y:y];
        self.size = size;
        self.angle = angle;
        self.response = response;
        self.octave = octave;
        self.classId = classId;
    }
    return self;
}

- (instancetype)initWithX:(float)x y:(float)y size:(float)size angle:(float)angle response:(float)response octave:(int)octave {
    return [self initWithX:x y:y size:size angle:angle response:response octave:octave classId:-1];
}

- (instancetype)initWithX:(float)x y:(float)y size:(float)size angle:(float)angle response:(float)response {
    return [self initWithX:x y:y size:size angle:angle response:response octave:0];
}

- (instancetype)initWithX:(float)x y:(float)y size:(float)size angle:(float)angle {
    return [self initWithX:x y:y size:size angle:angle response:0];
}

- (instancetype)initWithX:(float)x y:(float)y size:(float)size {
    return [self initWithX:x y:y size:size angle:-1];
}

+ (instancetype)fromNative:(cv::KeyPoint&)keyPoint {
    return [[KeyPoint alloc] initWithX:keyPoint.pt.x y:keyPoint.pt.y size:keyPoint.size angle:keyPoint.angle response:keyPoint.response octave:keyPoint.octave classId:keyPoint.class_id];
}

- (KeyPoint*)clone {
    return [[KeyPoint alloc] initWithX:self.pt.x y:self.pt.y size:self.size angle:self.angle response:self.response octave:self.octave classId:self.classId];
}

- (BOOL)isEqual:(id)other {
    if (other == self) {
        return YES;
    } else if (![other isKindOfClass:[KeyPoint class]]) {
        return NO;
    } else {
        KeyPoint* keyPoint = (KeyPoint*)other;
        return [self.pt isEqual:keyPoint.pt] && self.size == keyPoint.size && self.angle == keyPoint.angle && self.response == keyPoint.response && self.octave == keyPoint.octave && self.classId == keyPoint.classId;
    }
}

#define FLOAT_TO_BITS(x)  ((Cv32suf){ .f = x }).i

- (NSUInteger)hash {
    int prime = 31;
    uint32_t result = 1;
    result = prime * result + FLOAT_TO_BITS(self.pt.x);
    result = prime * result + FLOAT_TO_BITS(self.pt.y);
    result = prime * result + FLOAT_TO_BITS(self.size);
    result = prime * result + FLOAT_TO_BITS(self.angle);
    result = prime * result + FLOAT_TO_BITS(self.response);
    result = prime * result + self.octave;
    result = prime * result + self.classId;
    return result;
}

- (NSString*)description {
    return [NSString stringWithFormat:@"KeyPoint { pt: %@, size: %f, angle: %f, response: %f, octave: %d, classId: %d}", self.pt.description, self.size, self.angle, self.response, self.octave, self.classId];
}

@end