程序代写 PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

Changjae Oh

Copyright By PowCoder代写 加微信 powcoder

Computer Vision
– Tutorial 1 –

Semester 1, 22/23

• Setting up your playground

• Python / examples

• OpenCV / examples

• Setting up your playground

• Following slides are guidelines for those who start Python from scratch

• You can use your own way to setup the environment

• BUT make sure that your code is runnable in the provided environment:

̶ Python 3.8

̶ opencv-python

̶ opencv-contrib-python

̶ matplotlib

• A free and open-source distribution of the Python languages

̶ for scientific computing (data science, machine learning applications, large-scale data
processing, predictive analytics, etc.),

̶ aims to simplify package management and deployment.

Miniconda (Anaconda)

• A free minimal installer for conda.

̶ A small, bootstrap version of Anaconda that includes only conda, Python, the package
s they depend on, and a small number of other useful packages, including pip, zlib and
a few others.

̶ https://docs.conda.io/en/latest/miniconda.html

Download → Install

https://docs.conda.io/en/latest/miniconda.html

• Making your Python coding easier

̶ https://www.jetbrains.com/pycharm/

https://www.jetbrains.com/pycharm/

• Download -> Install!

1. Your directory

2. Put “requirements.txt” (in QMPlus) in the above folder

Your name! QM number!

3. Run Anaconda Prompt

4. Create the virtual environment (your playground)

5. Activate the environment

6. Installing packages from “requirements.txt”

Your virtual environment includes all libraries you need for this module

Now, let’s connect this virtual environment with PyCharm

9. Open PyCharm -> Projects ->

10. Set location as your folder

11. Previously configured interpreter → click “Add Local Interpreter…”

12. Load your conda environment

13. Click “OK” → “Create” → “Create from Existing Sources”

13. Create the subfolders you will need

14. Put any image in ./inputs/

15. Create python File in the ./codes/

16. Right click -> Run

Now you are ready to code!

Useful tips

• Setting up your playground

Why Python?

https://www.upgrad.com/blog/reasons-why-python-popular-with-developers/

Python (numpy) vs MATLAB

• Setting up your playground

Image Read

• cv2.imread()

̶ Loads an image from a file

̶ If the image cannot be read (because of missing file, improper permissions, unsupport
ed or invalid format), returns an empty matrix (Mat::data == NULL)

➢filename – Name of file to be loaded
➢flags – Flag that can take values of cv::ImreadModes

Image Show

• cv2.imshow()

̶ Displays an image in the specified window

Image Write

• cv2.imwrite()

̶ Saves an image to a specified file

Example 1 – Image Read / Write

• Read Lena.jpg with colour and greyscale and show them

Example 1 – Code

## image read, show, write

import cv2

im = cv2.imread(‘./inputs/lena.jpg’)

im_gray1 = cv2.imread(‘./inputs/lena.jpg’, 0)

im_gray2 = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)

cv2.imshow(‘lena’, im)

cv2.waitKey()

cv2.imshow(‘lena_gray’, im_gray1)

cv2.waitKey()

cv2.imshow(‘lena_gray’, im_gray2)

cv2.waitKey()

cv2.imwrite(‘./inputs/lena_gray.jpg’, im_gray1)

Example 2 – Image Composition with Numpy

• Resize the Lena image to half resolution and composite as shown below:

Example 2 – Code
# Image composition with numpy

import numpy as np

import cv2

im_gray = cv2.imread(‘./inputs/lena.jpg’, 0)

h, w = im_gray.shape

h_resize = np.int(np.floor(h/2))

w_resize = np.int(np.floor(w/2))

im_gray_resized = cv2.resize(im_gray, (h_resize, w_resize))

im_composited = np.zeros([h, w])

im_composited[0:h_resize, 0:w_resize] = im_gray_resized

cv2.imshow(‘lena’, im_gray)

cv2.waitKey()

cv2.imshow(‘lena_gray_com’, np.uint8(im_composited))

cv2.waitKey()

cv2.imwrite(‘./inputs/lena_gray_small.jpg’, np.uint8(im_composited))

Example 3 – Perspective Projection

• Given two point sets:
̶ 𝒙 = 𝒙1, … , 𝒙4 = 𝑢1, 𝑣1 , … , (𝑢4, 𝑣4) = (41,176), (67,1133), (749,16), (749,1270)

̶ 𝒙′ = 𝒙′1, … , 𝒙′4 = 𝑢′1, 𝑣′1 , … , (𝑢′4, 𝑣′4) = (0, 0), (0,1280), (749,0), (749,1280)

Find the perspective projection matrix 𝑷 such that 𝒙′ = 𝑷𝒙 and warp the image

• Perform perspective projection

Linear system

Linear system

Example 3 – Code

import sys

import numpy as np

import cv2

im = cv2.imread(‘./inputs/food.jpg’, 1)

rect = np.array([(176, 41), (1133, 67), (16, 749), (1270, 749)], dtype=”float32″)

dst = np.array([(0, 0), (1280, 0), (0, 749), (1280, 749)], dtype=”float32″)

M = cv2.getPerspectiveTransform(rect, dst)

warped = cv2.warpPerspective(im, M, (im.shape[1], im.shape[0]))

cv2.imshow(”, im)

cv2.waitKey()

cv2.imshow(”, warped)

cv2.waitKey()

cv2.imwrite(‘./results/food_rect.jpg’,warped)

Example 3 – Code

Example 3 – Code

Example 3 – Perspective Projection

• Given two point sets:
̶ 𝒙 = 𝒙1, … , 𝒙4 = 𝑢1, 𝑣1 , … , (𝑢4, 𝑣4) = (41,176), (67,1133), (749,16), (749,1270)

̶ 𝒙′ = 𝒙′1, … , 𝒙′4 = 𝑢′1, 𝑣′1 , … , (𝑢′4, 𝑣′4) = (0, 0), (0,1280), (749,0), (749,1280)

Find the perspective projection matrix 𝑷 such that 𝒙′ = 𝑷𝒙 and warp the image

• Perform perspective projection

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com