opev 随手记
**black = np.uint8([[[255,255,255]]])** #这里的三层括号应该分别对应于cvArray,cvMat,IplImage
**HSV = cv2.cvtColor(black,cv2.COLOR_BGR2HSV)**
颜色 | BGR | HSV |
---|---|---|
白 | 255,255,255 | 0,0,255 |
黑 | 0,0,0 | 0,0,0 |
##绘制轮廓
import cv2
img = cv2.imread(r'H:\Users\jm-zgs\Pictures\test.jpg')
imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.imshow('imgray',imgray)
ret,thresh = cv2.threshold(imgray,127,255,0)
image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
img = cv2.drawContours(img, contours, 2, (0,255,0), 1)
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
###颜色识别
import cv2
import numpy as np
black_lower=np.array([0,0,0])
black_upper=np.array([175,100,80])
img=cv2.imread(r"H:\Users\jm-zgs\Pictures\biao.jpg",cv2.IMREAD_COLOR)
cv2.imshow('image',img)
hsv=cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
cv2.imshow('hsv',hsv)
print(hsv[10,20])
mask=cv2.inRange(hsv,black_lower,black_upper)
res=cv2.bitwise_and(img,img,mask=mask)
cv2.imshow('image2',res)
cv2.imshow('msk',mask)
cv2.waitKey(0)
cv2.destroyAllWindows()