Created
October 5, 2020 13:07
-
-
Save komakai/c48fcd738b87e28a482ee34a8f9bdcc9 to your computer and use it in GitHub Desktop.
Access Mat.data from Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MatDataExt.h | |
// | |
// Created by Giles Payne on 2020/10/05. | |
// | |
#pragma once | |
#ifdef __cplusplus | |
#import <opencv2/opencv2.h> | |
#endif | |
#import <Foundation/Foundation.h> | |
@class Mat; | |
@interface MatDataExt: NSObject | |
+(unsigned char*)getMatData:(Mat*)mat; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MatDataExt.mm | |
// | |
// Created by Giles Payne on 2020/10/05. | |
// | |
#import "MatDataExt.h" | |
#import "opencv2/Mat.h" | |
@implementation MatDataExt | |
+(unsigned char*)getMatData:(Mat*)mat { | |
return [mat nativePtr]->data; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MatDataExt.swift | |
// | |
// Created by Giles Payne on 2020/10/05. | |
// | |
import Foundation | |
import opencv2 | |
extension Mat { | |
var data: UnsafeMutablePointer<UInt8> { | |
return MatDataExt.getMatData(self) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Make sure to set Objective-C Bridging Header in the project's Build Settings | |
// | |
#import "MatDataExt.h" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment