mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Use cv::Ptr instead of raw pointers
This commit is contained in:
@@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@interface Mat : NSObject
|
||||
|
||||
#ifdef __cplusplus
|
||||
@property(readonly) cv::Mat* nativePtr;
|
||||
@property(readonly) cv::Ptr<cv::Mat> nativePtr;
|
||||
@property(readonly) cv::Mat& nativeRef;
|
||||
#endif
|
||||
|
||||
@@ -35,8 +35,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (instancetype)init;
|
||||
- (void)dealloc;
|
||||
#ifdef __cplusplus
|
||||
- (instancetype)initWithNativeMat:(cv::Mat*)nativeMat;
|
||||
+ (instancetype)fromNativePtr:(cv::Mat*)nativePtr;
|
||||
- (instancetype)initWithNativeMat:(cv::Ptr<cv::Mat>)nativeMat;
|
||||
+ (instancetype)fromNativePtr:(cv::Ptr<cv::Mat>)nativePtr;
|
||||
+ (instancetype)fromNative:(cv::Mat&)nativeRef;
|
||||
#endif
|
||||
- (instancetype)initWithRows:(int)rows cols:(int)cols type:(int)type;
|
||||
|
||||
@@ -39,39 +39,31 @@ static bool updateIdx(cv::Mat* mat, std::vector<int>& indices, int inc) {
|
||||
}
|
||||
|
||||
- (cv::Mat&)nativeRef {
|
||||
return *(cv::Mat*)_nativePtr;
|
||||
return *_nativePtr;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_nativePtr = new cv::Mat();
|
||||
_nativePtr = cv::Ptr<cv::Mat>(new cv::Mat());
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
if (_nativePtr != NULL) {
|
||||
_nativePtr->release();
|
||||
delete _nativePtr;
|
||||
}
|
||||
_nsdata = NULL;
|
||||
}
|
||||
|
||||
- (instancetype)initWithNativeMat:(cv::Mat*)nativePtr {
|
||||
- (instancetype)initWithNativeMat:(cv::Ptr<cv::Mat>)nativePtr {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_nativePtr = new cv::Mat(*nativePtr);
|
||||
_nativePtr = nativePtr;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (instancetype)fromNativePtr:(cv::Mat*)nativePtr {
|
||||
+ (instancetype)fromNativePtr:(cv::Ptr<cv::Mat>)nativePtr {
|
||||
return [[Mat alloc] initWithNativeMat:nativePtr];
|
||||
}
|
||||
|
||||
+ (instancetype)fromNative:(cv::Mat&)nativeRef {
|
||||
return [[Mat alloc] initWithNativeMat:&nativeRef];
|
||||
return [[Mat alloc] initWithNativeMat:cv::Ptr<cv::Mat>(new cv::Mat(nativeRef))];
|
||||
}
|
||||
|
||||
- (instancetype)initWithRows:(int)rows cols:(int)cols type:(int)type {
|
||||
|
||||
Reference in New Issue
Block a user