Skip to content

Commit

Permalink
Add Objective-C/Swift wrappers for opencv_contrib modules
Browse files Browse the repository at this point in the history
  • Loading branch information
komakai committed Jul 21, 2020
1 parent af9ee90 commit 4cf7675
Show file tree
Hide file tree
Showing 15 changed files with 282 additions and 163 deletions.
4 changes: 3 additions & 1 deletion modules/calib3d/misc/objc/gen_dict.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"func_arg_fix" : {
"findCirclesGrid" : { "blobDetector" : {"defval" : "cv::SimpleBlobDetector::create()"} }
"Calib3d" : {
"findCirclesGrid" : { "blobDetector" : {"defval" : "cv::SimpleBlobDetector::create()"} }
}
}
}
2 changes: 1 addition & 1 deletion modules/core/misc/objc/common/Float6.mm
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ -(void)set:(NSArray<NSNumber*>*)vals {
}

-(NSArray<NSNumber*>*)get {
return @[[NSNumber numberWithFloat:native[0]], [NSNumber numberWithFloat:native[1]], [NSNumber numberWithFloat:native[2]], [NSNumber numberWithFloat:native[3]]];
return @[[NSNumber numberWithFloat:native[0]], [NSNumber numberWithFloat:native[1]], [NSNumber numberWithFloat:native[2]], [NSNumber numberWithFloat:native[3]], [NSNumber numberWithFloat:native[4]], [NSNumber numberWithFloat:native[5]]];
}

