首页 > 其他分享 >9、OpenCV4.4 色彩抽出

9、OpenCV4.4 色彩抽出

时间:2022-09-28 11:00:12浏览次数:63  
标签:img dst OpenCV4.4 imshow cv2 抽出 shape hsv 色彩


色彩的空间变换

# -*- coding: utf-8 -*-
import cv2
import numpy as np
original = cv2.imread('1.jpg', 1)
img = original.copy()
#副本
dst = np.zeros(img.shape,np.uint8)
#创建相同的图像矩阵
hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
#色彩转换
colorRange = [0,10]
thanSaturate = 0
thanValue = 0

for x in xrange(0,img.shape[1]):
for y in xrange(0,img.shape[0]):
# HSV 还是这样写比较nice 三色通道 [a,b,c] 通过阀值进行处理
if hsv[y,x,0] >= colorRange[0] and hsv[y,x,0] < colorRange[1] and hsv[y,x,1] > thanSaturate and hsv[y,x,2] > thanValue:
radius = 1
color = tuple([255,0,0])
thicness = 1
cv2.circle(img,tuple([x,y]),radius,color,thicness)

dst[y,x] = img[y,x]

cv2.imshow('Original',original)
cv2.imshow('Add',img)
cv2.imshow('Diff',dst)
cv2.imwrite('add.png',img)
cv2.imwrite('diff.png',dst)
k=cv2.waitKey(0)&0xff
print k
if k==27:
cv2.destroyAllWindows()
elif k==ord('s'):
cv2.imwrite('mypicture.png',img)
cv2.destroyAllWindows()

9、OpenCV4.4 色彩抽出_编程

9、OpenCV4.4 色彩抽出_编程_02

9、OpenCV4.4 色彩抽出_编程_03

标签:img,dst,OpenCV4.4,imshow,cv2,抽出,shape,hsv,色彩
From: https://blog.51cto.com/u_12504263/5718760

相关文章