Mat+Converters.mm 941 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // Mat+Converters.mm
  3. //
  4. // Created by Giles Payne on 2020/03/03.
  5. //
  6. #import "Mat+Converters.h"
  7. #import <opencv2/imgcodecs/ios.h>
  8. @implementation Mat (Converters)
  9. -(CGImageRef)toCGImage {
  10. return MatToCGImage(self.nativeRef);
  11. }
  12. -(instancetype)initWithCGImage:(CGImageRef)image {
  13. return [self initWithCGImage:image alphaExist:NO];
  14. }
  15. -(instancetype)initWithCGImage:(CGImageRef)image alphaExist:(BOOL)alphaExist {
  16. self = [self init];
  17. if (self) {
  18. CGImageToMat(image, self.nativeRef, (bool)alphaExist);
  19. }
  20. return self;
  21. }
  22. -(UIImage*)toUIImage {
  23. return MatToUIImage(self.nativeRef);
  24. }
  25. -(instancetype)initWithUIImage:(UIImage*)image {
  26. return [self initWithUIImage:image alphaExist:NO];
  27. }
  28. -(instancetype)initWithUIImage:(UIImage*)image alphaExist:(BOOL)alphaExist {
  29. self = [self init];
  30. if (self) {
  31. UIImageToMat(image, self.nativeRef, (bool)alphaExist);
  32. }
  33. return self;
  34. }
  35. @end