Skip to content

Expose CGImage <-> Mat conversion for iOS platforms#18855

Merged
alalek merged 4 commits intoopencv:masterfrom
Rightpoint:feature/colejd/add-apple-conversions-to-framework-builds
Nov 19, 2020
Merged

Expose CGImage <-> Mat conversion for iOS platforms#18855
alalek merged 4 commits intoopencv:masterfrom
Rightpoint:feature/colejd/add-apple-conversions-to-framework-builds

Conversation

@colejd
Copy link
Copy Markdown
Contributor

@colejd colejd commented Nov 18, 2020

#18547 introduces CGImage<->Mat conversion for MacOS platforms. This PR enables the same capabilities for iOS platforms. C++ users can now use MatToCGImage and CGImageToMat in ios.h, and Objc users can now do the equivalent conversions in Mat+Converters.h.

I also took the liberty of adding CF_RETURNS_RETAINED annotations to methods that return CGImageRef, so that the Swift compiler knows to CFRelease() when the reference count goes to 0. This is technically a breaking change, as the prior implementation required users to explicitly use takeRetainedValue() to properly reference count; however, I think the expectation is that such objects are reference counted by default, so I would categorize the prior behavior as a bug and my changes as a bugfix.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
force_builders_only=Custom Mac
build_image:Custom Mac=osx_framework-test
buildworker:Custom Mac=macosx-2
build_contrib:Custom Mac=OFF

@colejd colejd force-pushed the feature/colejd/add-apple-conversions-to-framework-builds branch from a7a2c8c to 1f93b48 Compare November 18, 2020 21:39
@alalek
Copy link
Copy Markdown
Member

alalek commented Nov 19, 2020

/cc @mtfrctl @komakai

@mtfrctl
Copy link
Copy Markdown
Contributor

mtfrctl commented Nov 19, 2020

Thank you @colejd !
Originally there was no CGImage <-> Mat conversion method for iOS (https://github.com/opencv/opencv/pull/18547/files#diff-c3966397c21ebeff71a44f0344019837cd32fdd566133506b5ed8d9a91bf8a3e), and the interface was added for macOS by me, so it's not intentionally hidden for iOS, but thank you for adding it for iOS as well.

Also, regarding the CF_RETURNS_RETAINED annotation, I was not confident in this process, so thank you for adding it.

@colejd
Copy link
Copy Markdown
Contributor Author

colejd commented Nov 19, 2020

@mtfrctl Thanks! Sorry, I didn't mean to imply any wrongdoing on your part. I should have paid more attention to the file history. Kind of flying by the seat of my pants here. I'll edit the description for clarity.

@colejd colejd changed the title Add apple_conversions to framework builds Expose CGImage <-> Mat conversion for iOS platforms Nov 19, 2020
@alalek
Copy link
Copy Markdown
Member

alalek commented Nov 19, 2020

👍

@alalek alalek merged commit c4c9cdd into opencv:master Nov 19, 2020
@colejd colejd deleted the feature/colejd/add-apple-conversions-to-framework-builds branch November 20, 2020 17:19
@alalek alalek mentioned this pull request Nov 27, 2020
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
…ple-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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants