Skip to content
프로젝트

foundry/OpenCVSwiftStitch

GitHub에서 보기

소개

OpenCVStitch 버전 6입니다. iOS에서 OpenCV를 사용해 이미지를 스티칭하는 방법을 다룹니다. 이 버전에서는 Swift v5.9 이전에 필요했던 Objective-C 래퍼 없이 하나의 프로젝트에서 Swift와 C++를 함께 사용하는 방법을 보여줍니다.

디자인 및 미디어

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

OpenCV computer vision with iOS: stitching panoramas

Version 6.0 of OpenCVStitch

This update implements Swift/C++ interoperabilty as announced at WWDC 2023. Swift now interfaces directly with the C++ OpenCV API. All traces of Objective-C code have been removed.

This project was created to a answer a couple of Stack Overflow questions:

It demonstrates how to mix Swift and C++ in one project whilst keeping the code clearly separate.

Wrapper

For Swift versions < 5.9 an Objective-C wrapper was required to interface between Swift and C++. Swift 5.9 allows us to dispense with Objective-C altogether. Swift can call the C++ APIs in the OpenCV framework directly.

A small C++ wrapper is still used as a workaround for OpenCV API types that can't be accessed directly or are not yet available from Swift.

Note — the InputArray/OutputArray gotcha

OpenCV's InputArray/OutputArray are reference typedefs (const _InputArray&) over a non-owning proxy, not value types. Early Swift/C++ interop (5.9) couldn't pass them at all, and an early wrapper bridged with cv::InputArray cvInputArray(cv::Mat& m) { return m; } — which compiled and ran, but returns a reference to a temporary (undefined behaviour); it only "worked" because _InputArray stays valid while its backing Mat is alive. The wrapper keeps these proxy types inside C++ and exposes only plain cv::Mat& to Swift. (The helpers are now gone, replaced by OpenCV's own UIImageToMat / MatToUIImage.)

This lifetime dependency is now expressible rather than only conventional: Swift 6.2's safe C++ interop can import _InputArray as SWIFT_NONESCAPABLE and mark the Mat→proxy bridge __lifetimebound (from <swift/bridging>), so the compiler enforces that the proxy can't outlive its Mat. Hiding the proxies is still the simplest choice here; the annotations are the sanctioned route if they are ever exposed directly.

Bridging Header To access the C++ wrapper from Swift in the same module it is imported via a bridging header.

Installation

Swift Package Manager
This version imports OpenCV as a Package Dependency from https://github.com/yeatse/opencv-spm

The Package will install OpenCV v4.13.0 (or later)

Alternatively, you can manually install the OpenCV framework from OpenCV.org

Use

OpenCVStitch is a very simple iOS/openCV example showing basic use of the Stitcher class. The c++ code is adapted from a sample included with the openCV distribution.

The app has almost no user interface. On launch, the stitching code operates on four sample images, displaying the result in a UIScrollView.

OpenCVSwiftStitch Versions
Version 6.0 Swift/C++ interop
OpenCV >=4.13.0 Swift package manager integration
Tested with XCode 15.0-26.6 / Swift 5.9-6.2 for iOS 15-26
Version 5.1
Swift / Objective-C / C++
OpenCV 4.3
Modern Swift - async / await
Error, exception handling from C++ -> Objective-C -> Swift
Tested with XCode 13.2 / Swift 5.0 for iOS 13.0+
Version 5.0
Swift / Objective-C / C++
OpenCV 4.3
Tested with XCode 12.0 / Swift 5.0 for iOS 9.0+
Version 4.0
Swift / Objective-C / C++
Tested with XCode 10.0 / Swift 4.2 for iOS 8.0+
Version 3.0
Swift / Objective-C / C++
Tested with XCode 8.0 / Swift 3.0 for iOS 8.0+
Version 2.1
Swift / Objective-C / C++
Tested with XCode 7.0 / Swift 2.0 for iOS 7.0+
Version 2.0
Swift / Objective-C / C++
Tested with XCode 6.4 / Swift 1.2 for iOS 7.0+
Version 1.0
Objective-C / C++
Tested with XCode 4.5.2 -> 6.3 for iOS 5.1 upwards

Provides a partial answer to: Libraries to capture panoramas in iOS 6 (Stack Overflow)

OpenCV Versions
OpenCV 4.8.1
The Swift package will bring in the most recent stable version of OpenCV

OpenCV 4.3
The podfile installs OpenCV 4.3

this version of OpenCVStitch opted to use cocoapods to overcome the notorious installation issues with previous versions of the framework

XCode 15

Project is now updated for Swift 5.9 and XCode 15. For backwards compatibility checkout the 2.0 / 2.1 branches, 3.0/4.0/5.0 releases or refer to the Objective-C version v1.0.

Comparisons

OpenCV 2.4.9OpenCV 3.0.0OpenCV 3.1.0OpenCV 4.3.0
v2_inset2 v3_inset2 v3.1_inset2 v5_inset2
v2_inset2 v2_inset2 v2_inset2 v5_inset2

관련 프로젝트 살펴보기

불러오는 중…