CodeLibrary/03_pycharm_python_coursework_20240427/opencv_02.py
JRNitre 2092240e04 计算机专业前沿作业 Python
Date: 20240427
Design by JRNitre
2024-04-27 20:40:24 +08:00

68 lines
1.2 KiB
Python

import cv2
import matplotlib.pyplot as plt
import numpy as np
img = cv2.imread('source/data_02.jpg')
plt.subplot(3, 3, 1)
plt.imshow(img)
plt.axis('off')
plt.title('BGR')
# BGR -> RGB
img_RGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.subplot(3, 3, 2)
plt.imshow(img_RGB)
plt.axis('off')
plt.title('RGB')
# 原图 -> 灰度
img_GRAY = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
plt.subplot(3, 3, 3)
plt.imshow(img_GRAY)
plt.axis('off')
plt.title('GRAY')
# HSV
img_HSV = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
plt.subplot(3, 3, 4)
plt.imshow(img_HSV)
plt.axis('off')
plt.title('HSV')
# TCrCb
img_YcrCb = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)
plt.subplot(3, 3, 5)
plt.imshow(img_YcrCb)
plt.axis('off')
plt.title('YcrCb')
# HLS
img_HLS = cv2.cvtColor(img, cv2.COLOR_BGR2HLS)
plt.subplot(3, 3, 6)
plt.imshow(img_HLS)
plt.axis('off')
plt.title('HLS')
# XYZ
img_XYZ = cv2.cvtColor(img, cv2.COLOR_BGR2XYZ)
plt.subplot(3, 3, 7)
plt.imshow(img_XYZ)
plt.axis('off')
plt.title('XYZ')
# LAB
img_LAB = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
plt.subplot(3, 3, 8)
plt.imshow(img_LAB)
plt.axis('off')
plt.title('LAB')
# YUV
img_YUV = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
plt.subplot(3, 3, 9)
plt.imshow(img_YUV)
plt.axis('off')
plt.title('LAB')
plt.show()