Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
a4a9f56c
O
Opencv
项目概览
Greenplum
/
Opencv
10 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a4a9f56c
编写于
4月 24, 2023
作者:
A
Alexander Smorkalov
提交者:
GitHub
4月 24, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #23513 from komakai:fix_unrecognized_selector
Fix "unrecognized selector" issue in Objective-C/Swift bindings
上级
9ab0ff6c
cfa5a270
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
306 addition
and
154 deletion
+306
-154
modules/core/misc/objc/common/Mat.h
modules/core/misc/objc/common/Mat.h
+39
-0
modules/core/misc/objc/common/Mat.mm
modules/core/misc/objc/common/Mat.mm
+55
-0
modules/imgcodecs/misc/objc/ios/Mat+Converters.mm
modules/imgcodecs/misc/objc/ios/Mat+Converters.mm
+0
-44
modules/imgcodecs/misc/objc/ios/MatConverters.h
modules/imgcodecs/misc/objc/ios/MatConverters.h
+32
-0
modules/imgcodecs/misc/objc/ios/MatConverters.mm
modules/imgcodecs/misc/objc/ios/MatConverters.mm
+40
-0
modules/imgcodecs/misc/objc/ios/MatQuickLook.h
modules/imgcodecs/misc/objc/ios/MatQuickLook.h
+3
-3
modules/imgcodecs/misc/objc/ios/MatQuickLook.mm
modules/imgcodecs/misc/objc/ios/MatQuickLook.mm
+32
-33
modules/imgcodecs/misc/objc/macosx/Mat+Converters.mm
modules/imgcodecs/misc/objc/macosx/Mat+Converters.mm
+0
-44
modules/imgcodecs/misc/objc/macosx/MatConverters.h
modules/imgcodecs/misc/objc/macosx/MatConverters.h
+32
-0
modules/imgcodecs/misc/objc/macosx/MatConverters.mm
modules/imgcodecs/misc/objc/macosx/MatConverters.mm
+40
-0
modules/imgcodecs/misc/objc/macosx/MatQuickLook.h
modules/imgcodecs/misc/objc/macosx/MatQuickLook.h
+3
-3
modules/imgcodecs/misc/objc/macosx/MatQuickLook.mm
modules/imgcodecs/misc/objc/macosx/MatQuickLook.mm
+25
-25
modules/objc/generator/gen_objc.py
modules/objc/generator/gen_objc.py
+4
-1
modules/objc/generator/templates/cmakelists.template
modules/objc/generator/templates/cmakelists.template
+1
-1
未找到文件。
modules/core/misc/objc/common/Mat.h
浏览文件 @
a4a9f56c
...
...
@@ -14,6 +14,14 @@
#import <Foundation/Foundation.h>
#ifdef AVAILABLE_IMGCODECS
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_MAC
#import <AppKit/AppKit.h>
#endif
#endif
@class
Size2i
;
@class
Scalar
;
@class
Range
;
...
...
@@ -181,6 +189,37 @@ CV_EXPORTS @interface Mat : NSObject
-
(
int
)
put
:(
NSArray
<
NSNumber
*>*
)
indices
count
:(
int
)
count
intBuffer
:(
const
int
*
)
buffer
NS_REFINED_FOR_SWIFT
;
-
(
int
)
put
:(
NSArray
<
NSNumber
*>*
)
indices
count
:(
int
)
count
shortBuffer
:(
const
short
*
)
buffer
NS_REFINED_FOR_SWIFT
;
#pragma mark - Converters
#ifdef AVAILABLE_IMGCODECS
-
(
CGImageRef
)
toCGImage
CF_RETURNS_RETAINED
;
-
(
instancetype
)
initWithCGImage
:(
CGImageRef
)
image
;
-
(
instancetype
)
initWithCGImage
:(
CGImageRef
)
image
alphaExist
:(
BOOL
)
alphaExist
;
#if TARGET_OS_IPHONE
-
(
UIImage
*
)
toUIImage
;
-
(
instancetype
)
initWithUIImage
:(
UIImage
*
)
image
;
-
(
instancetype
)
initWithUIImage
:(
UIImage
*
)
image
alphaExist
:(
BOOL
)
alphaExist
;
#elif TARGET_OS_MAC
-
(
NSImage
*
)
toNSImage
;
-
(
instancetype
)
initWithNSImage
:(
NSImage
*
)
image
;
-
(
instancetype
)
initWithNSImage
:(
NSImage
*
)
image
alphaExist
:(
BOOL
)
alphaExist
;
#endif
#endif
#pragma mark - QuickLook
#ifdef AVAILABLE_IMGCODECS
-
(
id
)
debugQuickLookObject
;
#endif
@end
...
...
modules/core/misc/objc/common/Mat.mm
浏览文件 @
a4a9f56c
...
...
@@ -13,6 +13,11 @@
#import "CvType.h"
#import "CVObjcUtil.h"
#ifdef AVAILABLE_IMGCODECS
#import "MatConverters.h"
#import "MatQuickLook.h"
#endif
static
int
idx2Offset
(
cv
::
Mat
*
mat
,
std
::
vector
<
int
>&
indices
)
{
int
offset
=
indices
[
0
];
for
(
int
dim
=
1
;
dim
<
mat
->
dims
;
dim
++
)
{
...
...
@@ -932,4 +937,54 @@ template<typename T> int putData(NSArray<NSNumber*>* indices, cv::Mat* mat, int
return
[
self
cols
];
}
#ifdef AVAILABLE_IMGCODECS
-
(
CGImageRef
)
toCGImage
{
return
[
MatConverters
convertMatToCGImageRef
:
self
];
}
-
(
instancetype
)
initWithCGImage
:(
CGImageRef
)
image
{
return
[
MatConverters
convertCGImageRefToMat
:
image
];
}
-
(
instancetype
)
initWithCGImage
:(
CGImageRef
)
image
alphaExist
:(
BOOL
)
alphaExist
{
return
[
MatConverters
convertCGImageRefToMat
:
image
alphaExist
:
alphaExist
];
}
#if TARGET_OS_IPHONE
-
(
UIImage
*
)
toUIImage
{
return
[
MatConverters
converMatToUIImage
:
self
];
}
-
(
instancetype
)
initWithUIImage
:(
UIImage
*
)
image
{
return
[
MatConverters
convertUIImageToMat
:
image
];
}
-
(
instancetype
)
initWithUIImage
:(
UIImage
*
)
image
alphaExist
:(
BOOL
)
alphaExist
{
return
[
MatConverters
convertUIImageToMat
:
image
alphaExist
:
alphaExist
];
}
#elif TARGET_OS_MAC
-
(
NSImage
*
)
toNSImage
{
return
[
MatConverters
converMatToNSImage
:
self
];
}
-
(
instancetype
)
initWithNSImage
:(
NSImage
*
)
image
{
return
[
MatConverters
convertNSImageToMat
:
image
];
}
-
(
instancetype
)
initWithNSImage
:(
NSImage
*
)
image
alphaExist
:(
BOOL
)
alphaExist
{
return
[
MatConverters
convertNSImageToMat
:
image
alphaExist
:
alphaExist
];
}
#endif
-
(
id
)
debugQuickLookObject
{
return
[
MatQuickLook
matDebugQuickLookObject
:
self
];
}
#endif
@end
modules/imgcodecs/misc/objc/ios/Mat+Converters.mm
已删除
100644 → 0
浏览文件 @
9ab0ff6c
//
// Mat+Converters.mm
//
// Created by Giles Payne on 2020/03/03.
//
#import "Mat+Converters.h"
#import <opencv2/imgcodecs/ios.h>
@implementation
Mat
(
Converters
)
-
(
CGImageRef
)
toCGImage
{
return
MatToCGImage
(
self
.
nativeRef
);
}
-
(
instancetype
)
initWithCGImage
:(
CGImageRef
)
image
{
return
[
self
initWithCGImage
:
image
alphaExist
:
NO
];
}
-
(
instancetype
)
initWithCGImage
:(
CGImageRef
)
image
alphaExist
:(
BOOL
)
alphaExist
{
self
=
[
self
init
];
if
(
self
)
{
CGImageToMat
(
image
,
self
.
nativeRef
,
(
bool
)
alphaExist
);
}
return
self
;
}
-
(
UIImage
*
)
toUIImage
{
return
MatToUIImage
(
self
.
nativeRef
);
}
-
(
instancetype
)
initWithUIImage
:(
UIImage
*
)
image
{
return
[
self
initWithUIImage
:
image
alphaExist
:
NO
];
}
-
(
instancetype
)
initWithUIImage
:(
UIImage
*
)
image
alphaExist
:(
BOOL
)
alphaExist
{
self
=
[
self
init
];
if
(
self
)
{
UIImageToMat
(
image
,
self
.
nativeRef
,
(
bool
)
alphaExist
);
}
return
self
;
}
@end
modules/imgcodecs/misc/objc/ios/Mat
+
Converters.h
→
modules/imgcodecs/misc/objc/ios/MatConverters.h
浏览文件 @
a4a9f56c
//
// Mat
+
Converters.h
// MatConverters.h
//
// Created by Giles Payne on 2020/03/03.
//
...
...
@@ -18,14 +18,14 @@
NS_ASSUME_NONNULL_BEGIN
CV_EXPORTS
@interface
Mat
(
Converters
)
CV_EXPORTS
@interface
Mat
Converters
:
NSObject
-
(
CGImageRef
)
toCGImage
CF_RETURNS_RETAINED
;
-
(
instancetype
)
initWithCGImage
:(
CGImageRef
)
image
;
-
(
instancetype
)
initWithCGImage
:(
CGImageRef
)
image
alphaExist
:(
BOOL
)
alphaExist
;
-
(
UIImage
*
)
toUIImage
;
-
(
instancetype
)
initWithUIImage
:(
UIImage
*
)
image
;
-
(
instancetype
)
initWithUIImage
:(
UIImage
*
)
image
alphaExist
:(
BOOL
)
alphaExist
;
+
(
CGImageRef
)
convertMatToCGImageRef
:(
Mat
*
)
mat
CF_RETURNS_RETAINED
;
+
(
Mat
*
)
convertCGImageRefToMat
:(
CGImageRef
)
image
;
+
(
Mat
*
)
convertCGImageRefToMat
:(
CGImageRef
)
image
alphaExist
:(
BOOL
)
alphaExist
;
+
(
UIImage
*
)
converMatToUIImage
:(
Mat
*
)
mat
;
+
(
Mat
*
)
convertUIImageToMat
:(
UIImage
*
)
image
;
+
(
Mat
*
)
convertUIImageToMat
:(
UIImage
*
)
image
alphaExist
:(
BOOL
)
alphaExist
;
@end
...
...
modules/imgcodecs/misc/objc/ios/MatConverters.mm
0 → 100644
浏览文件 @
a4a9f56c
//
// MatConverters.mm
//
// Created by Giles Payne on 2020/03/03.
//
#import "MatConverters.h"
#import <opencv2/imgcodecs/ios.h>
@implementation
MatConverters
+
(
CGImageRef
)
convertMatToCGImageRef
:(
Mat
*
)
mat
{
return
MatToCGImage
(
mat
.
nativeRef
);
}
+
(
Mat
*
)
convertCGImageRefToMat
:(
CGImageRef
)
image
{
return
[
MatConverters
convertCGImageRefToMat
:
image
alphaExist
:
NO
];
}
+
(
Mat
*
)
convertCGImageRefToMat
:(
CGImageRef
)
image
alphaExist
:(
BOOL
)
alphaExist
{
Mat
*
mat
=
[
Mat
new
];
CGImageToMat
(
image
,
mat
.
nativeRef
,
(
bool
)
alphaExist
);
return
mat
;
}
+
(
UIImage
*
)
converMatToUIImage
:(
Mat
*
)
mat
{
return
MatToUIImage
(
mat
.
nativeRef
);
}
+
(
Mat
*
)
convertUIImageToMat
:(
UIImage
*
)
image
{
return
[
MatConverters
convertUIImageToMat
:
image
alphaExist
:
NO
];
}
+
(
Mat
*
)
convertUIImageToMat
:(
UIImage
*
)
image
alphaExist
:(
BOOL
)
alphaExist
{
Mat
*
mat
=
[
Mat
new
];
UIImageToMat
(
image
,
mat
.
nativeRef
,
(
bool
)
alphaExist
);
return
mat
;
}
@end
modules/imgcodecs/misc/objc/ios/Mat
+
QuickLook.h
→
modules/imgcodecs/misc/objc/ios/MatQuickLook.h
浏览文件 @
a4a9f56c
//
// Mat
+
QuickLook.h
// MatQuickLook.h
//
// Created by Giles Payne on 2021/07/18.
//
...
...
@@ -18,9 +18,9 @@
NS_ASSUME_NONNULL_BEGIN
CV_EXPORTS
@interface
Mat
(
QuickLook
)
CV_EXPORTS
@interface
Mat
QuickLook
:
NSObject
-
(
id
)
debugQuickLookObjec
t
;
+
(
id
)
matDebugQuickLookObject
:(
Mat
*
)
ma
t
;
@end
...
...
modules/imgcodecs/misc/objc/ios/Mat
+
QuickLook.mm
→
modules/imgcodecs/misc/objc/ios/MatQuickLook.mm
浏览文件 @
a4a9f56c
//
// Mat
+
QuickLook.mm
// MatQuickLook.mm
//
// Created by Giles Payne on 2021/07/18.
//
#import "Mat+QuickLook.h"
#import "Mat+Converters.h"
#import "MatQuickLook.h"
#import "Rect2i.h"
#import "Core.h"
#import "Imgproc.h"
...
...
@@ -39,9 +38,9 @@ static UIFont* getSystemFont() {
typedef
UIFont
*
(
*
FontGetter
)();
@implementation
Mat
(
QuickLook
)
@implementation
Mat
QuickLook
-
(
NSString
*
)
makeLabel
:(
BOOL
)
isIntType
val
:(
NSNumber
*
)
num
{
+
(
NSString
*
)
makeLabel
:(
BOOL
)
isIntType
val
:(
NSNumber
*
)
num
{
if
(
isIntType
)
{
return
[
NSString
stringWithFormat
:
@"%d"
,
num
.
intValue
];
}
else
{
...
...
@@ -56,31 +55,31 @@ typedef UIFont* (*FontGetter)();
}
}
-
(
void
)
relativeLine
:(
UIBezierPath
*
)
path
relX
:(
CGFloat
)
x
relY
:(
CGFloat
)
y
{
+
(
void
)
relativeLine
:(
UIBezierPath
*
)
path
relX
:(
CGFloat
)
x
relY
:(
CGFloat
)
y
{
CGPoint
curr
=
path
.
currentPoint
;
[
path
addLineToPoint
:
CGPointMake
(
curr
.
x
+
x
,
curr
.
y
+
y
)];
}
-
(
id
)
debugQuickLookObjec
t
{
if
([
self
dims
]
==
2
&&
[
self
rows
]
<=
10
&&
[
self
cols
]
<=
10
&&
[
self
channels
]
==
1
)
{
+
(
id
)
matDebugQuickLookObject
:(
Mat
*
)
ma
t
{
if
([
mat
dims
]
==
2
&&
[
mat
rows
]
<=
10
&&
[
mat
cols
]
<=
10
&&
[
mat
channels
]
==
1
)
{
FontGetter
fontGetters
[]
=
{
getCMU
,
getBodoni72
,
getAnySerif
,
getSystemFont
};
UIFont
*
font
=
nil
;
for
(
int
fontGetterIndex
=
0
;
font
==
nil
&&
fontGetterIndex
<
(
sizeof
(
fontGetters
))
/
(
sizeof
(
fontGetters
[
0
]));
fontGetterIndex
++
)
{
font
=
fontGetters
[
fontGetterIndex
]();
}
int
elements
=
[
self
rows
]
*
[
self
cols
];
int
elements
=
[
mat
rows
]
*
[
mat
cols
];
NSDictionary
<
NSAttributedStringKey
,
id
>*
textFontAttributes
=
@{
NSFontAttributeName
:
font
,
NSForegroundColorAttributeName
:
UIColor
.
blackColor
};
NSMutableArray
<
NSNumber
*>*
rawData
=
[
NSMutableArray
new
];
for
(
int
dataIndex
=
0
;
dataIndex
<
elements
;
dataIndex
++
)
{
[
rawData
addObject
:[
NSNumber
numberWithDouble
:
0
]];
}
[
self
get
:
0
col
:
0
data
:
rawData
];
BOOL
isIntType
=
[
self
depth
]
<=
CV_32S
;
[
mat
get
:
0
col
:
0
data
:
rawData
];
BOOL
isIntType
=
[
mat
depth
]
<=
CV_32S
;
NSMutableArray
<
NSString
*>*
labels
=
[
NSMutableArray
new
];
NSMutableDictionary
<
NSString
*
,
NSValue
*>*
boundingRects
=
[
NSMutableDictionary
dictionaryWithCapacity
:
elements
];
int
maxWidth
=
0
,
maxHeight
=
0
;
for
(
NSNumber
*
number
in
rawData
)
{
NSString
*
label
=
[
self
makeLabel
:
isIntType
val
:
number
];
NSString
*
label
=
[
MatQuickLook
makeLabel
:
isIntType
val
:
number
];
[
labels
addObject
:
label
];
CGRect
boundingRect
=
[
label
boundingRectWithSize
:
CGSizeMake
(
CGFLOAT_MAX
,
CGFLOAT_MAX
)
options
:
NSStringDrawingUsesLineFragmentOrigin
attributes
:
textFontAttributes
context
:
nil
];
if
(
boundingRect
.
size
.
width
>
maxWidth
)
{
...
...
@@ -97,18 +96,18 @@ typedef UIFont* (*FontGetter)();
int
borderGap
=
8
;
int
lineThickness
=
3
;
int
lipWidth
=
6
;
int
imageWidth
=
2
*
(
borderGap
+
lipWidth
)
+
maxWidth
*
[
self
cols
]
+
colGap
*
([
self
cols
]
-
1
);
int
imageHeight
=
2
*
(
borderGap
+
lipWidth
)
+
maxHeight
*
[
self
rows
]
+
rowGap
*
([
self
rows
]
-
1
);
int
imageWidth
=
2
*
(
borderGap
+
lipWidth
)
+
maxWidth
*
[
mat
cols
]
+
colGap
*
([
mat
cols
]
-
1
);
int
imageHeight
=
2
*
(
borderGap
+
lipWidth
)
+
maxHeight
*
[
mat
rows
]
+
rowGap
*
([
mat
rows
]
-
1
);
UIBezierPath
*
leftBracket
=
[
UIBezierPath
new
];
[
leftBracket
moveToPoint
:
CGPointMake
(
borderGap
,
borderGap
)];
[
self
relativeLine
:
leftBracket
relX
:
0
relY
:
imageHeight
-
2
*
borderGap
];
[
self
relativeLine
:
leftBracket
relX
:
lineThickness
+
lipWidth
relY
:
0
];
[
self
relativeLine
:
leftBracket
relX
:
0
relY
:-
lineThickness
];
[
self
relativeLine
:
leftBracket
relX
:
-
lipWidth
relY
:
0
];
[
self
relativeLine
:
leftBracket
relX
:
0
relY
:-
(
imageHeight
-
2
*
(
borderGap
+
lineThickness
))];
[
self
relativeLine
:
leftBracket
relX
:
lipWidth
relY
:
0
];
[
self
relativeLine
:
leftBracket
relX
:
0
relY
:-
lineThickness
];
[
MatQuickLook
relativeLine
:
leftBracket
relX
:
0
relY
:
imageHeight
-
2
*
borderGap
];
[
MatQuickLook
relativeLine
:
leftBracket
relX
:
lineThickness
+
lipWidth
relY
:
0
];
[
MatQuickLook
relativeLine
:
leftBracket
relX
:
0
relY
:-
lineThickness
];
[
MatQuickLook
relativeLine
:
leftBracket
relX
:
-
lipWidth
relY
:
0
];
[
MatQuickLook
relativeLine
:
leftBracket
relX
:
0
relY
:-
(
imageHeight
-
2
*
(
borderGap
+
lineThickness
))];
[
MatQuickLook
relativeLine
:
leftBracket
relX
:
lipWidth
relY
:
0
];
[
MatQuickLook
relativeLine
:
leftBracket
relX
:
0
relY
:-
lineThickness
];
[
leftBracket
closePath
];
CGAffineTransform
reflect
=
CGAffineTransformConcat
(
CGAffineTransformMakeTranslation
(
-
imageWidth
,
0
),
CGAffineTransformMakeScale
(
-
1
,
1
));
UIBezierPath
*
rightBracket
=
[
leftBracket
copy
];
...
...
@@ -124,8 +123,8 @@ typedef UIFont* (*FontGetter)();
[
labels
enumerateObjectsUsingBlock
:
^
(
id
label
,
NSUInteger
index
,
BOOL
*
stop
)
{
CGRect
boundingRect
=
boundingRects
[
label
].
CGRectValue
;
int
row
=
(
int
)
index
/
[
self
cols
];
int
col
=
(
int
)
index
%
[
self
cols
];
int
row
=
(
int
)
index
/
[
mat
cols
];
int
col
=
(
int
)
index
%
[
mat
cols
];
int
x
=
borderGap
+
lipWidth
+
col
*
(
maxWidth
+
colGap
)
+
(
maxWidth
-
boundingRect
.
size
.
width
)
/
2
;
int
y
=
borderGap
+
lipWidth
+
row
*
(
maxHeight
+
rowGap
)
+
(
maxHeight
-
boundingRect
.
size
.
height
)
/
2
;
CGRect
textRect
=
CGRectMake
(
x
,
y
,
boundingRect
.
size
.
width
,
boundingRect
.
size
.
height
);
...
...
@@ -134,26 +133,26 @@ typedef UIFont* (*FontGetter)();
UIImage
*
image
=
UIGraphicsGetImageFromCurrentImageContext
();
UIGraphicsEndImageContext
();
return
image
;
}
else
if
(([
self
dims
]
==
2
)
&&
([
self
type
]
==
CV_8U
||
[
self
type
]
==
CV_8UC3
||
[
self
type
]
==
CV_8UC4
))
{
return
[
self
toUIImage
];
}
else
if
([
self
dims
]
==
2
&&
[
self
channels
]
==
1
)
{
}
else
if
(([
mat
dims
]
==
2
)
&&
([
mat
type
]
==
CV_8U
||
[
mat
type
]
==
CV_8UC3
||
[
mat
type
]
==
CV_8UC4
))
{
return
[
mat
toUIImage
];
}
else
if
([
mat
dims
]
==
2
&&
[
mat
channels
]
==
1
)
{
Mat
*
normalized
=
[
Mat
new
];
[
Core
normalize
:
self
dst
:
normalized
alpha
:
0
beta
:
255
norm_type
:
NORM_MINMAX
dtype
:
CV_8U
];
Mat
*
normalizedKey
=
[[
Mat
alloc
]
initWithRows
:[
self
rows
]
+
10
cols
:[
self
cols
]
type
:
CV_8U
];
[
Core
normalize
:
mat
dst
:
normalized
alpha
:
0
beta
:
255
norm_type
:
NORM_MINMAX
dtype
:
CV_8U
];
Mat
*
normalizedKey
=
[[
Mat
alloc
]
initWithRows
:[
mat
rows
]
+
10
cols
:[
mat
cols
]
type
:
CV_8U
];
std
::
vector
<
char
>
key
;
for
(
int
index
=
0
;
index
<
[
self
cols
];
index
++
)
{
key
.
push_back
((
char
)(
index
*
256
/
[
self
cols
]));
for
(
int
index
=
0
;
index
<
[
mat
cols
];
index
++
)
{
key
.
push_back
((
char
)(
index
*
256
/
[
mat
cols
]));
}
for
(
int
index
=
0
;
index
<
10
;
index
++
)
{
[
normalizedKey
put
:@[[
NSNumber
numberWithInt
:
index
],
[
NSNumber
numberWithInt
:
0
]]
count
:[
self
cols
]
byteBuffer
:
key
.
data
()];
[
normalizedKey
put
:@[[
NSNumber
numberWithInt
:
index
],
[
NSNumber
numberWithInt
:
0
]]
count
:[
mat
cols
]
byteBuffer
:
key
.
data
()];
}
[
normalized
copyTo
:[
normalizedKey
submatRoi
:[[
Rect2i
alloc
]
initWithX
:
0
y
:
10
width
:[
self
cols
]
height
:[
self
rows
]]]];
[
normalized
copyTo
:[
normalizedKey
submatRoi
:[[
Rect2i
alloc
]
initWithX
:
0
y
:
10
width
:[
mat
cols
]
height
:[
mat
rows
]]]];
Mat
*
colorMap
=
[
Mat
new
];
[
Imgproc
applyColorMap
:
normalizedKey
dst
:
colorMap
colormap
:
COLORMAP_JET
];
[
Imgproc
cvtColor
:
colorMap
dst
:
colorMap
code
:
COLOR_BGR2RGB
];
return
[
colorMap
toUIImage
];
}
return
[
self
description
];
return
[
mat
description
];
}
@end
modules/imgcodecs/misc/objc/macosx/Mat+Converters.mm
已删除
100644 → 0
浏览文件 @
9ab0ff6c
//
// Mat+Converters.mm
//
// Created by Masaya Tsuruta on 2020/10/08.
//
#import "Mat+Converters.h"
#import <opencv2/imgcodecs/macosx.h>
@implementation
Mat
(
Converters
)
-
(
CGImageRef
)
toCGImage
{
return
MatToCGImage
(
self
.
nativeRef
);
}
-
(
instancetype
)
initWithCGImage
:(
CGImageRef
)
image
{
return
[
self
initWithCGImage
:
image
alphaExist
:
NO
];
}
-
(
instancetype
)
initWithCGImage
:(
CGImageRef
)
image
alphaExist
:(
BOOL
)
alphaExist
{
self
=
[
self
init
];
if
(
self
)
{
CGImageToMat
(
image
,
self
.
nativeRef
,
(
bool
)
alphaExist
);
}
return
self
;
}
-
(
NSImage
*
)
toNSImage
{
return
MatToNSImage
(
self
.
nativeRef
);
}
-
(
instancetype
)
initWithNSImage
:(
NSImage
*
)
image
{
return
[
self
initWithNSImage
:
image
alphaExist
:
NO
];
}
-
(
instancetype
)
initWithNSImage
:(
NSImage
*
)
image
alphaExist
:(
BOOL
)
alphaExist
{
self
=
[
self
init
];
if
(
self
)
{
NSImageToMat
(
image
,
self
.
nativeRef
,
(
bool
)
alphaExist
);
}
return
self
;
}
@end
modules/imgcodecs/misc/objc/macosx/Mat
+
Converters.h
→
modules/imgcodecs/misc/objc/macosx/MatConverters.h
浏览文件 @
a4a9f56c
...
...
@@ -18,14 +18,14 @@
NS_ASSUME_NONNULL_BEGIN
CV_EXPORTS
@interface
Mat
(
Converters
)
-
(
CGImageRef
)
toCGImage
CF_RETURNS_RETAINED
;
-
(
instancetype
)
initWithCGImage
:(
CGImageRef
)
image
;
-
(
instancetype
)
initWithCGImage
:(
CGImageRef
)
image
alphaExist
:(
BOOL
)
alphaExist
;
-
(
NSImage
*
)
toNSImage
;
-
(
instancetype
)
initWithNSImage
:(
NSImage
*
)
image
;
-
(
instancetype
)
initWithNSImage
:(
NSImage
*
)
image
alphaExist
:(
BOOL
)
alphaExist
;
CV_EXPORTS
@interface
Mat
Converters
:
NSObject
+
(
CGImageRef
)
convertMatToCGImageRef
:(
Mat
*
)
mat
CF_RETURNS_RETAINED
;
+
(
Mat
*
)
convertCGImageRefToMat
:(
CGImageRef
)
image
;
+
(
Mat
*
)
convertCGImageRefToMat
:(
CGImageRef
)
image
alphaExist
:(
BOOL
)
alphaExist
;
+
(
NSImage
*
)
converMatToNSImage
:(
Mat
*
)
mat
;
+
(
Mat
*
)
convertNSImageToMat
:(
NSImage
*
)
image
;
+
(
Mat
*
)
convertNSImageToMat
:(
NSImage
*
)
image
alphaExist
:(
BOOL
)
alphaExist
;
@end
...
...
modules/imgcodecs/misc/objc/macosx/MatConverters.mm
0 → 100644
浏览文件 @
a4a9f56c
//
// MatConverters.mm
//
// Created by Masaya Tsuruta on 2020/10/08.
//
#import "MatConverters.h"
#import <opencv2/imgcodecs/macosx.h>
@implementation
MatConverters
+
(
CGImageRef
)
convertMatToCGImageRef
:(
Mat
*
)
mat
{
return
MatToCGImage
(
mat
.
nativeRef
);
}
+
(
Mat
*
)
convertCGImageRefToMat
:(
CGImageRef
)
image
{
return
[
MatConverters
convertCGImageRefToMat
:
image
alphaExist
:
NO
];
}
+
(
Mat
*
)
convertCGImageRefToMat
:(
CGImageRef
)
image
alphaExist
:(
BOOL
)
alphaExist
{
Mat
*
mat
=
[
Mat
new
];
CGImageToMat
(
image
,
mat
.
nativeRef
,
(
bool
)
alphaExist
);
return
mat
;
}
+
(
NSImage
*
)
converMatToNSImage
:(
Mat
*
)
mat
{
return
MatToNSImage
(
mat
.
nativeRef
);
}
+
(
Mat
*
)
convertNSImageToMat
:(
NSImage
*
)
image
{
return
[
MatConverters
convertNSImageToMat
:
image
alphaExist
:
NO
];
}
+
(
Mat
*
)
convertNSImageToMat
:(
NSImage
*
)
image
alphaExist
:(
BOOL
)
alphaExist
{
Mat
*
mat
=
[
Mat
new
];
NSImageToMat
(
image
,
mat
.
nativeRef
,
(
bool
)
alphaExist
);
return
mat
;
}
@end
modules/imgcodecs/misc/objc/macosx/Mat
+
QuickLook.h
→
modules/imgcodecs/misc/objc/macosx/MatQuickLook.h
浏览文件 @
a4a9f56c
//
// Mat
+
QuickLook.h
// MatQuickLook.h
//
// Created by Giles Payne on 2021/07/18.
//
...
...
@@ -18,9 +18,9 @@
NS_ASSUME_NONNULL_BEGIN
CV_EXPORTS
@interface
Mat
(
QuickLook
)
CV_EXPORTS
@interface
Mat
QuickLook
:
NSObject
-
(
id
)
debugQuickLookObjec
t
;
+
(
id
)
matDebugQuickLookObject
:(
Mat
*
)
ma
t
;
@end
...
...
modules/imgcodecs/misc/objc/macosx/Mat
+
QuickLook.mm
→
modules/imgcodecs/misc/objc/macosx/MatQuickLook.mm
浏览文件 @
a4a9f56c
//
// Mat
+
QuickLook.mm
// MatQuickLook.mm
//
// Created by Giles Payne on 2021/07/18.
//
#import "Mat
+
QuickLook.h"
#import "Mat
+
Converters.h"
#import "MatQuickLook.h"
#import "MatConverters.h"
#import "Rect2i.h"
#import "Core.h"
#import "Imgproc.h"
...
...
@@ -39,9 +39,9 @@ static NSFont* getSystemFont() {
typedef
NSFont
*
(
*
FontGetter
)();
@implementation
Mat
(
QuickLook
)
@implementation
Mat
QuickLook
-
(
NSString
*
)
makeLabel
:(
BOOL
)
isIntType
val
:(
NSNumber
*
)
num
{
+
(
NSString
*
)
makeLabel
:(
BOOL
)
isIntType
val
:(
NSNumber
*
)
num
{
if
(
isIntType
)
{
return
[
NSString
stringWithFormat
:
@"%d"
,
num
.
intValue
];
}
else
{
...
...
@@ -56,27 +56,27 @@ typedef NSFont* (*FontGetter)();
}
}
-
(
id
)
debugQuickLookObjec
t
{
+
(
id
)
matDebugQuickLookObject
:(
Mat
*
)
ma
t
{
// for smallish Mat objects display as a matrix
if
([
self
dims
]
==
2
&&
[
self
rows
]
<=
10
&&
[
self
cols
]
<=
10
&&
[
self
channels
]
==
1
)
{
if
([
mat
dims
]
==
2
&&
[
mat
rows
]
<=
10
&&
[
mat
cols
]
<=
10
&&
[
mat
channels
]
==
1
)
{
FontGetter
fontGetters
[]
=
{
getCMU
,
getBodoni72
,
getAnySerif
,
getSystemFont
};
NSFont
*
font
=
nil
;
for
(
int
fontGetterIndex
=
0
;
font
==
nil
&&
fontGetterIndex
<
(
sizeof
(
fontGetters
))
/
(
sizeof
(
fontGetters
[
0
]));
fontGetterIndex
++
)
{
font
=
fontGetters
[
fontGetterIndex
]();
}
int
elements
=
[
self
rows
]
*
[
self
cols
];
int
elements
=
[
mat
rows
]
*
[
mat
cols
];
NSDictionary
<
NSAttributedStringKey
,
id
>*
textFontAttributes
=
@{
NSFontAttributeName
:
font
,
NSForegroundColorAttributeName
:
NSColor
.
blackColor
};
NSMutableArray
<
NSNumber
*>*
rawData
=
[
NSMutableArray
new
];
for
(
int
dataIndex
=
0
;
dataIndex
<
elements
;
dataIndex
++
)
{
[
rawData
addObject
:[
NSNumber
numberWithDouble
:
0
]];
}
[
self
get
:
0
col
:
0
data
:
rawData
];
BOOL
isIntType
=
[
self
depth
]
<=
CV_32S
;
[
mat
get
:
0
col
:
0
data
:
rawData
];
BOOL
isIntType
=
[
mat
depth
]
<=
CV_32S
;
NSMutableArray
<
NSString
*>*
labels
=
[
NSMutableArray
new
];
NSMutableDictionary
<
NSString
*
,
NSValue
*>*
boundingRects
=
[
NSMutableDictionary
dictionaryWithCapacity
:
elements
];
int
maxWidth
=
0
,
maxHeight
=
0
;
for
(
NSNumber
*
number
in
rawData
)
{
NSString
*
label
=
[
self
makeLabel
:
isIntType
val
:
number
];
NSString
*
label
=
[
MatQuickLook
makeLabel
:
isIntType
val
:
number
];
[
labels
addObject
:
label
];
NSRect
boundingRect
=
[
label
boundingRectWithSize
:
NSMakeSize
(
CGFLOAT_MAX
,
CGFLOAT_MAX
)
options
:
NSStringDrawingUsesLineFragmentOrigin
attributes
:
textFontAttributes
];
if
(
boundingRect
.
size
.
width
>
maxWidth
)
{
...
...
@@ -93,8 +93,8 @@ typedef NSFont* (*FontGetter)();
int
borderGap
=
9
;
int
lineThickness
=
4
;
int
lipWidth
=
8
;
int
imageWidth
=
2
*
(
borderGap
+
lipWidth
)
+
maxWidth
*
[
self
cols
]
+
colGap
*
([
self
cols
]
-
1
);
int
imageHeight
=
2
*
(
borderGap
+
lipWidth
)
+
maxHeight
*
[
self
rows
]
+
rowGap
*
([
self
rows
]
-
1
);
int
imageWidth
=
2
*
(
borderGap
+
lipWidth
)
+
maxWidth
*
[
mat
cols
]
+
colGap
*
([
mat
cols
]
-
1
);
int
imageHeight
=
2
*
(
borderGap
+
lipWidth
)
+
maxHeight
*
[
mat
rows
]
+
rowGap
*
([
mat
rows
]
-
1
);
NSImage
*
image
=
[[
NSImage
alloc
]
initWithSize
:
NSMakeSize
(
imageWidth
,
imageHeight
)];
NSBezierPath
*
leftBracket
=
[
NSBezierPath
new
];
[
leftBracket
moveToPoint
:
NSMakePoint
(
borderGap
,
borderGap
)];
...
...
@@ -121,8 +121,8 @@ typedef NSFont* (*FontGetter)();
[
labels
enumerateObjectsUsingBlock
:
^
(
id
label
,
NSUInteger
index
,
BOOL
*
stop
)
{
NSRect
boundingRect
=
boundingRects
[
label
].
rectValue
;
int
row
=
[
self
rows
]
-
1
-
((
int
)
index
/
[
self
cols
]);
int
col
=
(
int
)
index
%
[
self
cols
];
int
row
=
[
mat
rows
]
-
1
-
((
int
)
index
/
[
mat
cols
]);
int
col
=
(
int
)
index
%
[
mat
cols
];
int
x
=
borderGap
+
lipWidth
+
col
*
(
maxWidth
+
colGap
)
+
(
maxWidth
-
boundingRect
.
size
.
width
)
/
2
;
int
y
=
borderGap
+
lipWidth
+
row
*
(
maxHeight
+
rowGap
)
+
(
maxHeight
-
boundingRect
.
size
.
height
)
/
2
;
NSRect
textRect
=
NSMakeRect
(
x
,
y
,
boundingRect
.
size
.
width
,
boundingRect
.
size
.
height
);
...
...
@@ -130,29 +130,29 @@ typedef NSFont* (*FontGetter)();
}];
[
image
unlockFocus
];
return
image
;
}
else
if
(([
self
dims
]
==
2
)
&&
([
self
type
]
==
CV_8U
||
[
self
type
]
==
CV_8UC3
||
[
self
type
]
==
CV_8UC4
))
{
}
else
if
(([
mat
dims
]
==
2
)
&&
([
mat
type
]
==
CV_8U
||
[
mat
type
]
==
CV_8UC3
||
[
mat
type
]
==
CV_8UC4
))
{
// convert to NSImage if the Mats has 2 dimensions and a type and number of channels consistent with it being a image
return
[
self
toNSImage
];
}
else
if
([
self
dims
]
==
2
&&
[
self
channels
]
==
1
)
{
return
[
mat
toNSImage
];
}
else
if
([
mat
dims
]
==
2
&&
[
mat
channels
]
==
1
)
{
// for other Mats with 2 dimensions and one channel - generate heat map
Mat
*
normalized
=
[
Mat
new
];
[
Core
normalize
:
self
dst
:
normalized
alpha
:
0
beta
:
255
norm_type
:
NORM_MINMAX
dtype
:
CV_8U
];
Mat
*
normalizedKey
=
[[
Mat
alloc
]
initWithRows
:[
self
rows
]
+
10
cols
:[
self
cols
]
type
:
CV_8U
];
[
Core
normalize
:
mat
dst
:
normalized
alpha
:
0
beta
:
255
norm_type
:
NORM_MINMAX
dtype
:
CV_8U
];
Mat
*
normalizedKey
=
[[
Mat
alloc
]
initWithRows
:[
mat
rows
]
+
10
cols
:[
mat
cols
]
type
:
CV_8U
];
std
::
vector
<
char
>
key
;
for
(
int
index
=
0
;
index
<
[
self
cols
];
index
++
)
{
key
.
push_back
((
char
)(
index
*
256
/
[
self
cols
]));
for
(
int
index
=
0
;
index
<
[
mat
cols
];
index
++
)
{
key
.
push_back
((
char
)(
index
*
256
/
[
mat
cols
]));
}
for
(
int
index
=
0
;
index
<
10
;
index
++
)
{
[
normalizedKey
put
:@[[
NSNumber
numberWithInt
:
index
],
[
NSNumber
numberWithInt
:
0
]]
count
:[
self
cols
]
byteBuffer
:
key
.
data
()];
[
normalizedKey
put
:@[[
NSNumber
numberWithInt
:
index
],
[
NSNumber
numberWithInt
:
0
]]
count
:[
mat
cols
]
byteBuffer
:
key
.
data
()];
}
[
normalized
copyTo
:[
normalizedKey
submatRoi
:[[
Rect2i
alloc
]
initWithX
:
0
y
:
10
width
:[
self
cols
]
height
:[
self
rows
]]]];
[
normalized
copyTo
:[
normalizedKey
submatRoi
:[[
Rect2i
alloc
]
initWithX
:
0
y
:
10
width
:[
mat
cols
]
height
:[
mat
rows
]]]];
Mat
*
colorMap
=
[
Mat
new
];
[
Imgproc
applyColorMap
:
normalizedKey
dst
:
colorMap
colormap
:
COLORMAP_JET
];
[
Imgproc
cvtColor
:
colorMap
dst
:
colorMap
code
:
COLOR_BGR2RGB
];
return
[
colorMap
toNSImage
];
}
//everything just return the Mat description
return
[
self
description
];
return
[
mat
description
];
}
@end
modules/objc/generator/gen_objc.py
浏览文件 @
a4a9f56c
...
...
@@ -1438,6 +1438,8 @@ typedef NS_ENUM(int, {1}) {{
opencv_header
=
"#import <Foundation/Foundation.h>
\n\n
"
opencv_header
+=
"// ! Project version number
\n
FOUNDATION_EXPORT double "
+
framework_name
+
"VersionNumber;
\n\n
"
opencv_header
+=
"// ! Project version string
\n
FOUNDATION_EXPORT const unsigned char "
+
framework_name
+
"VersionString[];
\n\n
"
opencv_header
+=
"
\n
"
.
join
([
"#define AVAILABLE_"
+
m
[
'name'
].
upper
()
for
m
in
config
[
'modules'
]])
opencv_header
+=
"
\n\n
"
opencv_header
+=
"
\n
"
.
join
([
"#import <"
+
framework_name
+
"/%s>"
%
os
.
path
.
basename
(
f
)
for
f
in
self
.
header_files
])
self
.
save
(
opencv_header_file
,
opencv_header
)
opencv_modulemap_file
=
os
.
path
.
join
(
output_objc_path
,
framework_name
+
".modulemap"
)
...
...
@@ -1446,8 +1448,9 @@ typedef NS_ENUM(int, {1}) {{
opencv_modulemap
+=
"
\n
"
.
join
([
" header
\"
%s
\"
"
%
os
.
path
.
basename
(
f
)
for
f
in
self
.
header_files
])
opencv_modulemap
+=
"
\n
export *
\n
module * {export *}
\n
}
\n
"
self
.
save
(
opencv_modulemap_file
,
opencv_modulemap
)
available_modules
=
" "
.
join
([
"-DAVAILABLE_"
+
m
[
'name'
].
upper
()
for
m
in
config
[
'modules'
]])
cmakelist_template
=
read_contents
(
os
.
path
.
join
(
SCRIPT_DIR
,
'templates/cmakelists.template'
))
cmakelist
=
Template
(
cmakelist_template
).
substitute
(
modules
=
";"
.
join
(
modules
),
framework
=
framework_name
,
objc_target
=
objc_target
)
cmakelist
=
Template
(
cmakelist_template
).
substitute
(
modules
=
";"
.
join
(
modules
),
framework
=
framework_name
,
objc_target
=
objc_target
,
module_availability_defines
=
available_modules
)
self
.
save
(
os
.
path
.
join
(
dstdir
,
"CMakeLists.txt"
),
cmakelist
)
mkdir_p
(
os
.
path
.
join
(
output_objc_build_path
,
"framework_build"
))
mkdir_p
(
os
.
path
.
join
(
output_objc_build_path
,
"test_build"
))
...
...
modules/objc/generator/templates/cmakelists.template
浏览文件 @
a4a9f56c
...
...
@@ -8,7 +8,7 @@ set(MODULES "$modules")
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_STANDARD_REQUIRED TRUE)
set (OBJC_COMPILE_FLAGS "-fobjc-arc -fobjc-weak -fvisibility=hidden -fPIC -D__OPENCV_BUILD=1")
set (OBJC_COMPILE_FLAGS "-fobjc-arc -fobjc-weak -fvisibility=hidden -fPIC -D__OPENCV_BUILD=1
$module_availability_defines
")
set (SUPPRESS_WARNINGS_FLAGS "-Wno-incomplete-umbrella")
set (CMAKE_CXX_FLAGS "$${CMAKE_CXX_FLAGS} $${OBJC_COMPILE_FLAGS} $${SUPPRESS_WARNINGS_FLAGS}")
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录