1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-21 19:33:03 +04:00
Files
opencv/modules/core/misc/objc/common/DMatch.mm
T
Giles Payne 02385472b6 Merge pull request #17165 from komakai:objc-binding
Objc binding

* Initial work on Objective-C wrapper

* Objective-C generator script; update manually generated wrappers

* Add Mat tests

* Core Tests

* Imgproc wrapper generation and tests

* Fixes for Imgcodecs wrapper

* Miscellaneous fixes. Swift build support

* Objective-C wrapper build/install

* Add Swift wrappers for videoio/objdetect/feature2d

* Framework build;iOS support

* Fix toArray functions;Use enum types whenever possible

* Use enum types where possible;prepare test build

* Update test

* Add test runner scripts for iOS and macOS

* Add test scripts and samples

* Build fixes

* Fix build (cmake 3.17.x compatibility)

* Fix warnings

* Fix enum name conflicting handling

* Add support for document generation with Jazzy

* Swift/Native fast accessor functions

* Add Objective-C wrapper for calib3d, dnn, ml, photo and video modules

* Remove IntOut/FloatOut/DoubleOut classes

* Fix iOS default test platform value

* Fix samples

* Revert default framework name to opencv2

* Add converter util functions

* Fix failing test

* Fix whitespace

* Add handling for deprecated methods;fix warnings;define __OPENCV_BUILD

* Suppress cmake warnings

* Reduce severity of "jazzy not found" log message

* Fix incorrect #include of compatibility header in ios.h

* Use explicit returns in subscript/get implementation

* Reduce minimum required cmake version to 3.15 for Objective-C/Swift binding
2020-06-08 18:32:53 +00:00

108 lines
2.5 KiB
Plaintext

//
// DMatch.m
//
// Created by Giles Payne on 2019/12/25.
//
#import "DMatch.h"
#import "CVObjcUtil.h"
@implementation DMatch {
cv::DMatch native;
}
- (int)queryIdx {
return native.queryIdx;
}
- (void)setQueryIdx:(int)queryIdx {
native.queryIdx = queryIdx;
}
- (int)trainIdx {
return native.trainIdx;
}
- (void)setTrainIdx:(int)trainIdx {
native.trainIdx = trainIdx;
}
- (int)imgIdx {
return native.imgIdx;
}
- (void)setImgIdx:(int)imgIdx {
native.imgIdx = imgIdx;
}
- (float)distance {
return native.distance;
}
- (void)setDistance:(float)distance {
native.distance = distance;
}
- (cv::DMatch&)nativeRef {
return native;
}
- (instancetype)init {
return [self initWithQueryIdx:-1 trainIdx:-1 distance:FLT_MAX];
}
- (instancetype)initWithQueryIdx:(int)queryIdx trainIdx:(int)trainIdx distance:(float)distance {
return [self initWithQueryIdx:queryIdx trainIdx:trainIdx imgIdx:-1 distance:distance];
}
- (instancetype)initWithQueryIdx:(int)queryIdx trainIdx:(int)trainIdx imgIdx:(int)imgIdx distance:(float)distance {
self = [super init];
if (self != nil) {
self.queryIdx = queryIdx;
self.trainIdx = trainIdx;
self.imgIdx = imgIdx;
self.distance = distance;
}
return self;
}
+ (instancetype)fromNative:(cv::DMatch&)dMatch {
return [[DMatch alloc] initWithQueryIdx:dMatch.queryIdx trainIdx:dMatch.trainIdx imgIdx:dMatch.imgIdx distance:dMatch.distance];
}
- (BOOL)lessThan:(DMatch*)it {
return self.distance < it.distance;
}
- (DMatch*)clone {
return [[DMatch alloc] initWithQueryIdx:self.queryIdx trainIdx:self.trainIdx imgIdx:self.imgIdx distance:self.distance];
}
- (BOOL)isEqual:(id)other {
if (other == self) {
return YES;
} else if (![other isKindOfClass:[DMatch class]]) {
return NO;
} else {
DMatch* dMatch = (DMatch*)other;
return self.queryIdx == dMatch.queryIdx && self.trainIdx == dMatch.trainIdx && self.imgIdx == dMatch.imgIdx && self.distance == dMatch.distance;
}
}
- (NSUInteger)hash {
int prime = 31;
uint32_t result = 1;
result = prime * result + self.queryIdx;
result = prime * result + self.trainIdx;
result = prime * result + self.imgIdx;
result = prime * result + FLOAT_TO_BITS(self.distance);
return result;
}
- (NSString *)description {
return [NSString stringWithFormat:@"DMatch { queryIdx: %d, trainIdx: %d, imgIdx: %d, distance: %f}", self.queryIdx, self.trainIdx, self.imgIdx, self.distance];
}
@end