Merge pull request #18855 from Rightpoint:feature/colejd/add-apple-conversions-to-framework-builds

Expose CGImage <-> Mat conversion for iOS platforms

* Add apple_conversions to framework builds

This exposes CGImage <-> Mat conversion.

* Export Mat <-> CGImage methods on iOS targets

* Add CGImage converters to iOS objc helper class

* Add CF_RETURNS_RETAINED annotations to methods returning CGImageRef
pull/18881/head
Jonathan Cole 4 years ago committed by GitHub
parent 11cfa64a10
commit c4c9cdd2b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/imgcodecs/CMakeLists.txt
  2. 2
      modules/imgcodecs/include/opencv2/imgcodecs/ios.h
  3. 2
      modules/imgcodecs/include/opencv2/imgcodecs/macosx.h
  4. 3
      modules/imgcodecs/misc/objc/ios/Mat+Converters.h
  5. 16
      modules/imgcodecs/misc/objc/ios/Mat+Converters.mm
  6. 2
      modules/imgcodecs/misc/objc/macosx/Mat+Converters.h
  7. 2
      modules/imgcodecs/src/apple_conversions.h

@ -113,7 +113,7 @@ file(GLOB imgcodecs_ext_hdrs
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/legacy/*.h"
)
if(APPLE)
if(APPLE OR APPLE_FRAMEWORK)
list(APPEND imgcodecs_srcs ${CMAKE_CURRENT_LIST_DIR}/src/apple_conversions.h)
list(APPEND imgcodecs_srcs ${CMAKE_CURRENT_LIST_DIR}/src/apple_conversions.mm)
endif()

@ -50,6 +50,8 @@
//! @addtogroup imgcodecs_ios
//! @{
CV_EXPORTS CGImageRef MatToCGImage(const cv::Mat& image) CF_RETURNS_RETAINED;
CV_EXPORTS void CGImageToMat(const CGImageRef image, cv::Mat& m, bool alphaExist = false);
CV_EXPORTS UIImage* MatToUIImage(const cv::Mat& image);
CV_EXPORTS void UIImageToMat(const UIImage* image,
cv::Mat& m, bool alphaExist = false);

@ -12,7 +12,7 @@
//! @addtogroup imgcodecs_macosx
//! @{
CV_EXPORTS CGImageRef MatToCGImage(const cv::Mat& image);
CV_EXPORTS CGImageRef MatToCGImage(const cv::Mat& image) CF_RETURNS_RETAINED;
CV_EXPORTS void CGImageToMat(const CGImageRef image, cv::Mat& m, bool alphaExist = false);
CV_EXPORTS NSImage* MatToNSImage(const cv::Mat& image);
CV_EXPORTS void NSImageToMat(const NSImage* image, cv::Mat& m, bool alphaExist = false);

@ -20,6 +20,9 @@ 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;
-(UIImage*)toUIImage;
-(instancetype)initWithUIImage:(UIImage*)image;
-(instancetype)initWithUIImage:(UIImage*)image alphaExist:(BOOL)alphaExist;

@ -9,6 +9,22 @@
@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);
}

@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
CV_EXPORTS @interface Mat (Converters)
-(CGImageRef)toCGImage;
-(CGImageRef)toCGImage CF_RETURNS_RETAINED;
-(instancetype)initWithCGImage:(CGImageRef)image;
-(instancetype)initWithCGImage:(CGImageRef)image alphaExist:(BOOL)alphaExist;
-(NSImage*)toNSImage;

@ -7,5 +7,5 @@
#import <ImageIO/ImageIO.h>
#include "opencv2/core.hpp"
CV_EXPORTS CGImageRef MatToCGImage(const cv::Mat& image);
CV_EXPORTS CGImageRef MatToCGImage(const cv::Mat& image) CF_RETURNS_RETAINED;
CV_EXPORTS void CGImageToMat(const CGImageRef image, cv::Mat& m, bool alphaExist);

Loading…
Cancel
Save