Computer vision review

Posted by SleepyP on Wed, 15 Dec 2021 15:50:32 +0100

1, Multiple choice questions

Details in the course.

2, Noun interpretation

1. Color space: also known as color model, color space, color model, etc., it is a storage method of images in the computer.

2. Perspective transformation: perspective transformation will convert the image into any quadrilateral. Its main feature is that all lines in the original image are still lines in the converted image.

3. Mean filtering: mean filtering takes the current point as the center and replaces the pixel value of the current point with the average value of the pixel values of the surrounding N*N points.

4. Gaussian filtering: Gaussian filtering is slightly different from mean filtering. It gives different weight values to pixels according to different distances between pixels and center points. The closer to the center point, the greater the weight, and the farther away from the center point, the smaller the weight; Then, the sum of all pixels in the field is calculated according to the weight value, and the sum is taken as the pixel value of the center point.

5. Binarization threshold processing: CV2 The value of the type parameter of the threshold() function is CV2 THRESH_ Binary performs binarization threshold processing, setting the pixel value greater than the threshold value to 255 and other pixel values to 0.

6. Anti binarization threshold processing: CV2 The value of the type parameter of the threshold() function is CV2 THRESH_ BINARY_ Inv, the inverse binarization threshold is processed, and the pixel value greater than the threshold is set to 0 and other pixel values are set to 255.

7. Corrosion: when the corrosion operation traverses the image, the output result of the image pixel corresponding to the center of the kernel will be determined according to the position of the kernel and the image. Through the etching operation, the boundary of the image is corroded. Reduce and refine the highlighted area or white part of the image, and the running result graph is smaller than the highlighted area of the original graph

8. Expansion: the expansion operation is just opposite to the corrosion operation. It expands the boundary of the image. When traversing, the value of the corresponding pixel in the center of the kernel is set to 0 only when the kernel is completely outside the foreground, otherwise it is set to 1

3, Simple questions

1. Main functions of Opencv: built-in data structure and input / output; Image processing operation; Graphical user interface operation;

Video analysis; 3D reconstruction; Feature extraction; Object detection; Machine learning;

Deep learning; Computational photography; Morphological analysis; Face detection and recognition; Surface matching;

Text detection and recognition.

2. How to perform image addition: addition operators "+" and CV2 The add() function can be used to perform an image addition operation.

When adding two image arrays with the "+" operator, if the addition of two pixels is greater than 256, it will be modulo by 256. cv2. When the add() function performs the addition of two image arrays, if the addition of two pixels is greater than 256, 255 is taken

3. Basic steps of KNN Algorithm in ml module of OpenCV:

(1) Call the cv2.ml.kneasest_create() function to create a KNN classifier.

(2) Taking the training data and flags as inputs, the train() method of KNN classifier is called to train the model.

(3) Take the data to be classified as input, call the findNearest() method of KNN classifier to find k nearest neighbors and return the relevant information of classification results.

4. Basic steps of EigenFaces face recognition:

(1) Call the cv2.face.EigenFaceRecognizer_create() method to create the EigenFaces recognizer

(2) Call the train() method of the recognizer to train the model with a known image

(3) Call the predict() method of the recognizer to identify the unknown image and confirm its identity.

5. The basic steps of image recognition using the deep learning pre training model in OpenCV:

(1) Load the model from the configuration file and the pre training model file.

(2) Processing an image file as block data (blob)

(3) Sets the block data of the image file as the input of the model

(4) Execute forecast

(5) Process forecast results

4, Programming fill in the blanks

Refer to the experimental examination contents

5, Programming problem

1. P144: CV2 of OpenCV Calchist() function to find the histogram, and then use Matplotlib The plot() function of pyplot plots histograms

import cv2
import matplotlib.pyplot as plt

img = cv2.imread('th.jpg')
cv2.imshow('original', img)
histb = cv2.calcHist([img], [0], None, [256], [0, 255])  # Calculate channel B histogram
plt.plot(histb, color='b')  # Calculate channel B histogram
plt.show()

2. P159: detect the face in the image

import cv2
img = cv2.imread('heard.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Load face detector
face = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
faces = face.detectMultiScale(gray)  # Perform face detection
for x, y, w, h in faces:
    cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)  # Draw rectangle to label face

cv2.imshow('face', img)  # Display test results
cv2.waitKey(0)

3. Fisher faces face recognition

import cv2
import numpy as np
# Read in training image
img11 = cv2.imread('x11.jpg', 0)  # Open image, grayscale image
img12 = cv2.imread('x12.jpg', 0)
img13 = cv2.imread('x13.jpg', 0)
img21 = cv2.imread('x21.jpg', 0)
img22 = cv2.imread('x22.jpg', 0)
img23 = cv2.imread('x23.jpg', 0)
train_images = [img11, img12, img13, img21, img22, img23]  # Create training image array
labels = np.array([0, 0, 0, 1, 1, 1])  # Create label array
recognizer = cv2.face.FisherFaceRecognizer_create()  # Create FisherFaces recognizer
recognizer.train(train_images, labels)  # Perform training operations
testimg = cv2.imread('no.jpg', 0)  # Open test image
label, confidence = recognizer.predict(testimg)  # Face recognition
print('Matching label:', label)
print('Credibility:', confidence)

Topics: OpenCV AI Computer Vision