首页 > 编程知识 正文

iphone 13 pro max和iphone13 pro,opencv画虚线

时间:2023-05-05 17:26:25 阅读:211443 作者:2669

opencv中HSV的值范围是:H 0-180;S 0-255; V 0-255 

import cv2from PIL import Imageimport numpy as npdef fetch_img(img, first_list, color_value_list, width, height): r,g,b = color_value_list sec_list = [0, width, 2*width] third_value_list = [0, 1, 2] img[first_list[0]:first_list[1], sec_list[0]:sec_list[1], third_value_list[0]] = np.full((height, width),b) img[first_list[0]:first_list[1], sec_list[0]:sec_list[1], third_value_list[1]] = np.full((height, width),g) img[first_list[0]:first_list[1], sec_list[0]:sec_list[1], third_value_list[2]] = np.full((height, width),r) img[first_list[0]:first_list[1], sec_list[1]:sec_list[2], third_value_list[0]] = np.full((height, width),255 - b) img[first_list[0]:first_list[1], sec_list[1]:sec_list[2], third_value_list[1]] = np.full((height, width),255 - g) img[first_list[0]:first_list[1], sec_list[1]:sec_list[2], third_value_list[2]] = np.full((height, width),255 - r) return imgdef fetch_img2(img, first_list, color_value_list, width, height): h,s,v = color_value_list # print("%dt%d"%(h, 90+h if h<90 else h-90 )) #opencv中色相环是顺时针的,和网上图片一样 sec_list = [0, width, 2*width] third_value_list = [0, 1, 2] img[first_list[0]:first_list[1], sec_list[0]:sec_list[1], third_value_list[0]] = np.full((height, width),h) img[first_list[0]:first_list[1], sec_list[0]:sec_list[1], third_value_list[1]] = np.full((height, width),s) img[first_list[0]:first_list[1], sec_list[0]:sec_list[1], third_value_list[2]] = np.full((height, width),v) img[first_list[0]:first_list[1], sec_list[1]:sec_list[2], third_value_list[0]] = np.full((height, width),90+h if h<360 else h-90) img[first_list[0]:first_list[1], sec_list[1]:sec_list[2], third_value_list[1]] = np.full((height, width),s) img[first_list[0]:first_list[1], sec_list[1]:sec_list[2], third_value_list[2]] = np.full((height, width),v) return imgdef generate_chart(): width = 100 height = 50 #RGB模型下画12色相环 color_num = 12 background = np.zeros((color_num*height,2*width,3)) color_dict = {"red":[255,0,0],"orange":[255,128,0],"yellow":[255, 255, 0],"yellowgreen":[128, 255, 0],"green":[0, 255, 0],"cyan_green":[0, 255, 128],"cyan":[0, 255, 255],"indigo":[0,128,255],"blue":[0, 0, 255],"purple":[128, 0, 255],"magenta":[255, 0, 255],"purple_red":[255, 0, 128]} color_list = ['red', 'orange', 'yellow', 'yellowgreen', 'green', 'cyan_green', 'cyan', 'indigo', 'blue', 'purple', 'magenta', 'purple_red'] pos_list = range(0,(color_num+1)*height,height) for num in range(len(color_list)): color = color_list[num] color_value_list = color_dict[color] pos_value = [pos_list[num],pos_list[num+1]] background = fetch_img(background, pos_value, color_value_list,width, height) cv2.imwrite("12.jpg", background) # cv2.imshow("src_12",background) #RGBzydxhd下画24色相环 color_num = 24 background = np.zeros((color_num*height,2*width,3)) color_dict = {"red":[255,0,0],"red_orange":[255,64,0],"orange":[255,128,0],"orange_yellow":[255, 192, 0],"yellow":[255, 255, 0],"yellowyellowgreen":[192, 255, 0],"yellowgreen":[128, 255, 0],"yellowgreengreen":[64, 255, 0],"green":[0, 255, 0],"green_cyan_green":[0, 255, 64],"cyan_green":[0, 255, 128],"cyan_green_cyan":[0, 255, 192],"cyan":[0, 255, 255],"cyan_indigo":[0,192,255],"indigo":[0,128,255],"indigo_blue":[0, 64, 255],"blue":[0, 0, 255],"blue_purple":[64, 0, 255],"purple":[128, 0, 255],"purple_magenta":[192, 0, 255],"magenta":[255, 0, 255],"magenta_purple_red":[255, 0, 192],"purple_red":[255, 0, 128],"purple_red_red":[255,0,64]} color_list = ['red', "red_orange",'orange',"orange_yellow",'yellow', "yellowyellowgreenrzdsb,"yellowgreengreen无私的睫毛, "green_cyan_green",'cyan_green',"cyan_green_cyan",'cyan', 'cyan_indigo','indigo','indigo_blue', 'blue', 'blue_purple','purple', 'purple_magenta','magenta','magenta_purple_red', 'purple_red',"purple_red_red"] pos_list = range(0,(color_num+1)*height,height) for num in range(len(color_list)): color = color_list[num] color_value_list = color_dict[color] pos_value = [pos_list[num],pos_list[num+1]] background = fetch_img(background, pos_value, color_value_list,width, height) cv2.imwrite("24.jpg", background) #HSVzydxhd下画12色相环 color_num = 12 background = np.zeros((color_num * height, 2 * width, 3)) # color_dict = {"red": [0, 255, 255], "orange": [30, 255, 255], "yellow": [60, 255, 255],"yellowgreen": [90, 255, 255], "green": [120, 255, 255], "cyan_green": [150, 255, 255],"cyan": [180, 255, 255], "indigo": [210, 255, 255], "blue": [240, 255, 255],"purple": [270, 255, 255], "magenta": [300, 255, 255], "purple_red": [330, 255, 255]} color_dict = {"red": [0, 255, 255], "orange": [15, 255, 255], "yellow": [30, 255, 255],"yellowgreen": [45, 255, 255], "green": [60, 255, 255], "cyan_green": [75, 255, 255],"cyan": [90, 255, 255], "indigo": [105, 255, 255], "blue": [120, 255, 255],"purple": [135, 255, 255], "magenta": [150, 255, 255], "purple_red": [165, 255, 255]} color_list = ['red', 'orange', 'yellow', 'yellowgreen', 'green', 'cyan_green', 'cyan', 'indigo', 'blue', 'purple','magenta', 'purple_red'] pos_list = range(0, (color_num + 1) * height, height) background = cv2.cvtColor(np.uint8(background), cv2.COLOR_BGR2HSV) for num in range(len(color_list)): color = color_list[num] color_value_list = color_dict[color] pos_value = [pos_list[num],pos_list[num+1]] background = fetch_img2(background, pos_value, color_value_list,width, height) background = cv2.cvtColor(background, cv2.COLOR_HSV2BGR) cv2.imwrite("12_hsv.jpg",background)def process(): generate_chart()if __name__ == "__main__": process()

    
 12色相环_rgbzydxhd下          12色相环_hsvzydxhd下             24色相环_rgbzydxhd下和下图对比效果是一样的

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。