赞
踩
- # hsv_color_picker
- """
- import cv2
- import numpy as np
- def nothing(x):
- pass
- cv2.namedWindow("frame")
- cv2.createTrackbar("H","frame",0,179,nothing)
- cv2.createTrackbar("S","frame",255,255,nothing)
- cv2.createTrackbar("V","frame",255,255,nothing)
- img_hsv=np.zeros((250,500,3),np.uint8)
- while True:
- h=cv2.getTrackbarPos("H","frame")
- s=cv2.getTrackbarPos("S","frame")
- v=cv2.getTrackbarPos("V","frame")
- img_hsv[:]=(h,s,v)
- img_bgr=cv2.cvtColor(img_hsv,cv2.COLOR_HSV2BGR)
- cv2.imshow("frame",img_bgr)
- key=cv2.waitKey(1)
- if key==27:
- break
- cv2.destroyWindow()
- """
-
- import cv2
-
- cap=cv2.VideoCapture(1)
- cap.set(cv2.CAP_PROP_FRAME_WIDTH,1280)
- cap.set(cv2.CAP_PROP_FRAME_HEIGHT,720)
-
-
- while True:
- _,frame=cap.read()
- hsv_frame=cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
- height,width,_=frame.shape
-
- cy,cx=height//2,width//2
-
- # 获取画面中心点像素值
- pixel_center=hsv_frame[cy,cx]
- hue_value=pixel_center[0]
-
- color="Undefined"
- if 0<hue_value<11 or 156<hue_value<180:
- color="RED"
- elif 11<hue_value<25:
- color="ORANGE"
- elif 26<hue_value<34:
- color="YELLOW"
- elif 35<hue_value<77:
- color="GREEN"
- elif 78<hue_value<99:
- color="Qing"
- elif 100<hue_value<124:
- color="BLUE"
- elif 125<hue_value<155:
- color="purple"
- # elif hue_value<170:
- # color="PINK"
- else:
- pass
- # color="RED"
-
-
- pixel_center_bgr=frame[cx,cy]
- b,g,r=[int(i) for i in pixel_center_bgr]
-
- cv2.putText(frame,color,(10,70),0,1,(255,255,255),2)
- cv2.circle(frame,(cx,cy),8,(255,255,255),3)
-
- cv2.imshow("Frame",frame)
- key=cv2.waitKey(1)
- if key==27:
- break
-
- cap.release()
- cv2.destroyWindow()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。