- (BOOL)isEqual:(id)other {
Expand Down
5 changes: 5 additions & 0 deletions modules/core/misc/objc/common/Point3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ CV_EXPORTS @interface Point3d : NSObject
- (instancetype)initWithPoint:(Point2d*)point;
- (instancetype)initWithVals:(NSArray<NSNumber*>*)vals;

#ifdef __cplusplus
+ (instancetype)fromNative:(cv::Point3d&)point;
- (void)update:(cv::Point3d&)point;
#endif

# pragma mark - Methods

/**
Expand Down
10 changes: 10 additions & 0 deletions modules/core/misc/objc/common/Point3d.mm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ - (instancetype)initWithVals:(NSArray<NSNumber*>*)vals {
return self;
}

+ (instancetype)fromNative:(cv::Point3d&)point {
return [[Point3d alloc] initWithX:point.x y:point.y z:point.z];
}

- (void)update:(cv::Point3d&)point {
self.x = point.x;
self.y = point.y;
self.z = point.z;
}

- (void)set:(NSArray<NSNumber*>*)vals {
self.x = (vals != nil && vals.count > 0) ? vals[0].doubleValue : 0.0;
self.y = (vals != nil && vals.count > 1) ? vals[1].doubleValue : 0.0;
Expand Down
4 changes: 4 additions & 0 deletions modules/core/misc/objc/common/Point3f.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ CV_EXPORTS @interface Point3f : NSObject
- (instancetype)initWithPoint:(Point2f*)point;
- (instancetype)initWithVals:(NSArray<NSNumber*>*)vals;

#ifdef __cplusplus
+ (instancetype)fromNative:(cv::Point3f&)point;
- (void)update:(cv::Point3f&)point;
#endif

# pragma mark - Methods

Expand Down
10 changes: 10 additions & 0 deletions modules/core/misc/objc/common/Point3f.mm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ - (instancetype)initWithVals:(NSArray<NSNumber*>*)vals {
return self;
}

+ (instancetype)fromNative:(cv::Point3f&)point {
return [[Point3f alloc] initWithX:point.x y:point.y z:point.z];
}

- (void)update:(cv::Point3f&)point {
self.x = point.x;
self.y = point.y;
self.z = point.z;
}

- (void)set:(NSArray<NSNumber*>*)vals {
self.x = (vals != nil && vals.count > 0) ? vals[0].floatValue : 0.0;
self.y = (vals != nil && vals.count > 1) ? vals[1].floatValue : 0.0;
Expand Down
5 changes: 5 additions & 0 deletions modules/core/misc/objc/common/Point3i.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ CV_EXPORTS @interface Point3i : NSObject
- (instancetype)initWithPoint:(Point2i*)point;
- (instancetype)initWithVals:(NSArray<NSNumber*>*)vals;

#ifdef __cplusplus
+ (instancetype)fromNative:(cv::Point3i&)point;
- (void)update:(cv::Point3i&)point;
#endif

# pragma mark - Methods

/**
Expand Down
10 changes: 10 additions & 0 deletions modules/core/misc/objc/common/Point3i.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ - (instancetype)initWithVals:(NSArray<NSNumber*>*)vals {
return self;
}

+ (instancetype)fromNative:(cv::Point3i&)point {
return [[Point3i alloc] initWithX:point.x y:point.y z:point.z];
}

- (void)update:(cv::Point3i&)point {
self.x = point.x;
self.y = point.y;
self.z = point.z;
}

- (void)set:(NSArray<NSNumber*>*)vals {
self.x = (vals != nil && vals.count > 0) ? vals[0].intValue : 0;
self.y = (vals != nil && vals.count > 1) ? vals[1].intValue : 0;
Expand Down
59 changes: 37 additions & 22 deletions modules/core/misc/objc/gen_dict.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,28 @@
}
},
"func_arg_fix" : {
"randu" : { "low" : {"ctype" : "double"},
"high" : {"ctype" : "double"} },
"randn" : { "mean" : {"ctype" : "double"},
"stddev" : {"ctype" : "double"} },
"inRange" : { "lowerb" : {"ctype" : "Scalar"},
"upperb" : {"ctype" : "Scalar"} },
"boundingRect" : { "points" : {"ctype" : "vector_Point"} },
"hconcat" : { "src" : {"ctype" : "vector_Mat"} },
"vconcat" : { "src" : {"ctype" : "vector_Mat"} },
"checkRange" : {"pos" : {"ctype" : "*"} },
"meanStdDev" : { "mean" : {"ctype" : "vector_double"},
"stddev" : {"ctype" : "vector_double"} },
"mixChannels" : { "dst" : {"attrib" : []} },
"rotate" : { "rotateCode" : {"ctype" : "RotateFlags"} },
"norm" : { "normType" : {"ctype" : "NormTypes"} },
"batchDistance" : { "normType" : {"ctype" : "NormTypes"} },
"normalize" : { "norm_type" : {"ctype" : "NormTypes"} },
"compare" : { "cmpop" : {"ctype" : "CmpTypes"} },
"copyMakeBorder" : { "borderType" : {"ctype" : "BorderTypes"} },
"borderInterpolate" : { "borderType" : {"ctype" : "BorderTypes"} },
"(void)divide:(double)scale src2:(Mat*)src2 dst:(Mat*)dst dtype:(int)dtype" : { "src2" : {"name" : "src"} }
"Core": {
"randu" : { "low" : {"ctype" : "double"},
"high" : {"ctype" : "double"} },
"randn" : { "mean" : {"ctype" : "double"},
"stddev" : {"ctype" : "double"} },
"inRange" : { "lowerb" : {"ctype" : "Scalar"},
"upperb" : {"ctype" : "Scalar"} },
"hconcat" : { "src" : {"ctype" : "vector_Mat"} },
"vconcat" : { "src" : {"ctype" : "vector_Mat"} },
"checkRange" : {"pos" : {"ctype" : "*"} },
"meanStdDev" : { "mean" : {"ctype" : "vector_double"},
"stddev" : {"ctype" : "vector_double"} },
"mixChannels" : { "dst" : {"attrib" : []} },
"rotate" : { "rotateCode" : {"ctype" : "RotateFlags"} },
"norm" : { "normType" : {"ctype" : "NormTypes"} },
"batchDistance" : { "normType" : {"ctype" : "NormTypes"} },
"normalize" : { "norm_type" : {"ctype" : "NormTypes"} },
"compare" : { "cmpop" : {"ctype" : "CmpTypes"} },
"copyMakeBorder" : { "borderType" : {"ctype" : "BorderTypes"} },
"borderInterpolate" : { "borderType" : {"ctype" : "BorderTypes"} },
"(void)divide:(double)scale src2:(Mat*)src2 dst:(Mat*)dst dtype:(int)dtype" : { "src2" : {"name" : "src"} }
}
},
"type_dict" : {
"Algorithm": {
Expand Down Expand Up @@ -227,7 +228,9 @@
"from_cpp": "[Double3 fromNative:%(n)s]"
},
"c_string": {
"objc_type": "NSString*"
"objc_type": "NSString*",
"to_cpp": "%(n)s.UTF8String",
"from_cpp": "[NSString stringWithUTF8String:%(n)s]"
},
"vector_DMatch": {
"objc_type": "DMatch*",
Expand Down Expand Up @@ -355,6 +358,18 @@
"objc_type": "ByteVector*",
"v_type": "ByteVector"
},
"vector_vector_int": {
"objc_type": "IntVector*",
"v_type": "IntVector"
},
"vector_vector_float": {
"objc_type": "FloatVector*",
"v_type": "FloatVector"
},
"vector_vector_double": {
"objc_type": "DoubleVector*",
"v_type": "DoubleVector"
},
"ByteVector": {
"objc_type": "ByteVector*",
"cast_to": "std::vector<char>"
Expand Down
36 changes: 20 additions & 16 deletions modules/dnn/misc/objc/gen_dict.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
{
"func_arg_fix" : {
"(Net*)readNetFromCaffe:(NSString*)prototxt caffeModel:(NSString*)caffeModel" : { "readNetFromCaffe" : {"name" : "readNetFromCaffeFile"} },
"(Net*)readNetFromCaffe:(ByteVector*)bufferProto bufferModel:(ByteVector*)bufferModel" : { "readNetFromCaffe" : {"name" : "readNetFromCaffeBuffer"} },
"(Net*)readNetFromDarknet:(NSString*)cfgFile darknetModel:(NSString*)darknetModel" : { "readNetFromDarknet" : {"name" : "readNetFromDarknetFile"} },
"(Net*)readNetFromDarknet:(ByteVector*)bufferCfg bufferModel:(ByteVector*)bufferModel" : { "readNetFromDarknet" : {"name" : "readNetFromDarknetBuffer"} },
"(Net*)readNetFromONNX:(NSString*)onnxFile" : { "readNetFromONNX" : {"name" : "readNetFromONNXFile"} },
"(Net*)readNetFromONNX:(ByteVector*)buffer" : { "readNetFromONNX" : {"name" : "readNetFromONNXBuffer"} },
"(Net*)readNetFromTensorflow:(NSString*)model config:(NSString*)config" : { "readNetFromTensorflow" : {"name" : "readNetFromTensorflowFile"} },
"(Net*)readNetFromTensorflow:(ByteVector*)bufferModel bufferConfig:(ByteVector*)bufferConfig" : { "readNetFromTensorflow" : {"name" : "readNetFromTensorflowBuffer"} },
"(void)forward:(NSMutableArray<Mat*>*)outputBlobs outputName:(NSString*)outputName" : { "forward" : {"name" : "forwardOutputBlobs"} },
"(void)forward:(NSMutableArray<Mat*>*)outputBlobs outBlobNames:(NSArray<NSString*>*)outBlobNames" : { "forward" : {"name" : "forwardOutputBlobs"} },
"(long)getFLOPS:(IntVector*)netInputShape" : { "getFLOPS" : {"name" : "getFLOPSWithNetInputShape"} },
"(long)getFLOPS:(NSArray<IntVector*>*)netInputShapes" : { "getFLOPS" : {"name" : "getFLOPSWithNetInputShapes"} },
"(long)getFLOPS:(int)layerId netInputShape:(IntVector*)netInputShape" : { "getFLOPS" : {"name" : "getFLOPSWithLayerId"} },
"(long)getFLOPS:(int)layerId netInputShapes:(NSArray<IntVector*>*)netInputShapes" : { "getFLOPS" : {"name" : "getFLOPSWithLayerId"} },
"(void)getLayersShapes:(IntVector*)netInputShape layersIds:(IntVector*)layersIds inLayersShapes:(NSMutableArray<NSMutableArray<IntVector*>*>*)inLayersShapes outLayersShapes:(NSMutableArray<NSMutableArray<IntVector*>*>*)outLayersShapes" : { "getLayersShapes" : {"name" : "getLayersShapesWithNetInputShape"} },
"(void)getLayersShapes:(NSArray<IntVector*>*)netInputShapes layersIds:(IntVector*)layersIds inLayersShapes:(NSMutableArray<NSMutableArray<IntVector*>*>*)inLayersShapes outLayersShapes:(NSMutableArray<NSMutableArray<IntVector*>*>*)outLayersShapes" : { "getLayersShapes" : {"name" : "getLayersShapesWithNetInputShapes"} }
"Dnn": {
"(Net*)readNetFromCaffe:(NSString*)prototxt caffeModel:(NSString*)caffeModel" : { "readNetFromCaffe" : {"name" : "readNetFromCaffeFile"} },
"(Net*)readNetFromCaffe:(ByteVector*)bufferProto bufferModel:(ByteVector*)bufferModel" : { "readNetFromCaffe" : {"name" : "readNetFromCaffeBuffer"} },
"(Net*)readNetFromDarknet:(NSString*)cfgFile darknetModel:(NSString*)darknetModel" : { "readNetFromDarknet" : {"name" : "readNetFromDarknetFile"} },
"(Net*)readNetFromDarknet:(ByteVector*)bufferCfg bufferModel:(ByteVector*)bufferModel" : { "readNetFromDarknet" : {"name" : "readNetFromDarknetBuffer"} },
"(Net*)readNetFromONNX:(NSString*)onnxFile" : { "readNetFromONNX" : {"name" : "readNetFromONNXFile"} },
"(Net*)readNetFromONNX:(ByteVector*)buffer" : { "readNetFromONNX" : {"name" : "readNetFromONNXBuffer"} },
"(Net*)readNetFromTensorflow:(NSString*)model config:(NSString*)config" : { "readNetFromTensorflow" : {"name" : "readNetFromTensorflowFile"} },
"(Net*)readNetFromTensorflow:(ByteVector*)bufferModel bufferConfig:(ByteVector*)bufferConfig" : { "readNetFromTensorflow" : {"name" : "readNetFromTensorflowBuffer"} }
},
"Net": {
"(void)forward:(NSMutableArray<Mat*>*)outputBlobs outputName:(NSString*)outputName" : { "forward" : {"name" : "forwardOutputBlobs"} },
"(void)forward:(NSMutableArray<Mat*>*)outputBlobs outBlobNames:(NSArray<NSString*>*)outBlobNames" : { "forward" : {"name" : "forwardOutputBlobs"} },
"(long)getFLOPS:(IntVector*)netInputShape" : { "getFLOPS" : {"name" : "getFLOPSWithNetInputShape"} },
"(long)getFLOPS:(NSArray<IntVector*>*)netInputShapes" : { "getFLOPS" : {"name" : "getFLOPSWithNetInputShapes"} },
"(long)getFLOPS:(int)layerId netInputShape:(IntVector*)netInputShape" : { "getFLOPS" : {"name" : "getFLOPSWithLayerId"} },
"(long)getFLOPS:(int)layerId netInputShapes:(NSArray<IntVector*>*)netInputShapes" : { "getFLOPS" : {"name" : "getFLOPSWithLayerId"} },
"(void)getLayersShapes:(IntVector*)netInputShape layersIds:(IntVector*)layersIds inLayersShapes:(NSMutableArray<NSMutableArray<IntVector*>*>*)inLayersShapes outLayersShapes:(NSMutableArray<NSMutableArray<IntVector*>*>*)outLayersShapes" : { "getLayersShapes" : {"name" : "getLayersShapesWithNetInputShape"} },
"(void)getLayersShapes:(NSArray<IntVector*>*)netInputShapes layersIds:(IntVector*)layersIds inLayersShapes:(NSMutableArray<NSMutableArray<IntVector*>*>*)inLayersShapes outLayersShapes:(NSMutableArray<NSMutableArray<IntVector*>*>*)outLayersShapes" : { "getLayersShapes" : {"name" : "getLayersShapesWithNetInputShapes"} }
}
},
"type_dict": {
"MatShape": {
Expand Down
23 changes: 15 additions & 8 deletions modules/features2d/misc/objc/gen_dict.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
"AgastFeatureDetector" : { "DetectorType": "AgastDetectorType" }
},
"func_arg_fix" : {
"(void)compute:(NSArray<Mat*>*)images keypoints:(NSMutableArray<NSMutableArray<KeyPoint*>*>*)keypoints descriptors:(NSMutableArray<Mat*>*)descriptors" : { "compute" : {"name" : "compute2"} },
"(void)detect:(NSArray<Mat*>*)images keypoints:(NSMutableArray<NSMutableArray<KeyPoint*>*>*)keypoints masks:(NSArray<Mat*>*)masks" : { "detect" : {"name" : "detect2"} },
"(DescriptorMatcher*)create:(NSString*)descriptorMatcherType" : { "create" : {"name" : "create2"} },
"FlannBasedMatcher": { "indexParams" : {"defval" : "cv::makePtr<cv::flann::KDTreeIndexParams>()"}, "searchParams" : {"defval" : "cv::makePtr<cv::flann::SearchParams>()"} },
"(SimpleBlobDetector*)create" : { "parameters" : {"defval" : "cv::SimpleBlobDetector::Params()"} },
"BFMatcher" : { "normType" : {"ctype" : "NormTypes"} },
"(BFMatcher*)create:(int)normType crossCheck:(BOOL)crossCheck" : { "create" : {"name" : "createBFMatcher"},
"normType" : {"ctype" : "NormTypes"} }
"Feature2D": {
"(void)compute:(NSArray<Mat*>*)images keypoints:(NSMutableArray<NSMutableArray<KeyPoint*>*>*)keypoints descriptors:(NSMutableArray<Mat*>*)descriptors" : { "compute" : {"name" : "compute2"} },
"(void)detect:(NSArray<Mat*>*)images keypoints:(NSMutableArray<NSMutableArray<KeyPoint*>*>*)keypoints masks:(NSArray<Mat*>*)masks" : { "detect" : {"name" : "detect2"} }
},
"DescriptorMatcher": {
"(DescriptorMatcher*)create:(NSString*)descriptorMatcherType" : { "create" : {"name" : "create2"} }
},
"FlannBasedMatcher": {
"FlannBasedMatcher": { "indexParams" : {"defval" : "cv::makePtr<cv::flann::KDTreeIndexParams>()"}, "searchParams" : {"defval" : "cv::makePtr<cv::flann::SearchParams>()"} }
},
"BFMatcher": {
"BFMatcher" : { "normType" : {"ctype" : "NormTypes"} },
"(BFMatcher*)create:(int)normType crossCheck:(BOOL)crossCheck" : { "create" : {"name" : "createBFMatcher"},
"normType" : {"ctype" : "NormTypes"} }
}
}
}
Loading

0 comments on commit 4cf7675

Please sign in to comment.