你和你的女神之间,差了一个OpenCV口红色号识别器,android开发环境的搭建步骤

MeanC=((int)(Mean_R/count),(int)(Mean_G/count),(int)(Mean_B/count))
return Me

番茄的颜色提取到了,那么和什么做比对呢?

当然是口红的数据,文摘菌这儿用到了 5 个品牌,分别是圣罗兰、香奈儿可可小姐、迪奥、美宝莲、纪梵希,共 17 个系列,271 个口红色号。

数据集是一个嵌套的字典数据结构,存为 json 串的形式,里面记录了每个口红品牌系列下不同口红色号的颜色 id、名称、和 16 进制颜色值。

lipstick.json部分数据集展示如下:

{“brands”:[{“name”:“圣罗兰”,“series”:
[{“name”:“莹亮纯魅唇膏”,“lipsticks”:
[{“color”:"#D62352",“id”:“49”,“name”:“撩骚”},
{“color”:"#DC4B41",“id”:“14”,“name”:“一见倾心”},
{“color”:"#B22146",“id”:“05”,“name”:“浮生若梦”},

数据集中存储的 RGB 颜色是 16 进制的字符串形式,需要将其转换成 RGB 值,比较两个颜色相近与否。

实际上是比较 RGB 三个分量维度上的误差,最小的口红输出对应的品牌、系列、色号和 id。

代码如下:

import json
import getcolor
import numpy as np
import lipcolor

#filename = ‘temp.txt’
##write the temp data to file##
def WtoFile(filename,RGB_temp):
num=len(RGB_temp)
with open(filename,‘w’) as f:
for i in range(num):
s = str(RGB_temp[i]).replace(’[’,’’).replace(’]’,’’)
f.write(s)
f.write("\n")

#operate the data #
##save the brand&series&color id&color name to sum_list##
##covert the color #D62352 to RGB_array##
##caculate the RGB difference to RGB_temp and write the value to file##
def data_operate():
with open(‘lipstick.json’, ‘r’, encoding=‘utf-8’) as f:
ret_dic = json.load(f)
#print(ret_dic[‘brands’])
#print(type(ret_dic)) # <class ‘dict’>
#print(ret_dic[‘brands’][0][‘name’])
b_num=len(ret_dic[‘brands’])
#print(b_num)#brands number

s_list=[]
#series brands#
for i in range(len(ret_dic[‘brands’])):
s_num=len(ret_dic[‘brands’][i][‘series’])
s_list.append(s_num)
#print("{0} has {1} series".format((ret_dic[‘brands’][i][‘name’]),(s_list[i])))

#the lipstick color of every brands every series#
#the first loop calculate the total color numbers
sum=0
for b1 in range(b_num):
for s1 in range(s_list[b1]):
brand_name=ret_dic[‘brands’][b1][‘name’]
lip_name=ret_dic[‘brands’][b1][‘series’][s1][‘name’]
color_num=len(ret_dic[‘brands’][b1][‘series’][s1][‘lipsticks’])
sum+=color_num#calculate the total color numbers

#the second loop save the message to a list#
sum_list=np.zeros((sum,4), dtype=(str,8))
value_array=np.zeros((sum,6), dtype=int)
i=0
for b2 in range(b_num):
for s2 in range(s_list[b2]):
brand_name=ret_dic[‘brands’][b2][‘name’]
#print(type(brand_name))
lip_name=ret_dic[‘brands’][b2][‘series’][s2][‘name’]
color_num=len(ret_dic[‘brands’][b2][‘series’][s2][‘lipsticks’])
for c in range(color_num):
color_value=ret_dic[‘brands’][b2][‘series’][s2][

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值