Python
OpenCV
Tutorials

In this lab tutorial, you will learn the basis of python and how to use the OpenCV-python library to perform basic image processing tasks. The experiments are performed in the Google Colab environment. You can run the experiments without installing any software on your computer.

Start Learning

Lab Report

Individual Report

Due date: 23 Oct 2024

Include Code, figures

Submit: PDF file only to Blackboard

Q&A: Contact at the Bottom of this web page

Questions Image Resources: Link

Question 1

Give the codes and answers to the following questions about Numpy, use only one line code

  1. How to find the maximum value of each row in a 2-dimensional NumPy array? (Find the maximum value of each row in a given array)

    
    np.random.seed(100)
    a = np.random.randint(1,10, [5,3])
    #> array([[9, 9, 4],
    #> [8, 8, 1],
    #> [5, 3, 6],
    #> [3, 3, 3],
    #> [2, 1, 9]])
                    
  2. How to compute the result of dividing the min-by-max of each row of a 2-dimensional NumPy array? (Given a 2-dimensional NumPy array, compute min-by-max for each row)

    
    np.random.seed(100)
    a = np.random.randint(1,10, [5,3])
    a
    #> array([[9, 9, 4],
    #> [8, 8, 1],
    #> [5, 3, 6],
    #> [3, 3, 3],
    #> [2, 1, 9]])
                    
  3. How to remove all missing values from a NumPy array? (Remove all nan values from a 1-dimensional NumPy array)

    
    # input
    np.array([1,2,3,np.nan,5,6,7,np.nan])
    # expect output
    array([ 1., 2., 3., 5., 6., 7.])
                    
  4. How to find all local maxima (peaks) in a 1-dimensional array? (Find all the peaks in a 1-dimensional array a. A peak is a number that is larger than the numbers on either side of it.)

    
    # input
    a = np.array([1, 3, 7, 1, 2, 6, 0, 1])
    # expect output
    array([2, 5])
                    
  5. How to invert all columns of a 2D array? (Reverse all columns in 2D array arr)

    
    # input
    arr = np.arange(9).reshape(3,3)
                    

Question 2

Calculate and report the camera's intrinsics and distortion coefficient of the provided images on a checkerboard (The checkerboards square actual size is 20x20 mm. The images of checkerboards are in the folder Q2_calibration).

Question 3

Using the provided set of 9 images (The images are in the folder Q3_stitching):

  • Implement an image stitching algorithm using OpenCV.
  • Detect and match keypoints between adjacent images.
  • Estimate homographies between image pairs.

Question 4

Implement a stereo matching algorithm to generate a disparity map from the provided pair of stereo images (The images are in the folder Q4_disparity).

Question 5

Leaf Contour Extraction: Extract the contour of the green leaf in the image (The image in the folder Q5_contour), and discuss potential challenges and solutions for extracting contours from more complex backgrounds than the simple single-colored desktop.