仅作为记录,大佬请跳过。
读取和显示图像
import cv2
img = cv2.imread('chipcode1_1.jpg')
cv2.imshow('src',img)
cv2.waitKey(0)
cv.imshow显示图像过大
系统自动
加入cv2.namedWindow('src', 0)
展示
加入前: 加入后:
参考
更新大佬博主文章:传送门
直接规定大小
用cv2.resizeWindow('demo', 600, 500)
import cv2
img = cv2.imread('chipcode1_1.jpg')
cv2.namedWindow('src', 0)
cv2.resizeWindow('src', int(img.shape[0]/3), int(img.shape[1]/3))
cv2.imshow('src',img)
cv2.waitKey(0)
cv2的HSV色域
import cv2
import matplotlib.pyplot as plt
'''读取图像,取灰度图'''
img=cv2.imread('chipcode1_1.jpg', cv2.IMREAD_COLOR)
img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
turn_green_hsv = img_hsv.copy()
turn_green_hsv[:, :, 0] = (turn_green_hsv[:, :, 0]+15) % 180
turn_green_img = cv2.cvtColor(turn_green_hsv, cv2.COLOR_HSV2BGR)
colorless_hsv = img_hsv.copy()
colorless_hsv[:, :, 1] = 0.5 * colorless_hsv[:, :, 1]
colorless_img = cv2.cvtColor(colorless_hsv, cv2.COLOR_HSV2BGR)
darker_hsv = img_hsv.copy()
darker_hsv[:, :, 2] =255
darker_img = cv2.cvtColor(darker_hsv, cv2.COLOR_HSV2BGR)
cv2.namedWindow('src', 0)
cv2.resizeWindow('src', int(img.shape[0]/3), int(img.shape[1]/3))
cv2.imshow('src',darker_img)
cv2.waitKey(0)
print('ok')
展示
完全参考大佬博主文章:传送门
import cv2
img=cv2.imread('test3.png', cv2.IMREAD_COLOR)
img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
turn_green_hsv = img_hsv.copy()
turn_green_hsv[:, :, 0] = (turn_green_hsv[:, :, 0]+15) % 180
turn_green_img = cv2.cvtColor(turn_green_hsv, cv2.COLOR_HSV2BGR)
cv2.imshow('image',turn_green_img)
cv2.waitKey(0)
colorless_hsv = img_hsv.copy()
colorless_hsv[:, :, 1] = 0.5 * colorless_hsv[:, :, 1]
colorless_img = cv2.cvtColor(colorless_hsv, cv2.COLOR_HSV2BGR)
cv2.imshow('image',colorless_img)
cv2.waitKey(0)
darker_hsv = img_hsv.copy()
darker_hsv[:, :, 2] =255
darker_img = cv2.cvtColor(darker_hsv, cv2.COLOR_HSV2BGR)
cv2.imshow('image',darker_img)
cv2.waitKey(0)
|