Python image processing OpenCV


Preface

  • Basic package opencv-python
  • High distribution opencv-contrib-python

1. Image basis

1.1 Theoretical introduction

Insert picture description here
Use cv2.imread() to change the storage format :
from jpg:rgb—>opencv:bgr
Insert picture description here
Insert picture description here
Insert picture description here

One image processing:

  • 1. Three-dimensional array
  • 2. Draw a three-dimensional scatter chart
  • 3. The histogram of the image: the gray-scale image of the statistical pixel distribution
  • Three-dimensional color image == "turned to one-dimensional grayscale image
    Insert picture description here
  • Draw a histogram
    Insert picture description here
    Insert picture description here
    Insert picture description here
    Insert picture description here
    Insert picture description here
  • ravel() method pulls the array dimension into a one-dimensional array
  • Hist function function-draw a histogram

1.2 Case 1-Handwritten Digit Recognition

Enter a picture: identify the digital
opencv, remove the messy lines and dots in the digital picture, filter out all the messy lines, and keep only the digital lines
Insert picture description here

  • Create a picture

Choose the thickest line to write the number, and use other lines (not the thickest) to add and embellish

Insert picture description here
Insert picture description here
Insert picture description here

  • Number recognition
    Insert picture description here
    Insert picture description here
    Insert picture description here
    Insert picture description here
    Insert picture description here
    Insert picture description here
    Insert picture description here

  • Generate verification code pip install captcha
    Insert picture description here
    Insert picture description here
    Insert picture description here
    Insert picture description here
    Insert picture description here
    Insert picture description here

  • To get all the files in this folder, you can use the for (root, dirs, files) in walk (path name) function .


2. Image filtering and preprocessing

Opencv filtering and edge detection: recognition of lane lines
'''
Identifies geometric features in the image, such as: line circle square
1. Grayscale color image is converted to grayscale image
2. Filtering is prepared for edge detection. What about filtering? The interference of noise on edge detection eliminates the influence of noise
3. Edge detection Canny Sobel Laplacian> Find the difference between adjacent or close pixels (pixel difference)
4. Shape feature detection Hough transform
'''

2.1 Filtering

Insert picture description here

  • Mean filter
    Insert picture description here

  • Set salt and pepper noise
    Insert picture description here
    Insert picture description here

  • Gaussian filter-must be an odd term
    Insert picture description here

  • Median filtering-must be an odd term
    Insert picture description here

2.2 Edge detection

  • Canny
    Insert picture description here
    Insert picture description here
    Insert picture description here
  • Sobel
    Insert picture description here
  • Laplace
    Insert picture description here

Three, image transformation

  • Affine transformation
  • Perspective transformation

3.1 Affine transformation

Two-dimensional to two-dimensional graphics, translation, rotation, zoom and other operations

Insert picture description here
Insert picture description here

  • Pan
    Insert picture description here
  • Zoom out and pan
    Insert picture description here
  • Spin
    Insert picture description here
    Insert picture description here
    Insert picture description here

3.2 Perspective transformation

Two-dimensional transformation into three-dimensional space and then projected to a new plane, also known as: projection mapping.
Function 1: Turn to the real image plane. Function 2: Transform or transform the original captured image to improve the accuracy of image recognition.

Insert picture description here
Insert picture description here
Insert picture description here

pst1: coordinate point in the original image pst2: coordinate point
to be generated

Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/HG0724/article/details/114180572