Mat.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // Mat.h
  3. //
  4. // Created by Giles Payne on 2019/10/06.
  5. //
  6. #pragma once
  7. #ifdef __cplusplus
  8. #import "opencv2/core.hpp"
  9. #else
  10. #define CV_EXPORTS
  11. #endif
  12. #import <Foundation/Foundation.h>
  13. @class Size2i;
  14. @class Scalar;
  15. @class Range;
  16. @class Rect2i;
  17. @class Point2i;
  18. NS_ASSUME_NONNULL_BEGIN
  19. /**
  20. The class Mat represents an n-dimensional dense numerical single-channel or multi-channel array.
  21. ####Swift Example
  22. ```swift
  23. let mat = Mat(rows: 2, cols: 3, type: CvType.CV_8U)
  24. try! mat.put(row: 0, col: 0, data: [2, 3, 4, 4, 5, 6] as [Int8])
  25. print("mat: \(mat.dump())")
  26. ```
  27. ####Objective-C Example
  28. ```objc
  29. Mat* mat = [[Mat alloc] initWithRows:2 cols:3 type: CV_8U];
  30. [m1 put:0 col:0 data:@[@2, @3, @4, @3, @4, @5]];
  31. NSLog(@"mat: %@", [m1 dump]);
  32. ```
  33. */
  34. CV_EXPORTS @interface Mat : NSObject
  35. #ifdef __cplusplus
  36. @property(readonly) cv::Ptr<cv::Mat> nativePtr;
  37. @property(readonly) cv::Mat& nativeRef;
  38. #endif
  39. #pragma mark - Constructors
  40. - (instancetype)init;
  41. #ifdef __cplusplus
  42. - (instancetype)initWithNativeMat:(cv::Ptr<cv::Mat>)nativeMat;
  43. + (instancetype)fromNativePtr:(cv::Ptr<cv::Mat>)nativePtr;
  44. + (instancetype)fromNative:(cv::Mat&)nativeRef;
  45. #endif
  46. /**
  47. Creates a Mat object with the specified number of rows and columns and Mat type
  48. @param rows Number of rows
  49. @param cols Number of columns
  50. @param type Mat type (refer: `CvType`)
  51. */
  52. - (instancetype)initWithRows:(int)rows cols:(int)cols type:(int)type;
  53. - (instancetype)initWithRows:(int)rows cols:(int)cols type:(int)type data:(NSData*)data;
  54. - (instancetype)initWithRows:(int)rows cols:(int)cols type:(int)type data:(NSData*)data step:(long)step;
  55. - (instancetype)initWithSize:(Size2i*)size type:(int)type;
  56. - (instancetype)initWithSizes:(NSArray<NSNumber*>*)sizes type:(int)type;
  57. - (instancetype)initWithRows:(int)rows cols:(int)cols type:(int)type scalar:(Scalar*)scalar;
  58. - (instancetype)initWithSize:(Size2i*)size type:(int)type scalar:(Scalar*)scalar;
  59. - (instancetype)initWithSizes:(NSArray<NSNumber*>*)sizes type:(int)type scalar:(Scalar*)scalar;
  60. - (instancetype)initWithMat:(Mat*)mat rowRange:(Range*)rowRange colRange:(Range*)colRange;
  61. - (instancetype)initWithMat:(Mat*)mat rowRange:(Range*)rowRange;
  62. - (instancetype)initWithMat:(Mat*)mat ranges:(NSArray<Range*>*)ranges;
  63. - (instancetype)initWithMat:(Mat*)mat rect:(Rect2i*)roi;
  64. #pragma mark - Mat operations
  65. - (Mat*)adjustRoiTop:(int)dtop bottom:(int)dbottom left:(int)dleft right:(int)dright NS_SWIFT_NAME(adjustRoi(top:bottom:left:right:));
  66. - (void)assignTo:(Mat*)mat type:(int)type;
  67. - (void)assignTo:(Mat*)mat;
  68. - (BOOL)isSameMat:(Mat*)mat;
  69. - (int)channels;
  70. - (int)checkVector:(int)elemChannels depth:(int)depth requireContinuous:(BOOL) requireContinuous NS_SWIFT_NAME(checkVector(elemChannels:depth:requireContinuous:));
  71. - (int)checkVector:(int)elemChannels depth:(int)depth NS_SWIFT_NAME(checkVector(elemChannels:depth:));
  72. - (int)checkVector:(int)elemChannels NS_SWIFT_NAME(checkVector(elemChannels:));
  73. - (Mat*)clone;
  74. - (Mat*)col:(int)x;
  75. - (Mat*)colRange:(int)start end:(int)end NS_SWIFT_NAME(colRange(start:end:));
  76. - (Mat*)colRange:(Range*)range;
  77. - (int)dims;
  78. - (int)cols;
  79. - (void)convertTo:(Mat*)mat rtype:(int)rtype alpha:(double)alpha beta:(double)beta;
  80. - (void)convertTo:(Mat*)mat rtype:(int)rtype alpha:(double)alpha;
  81. - (void)convertTo:(Mat*)mat rtype:(int)rtype;
  82. - (void)copyTo:(Mat*)mat;
  83. - (void)copyTo:(Mat*)mat mask:(Mat*)mask;
  84. - (void)create:(int)rows cols:(int)cols type:(int)type NS_SWIFT_NAME(create(rows:cols:type:));
  85. - (void)create:(Size2i*)size type:(int)type NS_SWIFT_NAME(create(size:type:));
  86. - (void)createEx:(NSArray<NSNumber*>*)sizes type:(int)type NS_SWIFT_NAME(create(sizes:type:));
  87. - (void)copySize:(Mat*)mat;
  88. - (Mat*)cross:(Mat*)mat;
  89. - (unsigned char*)dataPtr NS_SWIFT_NAME(dataPointer());
  90. - (int)depth;
  91. - (Mat*)diag:(int)diagonal;
  92. - (Mat*)diag;
  93. + (Mat*)diag:(Mat*)diagonal;
  94. - (double)dot:(Mat*)mat;
  95. - (long)elemSize;
  96. - (long)elemSize1;
  97. - (BOOL)empty;
  98. + (Mat*)eye:(int)rows cols:(int)cols type:(int)type NS_SWIFT_NAME(eye(rows:cols:type:));
  99. + (Mat*)eye:(Size2i*)size type:(int)type NS_SWIFT_NAME(eye(size:type:));
  100. - (Mat*)inv:(int)method;
  101. - (Mat*)inv;
  102. - (BOOL)isContinuous;
  103. - (BOOL)isSubmatrix;
  104. - (void)locateROI:(Size2i*)wholeSize ofs:(Point2i*)offset NS_SWIFT_NAME(locateROI(wholeSize:offset:));
  105. - (Mat*)mul:(Mat*)mat scale:(double)scale;
  106. /**
  107. Performs element-wise multiplication
  108. @param mat operand with with which to perform element-wise multiplication
  109. */
  110. - (Mat*)mul:(Mat*)mat;
  111. /**
  112. Performs matrix multiplication
  113. @param mat operand with with which to perform matrix multiplication
  114. @see `Core.gemm(...)`
  115. */
  116. - (Mat*)matMul:(Mat*)mat;
  117. + (Mat*)ones:(int)rows cols:(int)cols type:(int)type NS_SWIFT_NAME(ones(rows:cols:type:));
  118. + (Mat*)ones:(Size2i*)size type:(int)type NS_SWIFT_NAME(ones(size:type:));
  119. + (Mat*)onesEx:(NSArray<NSNumber*>*)sizes type:(int)type NS_SWIFT_NAME(ones(sizes:type:));
  120. - (void)push_back:(Mat*)mat;
  121. - (Mat*)reshape:(int)channels rows:(int)rows NS_SWIFT_NAME(reshape(channels:rows:));
  122. - (Mat*)reshape:(int)channels NS_SWIFT_NAME(reshape(channels:));
  123. - (Mat*)reshape:(int)channels newshape:(NSArray<NSNumber*>*)newshape NS_SWIFT_NAME(reshape(channels:newshape:));
  124. - (Mat*)row:(int)y;
  125. - (Mat*)rowRange:(int)start end:(int)end NS_SWIFT_NAME(rowRange(start:end:));
  126. - (Mat*)rowRange:(Range*)range;
  127. - (int)rows;
  128. - (Mat*)setToScalar:(Scalar*)scalar NS_SWIFT_NAME(setTo(scalar:));
  129. - (Mat*)setToScalar:(Scalar*)scalar mask:(Mat*)mask NS_SWIFT_NAME(setTo(scalar:mask:));
  130. - (Mat*)setToValue:(Mat*)value mask:(Mat*)mask NS_SWIFT_NAME(setTo(value:mask:));
  131. - (Mat*)setToValue:(Mat*)value NS_SWIFT_NAME(setTo(value:));
  132. - (Size2i*)size;
  133. - (int)size:(int)dim;
  134. - (long)step1:(int)dim;
  135. - (long)step1;
  136. - (Mat*)submat:(int)rowStart rowEnd:(int)rowEnd colStart:(int)colStart colEnd:(int)colEnd NS_SWIFT_NAME(submat(rowStart:rowEnd:colStart:colEnd:));
  137. - (Mat*)submat:(Range*)rowRange colRange:(Range*)colRange NS_SWIFT_NAME(submat(rowRange:colRange:));
  138. - (Mat*)submat:(NSArray<Range*>*)ranges NS_SWIFT_NAME(submat(ranges:));
  139. - (Mat*)submatRoi:(Rect2i*)roi NS_SWIFT_NAME(submat(roi:));
  140. - (Mat*)t;
  141. - (long)total;
  142. - (int)type;
  143. + (Mat*)zeros:(int)rows cols:(int)cols type:(int)type;
  144. + (Mat*)zeros:(Size2i*)size type:(int)type;
  145. + (Mat*)zerosEx:(NSArray<NSNumber*>*)sizes type:(int)type NS_SWIFT_NAME(zeros(sizes:type:));
  146. - (NSString*)description;
  147. - (NSString*)dump;
  148. - (int)height;
  149. - (int)width;
  150. #pragma mark - Accessors
  151. - (int)put:(int)row col:(int)col data:(NSArray<NSNumber*>*)data NS_REFINED_FOR_SWIFT;
  152. - (int)put:(NSArray<NSNumber*>*)indices data:(NSArray<NSNumber*>*)data NS_REFINED_FOR_SWIFT;
  153. - (int)get:(int)row col:(int)col data:(NSMutableArray<NSNumber*>*)data NS_REFINED_FOR_SWIFT;
  154. - (int)get:(NSArray<NSNumber*>*)indices data:(NSMutableArray<NSNumber*>*)data NS_REFINED_FOR_SWIFT;
  155. - (NSArray<NSNumber*>*)get:(int)row col:(int)col NS_REFINED_FOR_SWIFT;
  156. - (NSArray<NSNumber*>*)get:(NSArray<NSNumber*>*)indices NS_REFINED_FOR_SWIFT;
  157. - (int)get:(NSArray<NSNumber*>*)indices count:(int)count byteBuffer:(char*)buffer NS_REFINED_FOR_SWIFT;
  158. - (int)get:(NSArray<NSNumber*>*)indices count:(int)count doubleBuffer:(double*)buffer NS_REFINED_FOR_SWIFT;
  159. - (int)get:(NSArray<NSNumber*>*)indices count:(int)count floatBuffer:(float*)buffer NS_REFINED_FOR_SWIFT;
  160. - (int)get:(NSArray<NSNumber*>*)indices count:(int)count intBuffer:(int*)buffer NS_REFINED_FOR_SWIFT;
  161. - (int)get:(NSArray<NSNumber*>*)indices count:(int)count shortBuffer:(short*)buffer NS_REFINED_FOR_SWIFT;
  162. - (int)put:(NSArray<NSNumber*>*)indices count:(int)count byteBuffer:(const char*)buffer NS_REFINED_FOR_SWIFT;
  163. - (int)put:(NSArray<NSNumber*>*)indices count:(int)count doubleBuffer:(const double*)buffer NS_REFINED_FOR_SWIFT;
  164. - (int)put:(NSArray<NSNumber*>*)indices count:(int)count floatBuffer:(const float*)buffer NS_REFINED_FOR_SWIFT;
  165. - (int)put:(NSArray<NSNumber*>*)indices count:(int)count intBuffer:(const int*)buffer NS_REFINED_FOR_SWIFT;
  166. - (int)put:(NSArray<NSNumber*>*)indices count:(int)count shortBuffer:(const short*)buffer NS_REFINED_FOR_SWIFT;
  167. @end
  168. NS_ASSUME_NONNULL_END