Codementor Events

How and why I built PerspectiveTransform cocoapod

Published Feb 08, 2019Last updated Feb 12, 2019
How and why I built PerspectiveTransform cocoapod

About me

I am an iOS developer with 10 years of experience, have built and released over 80 apps to the AppStore.

The problem I wanted to solve

Many apps have an onboarding flow to show how the app is used. Our designer wanted to show live screenshots of the app as it looks in a hands of users. This requires transforming a screenshot into the perspective of a user shown on a picture.

By calculating Core Animation transformation CATransform3D matrix we can tranform an image to place it exactly within the boundaries.
with-overlay.svg

What is PerspectiveTransform cocoapod?

PerspectiveTransform is a Cocoapod library that allows 3D transformation of a view into a perspective defined by 4 corners.

https://cocoapods.org/pods/PerspectiveTransform

Tech stack

I've used multiple approaches:

  1. OpenCV - open-source computer vision framework on Mac and iOS.
  2. Accelerate.framework by Apple
  3. SIMD framework by Apple

The process of building PerspectiveTransform cocoapod

There was one solution I found online but it was using an inefficient method of linear equations to solve the problem

Challenges I faced

Computer vision framework is quite large, takes a long time to install and slow as it does multiple iterations to approximate the solution.

Key learnings

SIMD - "Single Instruction Multiple Data" builtin iOS framework provided the most efficient and elegant solution to the problem.

Tips and advice

TDD or Test Driven Development is a very helpful way to discover new more efficient and elegant solutions.

Final thoughts and next steps

Github repository:
https://github.com/paulz/PerspectiveTransform
100% test coverage report:
https://codecov.io/gh/paulz/PerspectiveTransform
Continuous Integration on Circle CI and Travis:
https://circleci.com/gh/paulz/PerspectiveTransform
https://travis-ci.org/paulz/PerspectiveTransform

Discover and read more posts from Paul Zabelin
get started
post commentsBe the first to share your opinion
Show more replies