diff --git a/modules/core/misc/objc/common/CvType.mm b/modules/core/misc/objc/common/CvType.mm index 0b8ee34540..4d4688c99b 100644 --- a/modules/core/misc/objc/common/CvType.mm +++ b/modules/core/misc/objc/common/CvType.mm @@ -43,14 +43,19 @@ switch (depth) { case CV_8U: case CV_8S: + case CV_Bool: return 8; case CV_16U: case CV_16S: case CV_16F: + case CV_16BF: return 16; case CV_32S: + case CV_32U: case CV_32F: return 32; + case CV_64U: + case CV_64S: case CV_64F: return 64; default: @@ -71,12 +76,16 @@ switch (depth) { case CV_8U: case CV_16U: + case CV_32U: + case CV_64U: return 'U'; case CV_8S: case CV_16S: case CV_32S: + case CV_64S: return 'S'; case CV_16F: + case CV_16BF: case CV_32F: case CV_64F: return 'F'; diff --git a/modules/core/misc/objc/common/CvTypeExt.swift b/modules/core/misc/objc/common/CvTypeExt.swift index dc0f11c429..a97495bc99 100644 --- a/modules/core/misc/objc/common/CvTypeExt.swift +++ b/modules/core/misc/objc/common/CvTypeExt.swift @@ -6,15 +6,22 @@ import Foundation +//NOTE: Type constants and related functions are ported from modules/core/include/opencv2/core/hal/interface.h + public extension CvType { static let CV_8U: Int32 = 0 static let CV_8S: Int32 = 1 static let CV_16U: Int32 = 2 static let CV_16S: Int32 = 3 static let CV_32S: Int32 = 4 + static let CV_32U: Int32 = 12 + static let CV_64U: Int32 = 10 + static let CV_64S: Int32 = 11 static let CV_32F: Int32 = 5 static let CV_64F: Int32 = 6 static let CV_16F: Int32 = 7 + static let CV_16BF: Int32 = 8 + static let CV_Bool: Int32 = 9 static let CV_8UC1: Int32 = CV_8UC(1) static let CV_8UC2: Int32 = CV_8UC(2) @@ -38,6 +45,20 @@ public extension CvType { static let CV_32SC2: Int32 = CV_32SC(2) static let CV_32SC3: Int32 = CV_32SC(3) static let CV_32SC4: Int32 = CV_32SC(4) + static let CV_32UC1: Int32 = CV_32UC(1) + static let CV_32UC2: Int32 = CV_32UC(2) + static let CV_32UC3: Int32 = CV_32UC(3) + static let CV_32UC4: Int32 = CV_32UC(4) + + static let CV_64SC1: Int32 = CV_64SC(1) + static let CV_64SC2: Int32 = CV_64SC(2) + static let CV_64SC3: Int32 = CV_64SC(3) + static let CV_64SC4: Int32 = CV_64SC(4) + static let CV_64UC1: Int32 = CV_64UC(1) + static let CV_64UC2: Int32 = CV_64UC(2) + static let CV_64UC3: Int32 = CV_64UC(3) + static let CV_64UC4: Int32 = CV_64UC(4) + static let CV_32FC1: Int32 = CV_32FC(1) static let CV_32FC2: Int32 = CV_32FC(2) static let CV_32FC3: Int32 = CV_32FC(3) @@ -47,12 +68,23 @@ public extension CvType { static let CV_64FC2: Int32 = CV_64FC(2) static let CV_64FC3: Int32 = CV_64FC(3) static let CV_64FC4: Int32 = CV_64FC(4) + static let CV_16FC1: Int32 = CV_16FC(1) static let CV_16FC2: Int32 = CV_16FC(2) static let CV_16FC3: Int32 = CV_16FC(3) static let CV_16FC4: Int32 = CV_16FC(4) - static let CV_CN_MAX = 512 + static let CV_16BFC1: Int32 = CV_16BFC(1) + static let CV_16BFC2: Int32 = CV_16BFC(2) + static let CV_16BFC3: Int32 = CV_16BFC(3) + static let CV_16BFC4: Int32 = CV_16BFC(4) + + static let CV_BoolC1: Int32 = CV_BoolC(1) + static let CV_BoolC2: Int32 = CV_BoolC(2) + static let CV_BoolC3: Int32 = CV_BoolC(3) + static let CV_BoolC4: Int32 = CV_BoolC(4) + + static let CV_CN_MAX = 128 static let CV_CN_SHIFT = 5 static let CV_DEPTH_MAX = 1 << CV_CN_SHIFT @@ -76,6 +108,18 @@ public extension CvType { return make(CV_32S, channels: channels) } + static func CV_32UC(_ channels:Int32) -> Int32 { + return make(CV_32U, channels: channels) + } + + static func CV_64SC(_ channels:Int32) -> Int32 { + return make(CV_64S, channels: channels) + } + + static func CV_64UC(_ channels:Int32) -> Int32 { + return make(CV_64U, channels: channels) + } + static func CV_32FC(_ channels:Int32) -> Int32 { return make(CV_32F, channels: channels) } @@ -87,4 +131,12 @@ public extension CvType { static func CV_16FC(_ channels:Int32) -> Int32 { return make(CV_16F, channels: channels) } + + static func CV_16BFC(_ channels:Int32) -> Int32 { + return make(CV_16BF, channels: channels) + } + + static func CV_BoolC(_ channels:Int32) -> Int32 { + return make(CV_Bool, channels: channels) + } } diff --git a/modules/core/misc/objc/common/Mat.mm b/modules/core/misc/objc/common/Mat.mm index 54387a4772..2cdf5756c2 100644 --- a/modules/core/misc/objc/common/Mat.mm +++ b/modules/core/misc/objc/common/Mat.mm @@ -568,10 +568,22 @@ template void putData(uchar* dataDest, int count, T (^readData)(int) putData(dest, count, ^short (int index) { return cv::saturate_cast(data[offset + index].doubleValue);} ); } else if (depth == CV_32S) { putData(dest, count, ^int32_t (int index) { return cv::saturate_cast(data[offset + index].doubleValue);} ); + } else if (depth == CV_32U) { + putData(dest, count, ^uint32_t (int index) { return cv::saturate_cast(data[offset + index].doubleValue);} ); + } else if (depth == CV_64U) { + putData(dest, count, ^uint64_t (int index) { return cv::saturate_cast(data[offset + index].doubleValue);} ); + } else if (depth == CV_64S) { + putData(dest, count, ^int64_t (int index) { return cv::saturate_cast(data[offset + index].doubleValue);} ); } else if (depth == CV_32F) { putData(dest, count, ^float (int index) { return cv::saturate_cast(data[offset + index].doubleValue);} ); } else if (depth == CV_64F) { putData(dest, count, ^double (int index) { return data[offset + index].doubleValue;} ); + } else if (depth == CV_Bool) { + putData(dest, count, ^double (int index) { return data[offset + index].boolValue;} ); + } else if (depth == CV_16F || depth == CV_16BF) { + @throw [NSException exceptionWithName:@"NotImplementedError" + reason:@"Can not put data to Mat with CV_16F or CV_16BF underlying type." + userInfo:nil]; } } diff --git a/modules/core/misc/objc/test/MatTestObjc.m b/modules/core/misc/objc/test/MatTestObjc.m index 26a5aaa06f..c258f7ad15 100644 --- a/modules/core/misc/objc/test/MatTestObjc.m +++ b/modules/core/misc/objc/test/MatTestObjc.m @@ -7,6 +7,8 @@ #import #import +//NOTE: Type constants and related functions are ported from modules/core/include/opencv2/core/hal/interface.h + #define CV_8U 0 #define CV_8S 1 #define CV_16U 2