邯郸wap网站建设报价,首次建设网站流程图,花都网站推广,项目建设方案怎么写需要根据不同的数值生成不同色彩的小方块#xff0c;并标明数值#xff0c;考虑到各种色彩的方块#xff0c;如果采用文字采用黑色或者白色总是避免不了和背景色重复#xff0c;所以把数值转化成rgb(0x11,0xf0,0x3b)类似的值#xff0c;然后文字采用rgb(255-0x11,255-0xf0…需要根据不同的数值生成不同色彩的小方块并标明数值考虑到各种色彩的方块如果采用文字采用黑色或者白色总是避免不了和背景色重复所以把数值转化成rgb(0x11,0xf0,0x3b)类似的值然后文字采用rgb(255-0x11,255-0xf0,255-0x3b)要把背景色的rgb转成十进制再进行减法操作这里为了方便陈述用的十六进制没有转。这里的filename为需要做方块图的数值按一定格式存在此文件中例如11330a346578944c32011按自己数值存放的格式解析就好了总之得到需要作图的数值按一定的方式转成rgb后再作图或者自己挑选几种、几十种类似这样的#0012ce色彩值对应自己的数值也行import numpy as npimport matplotlibmatplotlib.use(Agg)import matplotlib.pyplot as pltimport osimport cv2import re #按固定长度截取字符串img_output_path/home/xxx/image/class draw_sequences():def __init__(self, idx):#背景颜色为黑色的画布#im np.zeros((300, 300, 3), dtypeuint8) #3#背景颜色为白色的画布self.im np.ones((800,600,3),np.uint8)*255#画布使用默认字体self.font cv2.FONT_HERSHEY_SIMPLEX#起始作图坐标self.leftx 10self.lefty 10#矩形单元长高self.len 70self.high 15self.filepath img_output_path / idx#第idx张画布(也许一张不够)self.idx idxself.bdraw Falseself.filename filename#画一个矩形序列单元def draw_sequence(self, listseq):if self.leftx self.len 600:self.leftx 10self.move_down()self.bdraw True#矩形边框颜色#cv2.rectangle(self.im, (self.leftx, self.lefty), (self.leftxself.len, self.leftyself.high), (int(listseq[0],16),int(listseq[1],16),int(listseq[2],16))) #12#填充矩形颜色rseq int(listseq[0],16)gseq (int(listseq[1],16)100)%255bseq (int(listseq[2],16)50)%255cv2.rectangle(self.im, (self.leftx, self.lefty), (self.leftxself.len, self.leftyself.high), (rseq, gseq, bseq), thickness-1)#填充文字seq .join(str(i) for i in listseq)cv2.putText(self.im,seq,(self.leftx, self.lefty10), self.font, 0.4, (255-rseq, 255-gseq,255-bseq), 1)self.move_right()#保存序列图def write_jpg(self):if self.bdraw True:cv2.imwrite(self.filepath .jpg, self.im)self.idx self.idx 1self.__init__(self.idx)#往右移一个位置画序列单元def move_down(self):self.lefty self.lefty self.highself.leftx 10if self.lefty 800:self.write_jpg()#另起一行画序列单元def move_right(self):self.leftx self.leftxself.lencdraw draw_sequences(, filemd5, 0)txtread open(filename,r)for line in txtread:sub_seqs i.split()sub_seqs.pop()idx 0lseq []for i in sub_seqs:if len(i) 2:subseqs re.findall(r.{2}, i)for j in subseqs:lseq.append(j)if (idx1)%3 0:cdraw.draw_sequence(lseq)lseq []idx idx1else:lseq.append(i)if (idx1)%3 0:cdraw.draw_sequence(lseq)lseq []idx idx1listlen len(lseq)if (listlen):if listlen 3:for i in range(listlen,3):lseq.append(00)cdraw.draw_sequence(lseq)cdraw.move_right()cdraw.write_jpg()del cdraw这里是一行数值作一张图符号分割后的数字两位两位划分不够的用0补每6位数字作一个方块