Python代写|Assignment2 Image matching and retrieval



1 Computer Vision Assignment 2: Image matching and retrieval

In this assignment, you will experiment with image feature detectors, descriptors and matching.

There are 3 main parts to the assignment:

  • matching an object in a pair of images
  • searching for an object in a collection of images
  • analysis and discussion of results

This assignment will have a minimum hurdle of 40%. You will fail if you can not reach the minimum hurdle.

1.1 General instructions

As before, you will use this notebook to run your code and display your results and analysis. Again we will mark a PDF conversion of your notebook, referring to your code if necessary, so you should ensure your code output is formatted neatly.

When converting to PDF, include the outputs and analysis only, not your code. You can do this from the command line using the nbconvert command (installed as part of Jupyter) as follows:

jupyter nbconvert Assignment2.ipynb –to pdf –no-input –TagRemovePreprocessor.remove_cell_tags ‘remove-cell’

Please do try this ccommond early before the last day!

This will also remove the preamble text from each question. We will use the OpenCV library to complete the prac. It has several built in functions that will be useful. You are expected to consult documentation and use them appropriately.

This being the second assignment, we have provided less strict direction this time and you have more flexibility to choose how you answer each question. However you still need to ensure the outputs and report are clear and easy to read. This includes:

  • sizing, arranging and captioning image outputs appropriately
  • explaining what you have done clearly and concisely
  • clearly separating answers to each question

1.2 Data

We have provided some example images for this assignment, available through a link on the MyUni assignment page. The images are organised by subject matter, with one folder containing images of book covers, one of museum exhibits, and another of urban landmarks. Within each category, there is a “Reference” folder containing a clean image of each object and a “Query” folder containing images taken on a mobile device. Within each category, images with the same name contain the same object (so 001.jpg in the Reference folder contains the same book as 001.jpg in the Query folder). The data is a subset of the Stanford Mobile Visual Search Dataset which is available at

The full data set contains more image categories and more query images of the objects we have provided, which may be useful for your testing!

Do not submit your own copy of the data or rename any files or folders! For marking, we will assume the datasets are available in subfolders of the working directory using the same folder names provided.

Here is some general setup code, which you can edit to suit your needs.

[1]: # Numpy is the main package for scientific computing with Python.

import numpy as np

import cv2

# Matplotlib is a useful plotting library for python

import matplotlib.pyplot as plt

# This code is to make matplotlib figures appear inline in the

# notebook rather than in a new window.

%matplotlib inline

plt.rcParams[‘figure.figsize’] = (10.0, 8.0) # set default size of plots, can

, be changed

plt.rcParams[‘image.interpolation’] = ‘nearest’

plt.rcParams[‘image.cmap’] = ‘gray’

# Some more magic so that the notebook will reload external python modules;

# see

, autoreload-of-modules-in-ipython

%load_ext autoreload

%autoreload 2

%reload_ext autoreload

[ ]: def draw_outline(ref, query, model):


Draw outline of reference image in the query image.

This is just an example to show the steps involved.

You can modify to suit your needs.


ref: reference image

query: query image

model: estimated transformation from query to reference image


h,w = ref.shape[:2]

pts = np.float32([ [0,0],[0,h-1],[w-1,h-1],[w-1,0] ]).reshape(-1,1,2)

dst = cv2.perspectiveTransform(pts,model)

img = query.copy()

img = cv2.polylines(img,[np.int32(dst)],True,255,3, cv2.LINE_AA)

plt.imshow(img, ‘gray’),

def draw_inliers(img1, img2, kp1, kp2, matches, matchesMask):


Draw inlier between images

img1 / img2: reference/query img

kp1 / kp2: their keypoints

matches : list of (good) matches after ratio test

matchesMask: Inlier mask returned in cv2.findHomography()


matchesMask = matchesMask.ravel().tolist()

draw_params = dict(matchColor = (0,255,0), # draw matches in green color

singlePointColor = None,

matchesMask = matchesMask, # draw only inliers

flags = 2)

img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches,None,**draw_params)

plt.imshow(img3, ‘gray’),


本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail:  微信:itcsdx