Before, I published a recommended image processing entry 100 questions, mainly for some basic operations of image processing, very suitable for entry! \

However, this resource tutorial was written by a Japanese, and the Japanese version is very inconvenient to read. Good news, recently I was on GitHub and noticed someone had translated this tutorial into Chinese. This project contains the CV field, OpenCV image processing introduction 100 sample analysis, and equipped with complete Pyhon code.

First, put the original Japanese address: \

Github.com/yoyoyo-yo/G…

The corresponding Chinese translation address: \

Github.com/gzr2017/Ima…

Tutorial\

This part of the minimalist tutorial is mainly to introduce the image processing open source library OpenCV installation, read, display images, operating pixels and other basic operations. Available in Python and C++.

The authors recommend a minimalist installation method for OpenCV:

1. Install MiniConda

Address: conda. IO/miniconda. H…

2. Create a virtual environment and activate it

$ conda create python = 3.6  -  n gasyori 100
$ source actiavte gasyori 100
Copy the code

3. The installation package

$ pip install -r requirement.txt
Copy the code

The requirement. TXT file is downloaded from the root directory of the project to the command line directory and run the preceding command directly.

This project contains a total of 100 image processing introductory questions, below take a look at each one! \

Question 1-10 \

This section is available in both Python and C++. Consider, for example, a value filtering algorithm.

Python:

import cv2
import numpy as np

# Read image
img = cv2.imread("imori_noise.jpg")
H, W, C = img.shape


# Gaussian Filter
K_size = 3
sigma = 1.3

## Zero padding
pad = K_size / / 2
out = np.zeros((H + pad*2, W + pad*2, C), dtype=np.float)
out[pad:pad+H, pad:pad+W] = img.copy().astype(np.float)

## Kernel
K = np.zeros((K_size, K_size), dtype=np.float)
for x in range(-pad, -pad+K_size):
    
    for y in range(-pad, -pad+K_size):
        K[y+pad, x+pad] = np.exp( -(x**2 + y**2)/(2* (sigma**2)))
K /= (sigma * np.sqrt(2 * np.pi))
K /= K.sum()

tmp = out.copy(a)for y in range(H):
    for x in range(W):
        for c in range(C):
            out[pad+y, pad+x, c] = np.sum(K * tmp[y:y+K_size, x:x+K_size, c])

out = out[pad:pad+H, pad:pad+W].astype(np.uint8)

# Save result
cv2.imwrite("out.jpg", out)
cv2.imshow("result", out)
cv2.waitKey(0)
cv2.destroyAllWindows()
Copy the code

C + + version: \

#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <math.h>


// gaussian filter
cv::Mat gaussian_filter(cv::Mat img, double sigma, int kernel_size){
  int height = img.rows;
  int width = img.cols;
  int channel = img.channels();

  // prepare output
  cv::Mat out = cv::Mat::zeros(height, width, CV_8UC3);

  // prepare kernel
  int pad = floor(kernel_size / 2);
  int _x = 0, _y = 0;
  double kernel_sum = 0;
  
  // get gaussian kernel
  float kernel[kernel_size][kernel_size];

  for (int y = 0; y < kernel_size; y++){
    for (int x = 0; x < kernel_size; x++){
      _y = y - pad;
      _x = x - pad;
      kernel[y][x] = 1 / (2 * M_PI * sigma * sigma) * exp( - (_x * _x + _y * _y) / (2* sigma * sigma)); kernel_sum += kernel[y][x]; }}for (int y = 0; y < kernel_size; y++){
    for (int x = 0; x < kernel_size; x++){ kernel[y][x] /= kernel_sum; }}// filtering
  double v = 0;
  
  for (int y = 0; y < height; y++){
    for (int x = 0; x < width; x++){
      for (int c = 0; c < channel; c++){

      v = 0;

      for (int dy = -pad; dy < pad + 1; dy++){
        for (int dx = -pad; dx < pad + 1; dx++){
          if (((x + dx) >= 0) && ((y + dy) >= 0)){ v += (double)img.at<cv::Vec3b>(y + dy, x + dx)[c] * kernel[dy + pad][dx + pad]; } } } out.at<cv::Vec3b>(y, x)[c] = v; }}}return out;
}

int main(int argc, const char* argv[]){
  // read image
  cv::Mat img = cv::imread("imori_noise.jpg", cv::IMREAD_COLOR);

  // gaussian filter
  cv::Mat out = gaussian_filter(img, 1.3.3);
  
  //cv::imwrite("out.jpg", out);
  cv::imshow("answer", out);
  cv::waitKey(0);
  cv::destroyAllWindows();

  return 0;
}
Copy the code

Question 11-20 \

Question 21-30 \

Question 31-40 \

Question 41 to 50 \

Question 51 to 60 \

Problem \ 61-70

Problem \ 71-80

Problem \ 81-90

Problem \ 91-100

The biggest feature of this project is 100 questions step by step, basically covering the key knowledge points of OpenCV. If you are getting started with CV and learning OpenCV, this project will be a good tutorial from beginning to advanced. Use the code, personally run the results, I hope to help you!