In this assignment you will implement and experiment with a document scanner tool that can let you unwarp images based on keypoints. The functionality is similar to that of Microsoft’s Offiffiffice Lens or Adobe Scan. This tool is based on homographies, which is a matrix transform that relates two planar surfaces in space as discussed in Lectures 1 and 2. Your specifific task is to complete the technique’s implementation in the starter code. The code has an optional app that you can use to test your algorithm and play around with the document scanner interactively.
Goals: The goals of this assignment are to (1) get you familiar with working with images, Python,and NumPy; (2) learn how to implement basic geometrical operations like transformations and mapping; and (3) learn some insights of what kind of diffiffifficulties arise when you geometrically manipulate images.
Bonus: We suggest that you implement the transformations in the most naive way possible using for loops; there are ways to implement it much faster by taking advantage of NumPy and vectorization.
Although there are no explicit bonus marks for effiffifficient code in this assignment, you should discuss any improvements you made in your report. Exceptional efffforts in this direction may be rewarded with a bonus on a case-by-case basis.
Important: You should start by getting a high level idea of what the code does by reading this document. Then, try to run the reference solution by following the instructions in the section below.
Once you get the high level idea of what the code does, take a look at app/a1/a1 headless.py (where the app is implemented) and viscomp/algos/a1.py (what you need to complete) to understand the overall flflow of things. Everything you need to implement is in viscomp/algos/a1.py. You do not need to make any other changes. What you should not do: you may not rely on OpenCV or any external computer vision or image processing library to implement the assignment. You should be able to implement everything just purely with NumPy and Python.
Testing your implementation: Your implementation will be tested on the teaching labs Linux machines, by running app/a1/a1 tests.py. Make sure you can run these tests by following the instructions below and check that your output looks fifine.
Homography Algorithm (85 Marks)
In this section, you will implement the two algorithms:
- Homography Matrix: Calculating a homography matrix from 2 quadrilaterals.
- Backward Mapping: Looping through every destination pixel and using the homography to fifind the corresponding source pixel.
Both of these functions and their skeletons can be found in viscomp/algos/a1.py. Your implementation will wholly reside in this fifile. You will not need to make modifification to anything else in the codebase.
Part A.1: Homography Matrix: The calculate homography() function (45 marks)
We can estimate a homography H given suffiffifficiently many point correspondences. Usually, many correspondences are used to compute H. However, for this assignment, we will use the minimum number of correspondences needed for a unique solution: four, under the condition that the four points are distinct, and defifine a (convex) quadrilateral. You will be implementing the code for determining H in calculate homography().
Let’s start by writing down the equations for a single point pi in the source image and its correspon dence p′ i in the destination image, shown in the Figure 2 below:
Points pi and p′ i have known coordinates, either provided by the values in the .csv fifiles for the reference solution or extracted from the user’s clicks in the interactive app. We can write them as:
pi =xi yi 1，p′ i =x′i y′i 1
and are related by the unknown homography matrix H
Part A.2: Backward Mapping: The backward mapping() function (40 marks)
Now that we have our homography matrix H, we can apply it to portion of the source image in the convex region outlined by the four source correspondence points.
This is the task for backward mapping(), where you will pass in as input
- transform: your 3×3 homography matrix solved for in calculate homography
- source image: the Hs x Ws x 4 image that is used as the source to read from.
- destination image: the Hd x Wd x 4 image that is used as the destination to write to.
- destination coords: the 2D locations of the 4 corners on the destination.
and return the backward mapped image. This task will require looping through every destination pixel, fifinding which points are inside the convex polygon, using the homography H to fifind the corresponding source pixel, and writing to that pixel with the destination pixel. Make sure to check your matrix dimensions when implementing the multiplication!
本网站支持淘宝 支付宝 微信支付 paypal等等交易。如果不放心可以用淘宝交易！
E-mail: email@example.com 微信:itcsdx