|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +import cv2 |
| 3 | +import numpy as np |
| 4 | + |
| 5 | +# Learn arithmetic operations on images, addition, subtraction, bit operations, etc. |
| 6 | + |
| 7 | +# You can use the function cv2.add() to add two images. Of course, you can also use numpy directly. |
| 8 | +# res=img1+img |
| 9 | +# The size and type of the two images must be the same, or the second image can be a simple scalar value. |
| 10 | + |
| 11 | + |
| 12 | +x = np.uint8([250]) |
| 13 | +y = np.uint8([10]) |
| 14 | +print(cv2.add(x, y)) # 250+10 = 260 => 255 |
| 15 | +# [[255]] |
| 16 | +print(x + y) # 250+10=260%256=4 |
| 17 | +# [4] |
| 18 | + |
| 19 | + |
| 20 | +# 图像混合 # Image mixing |
| 21 | +img1 = cv2.imread('data/ml.png') |
| 22 | +img2 = cv2.imread('data/opencv_logo.jpg') |
| 23 | + |
| 24 | +dst = cv2.addWeighted(img1, 0.7, img2, 0.3, 0) # 第一幅图的权重是 0.7 第二幅图的权重是 0.3 |
| 25 | + # The weight of the first image is 0.7 and the weight of the second image is 0.3 |
| 26 | + |
| 27 | +cv2.imshow('dst', dst) |
| 28 | +cv2.waitKey(0) |
| 29 | +cv2.destroyAllWindows() |
0 commit comments