opencv colors
"""
在利用python进行画图时,我们可能常常用的颜色就是'k'黑色,'r'红色,'b'蓝色,'g'绿色等,这些颜色分别代表常见的
几种颜色。但是当我们画图比较多时,颜色如何分配呢?可以参考下面的这些方案。
这样在画图时,可以选用的就很多,当然在应用时,如果想让你的图更有对比性,可以将对比性差的
去掉不用。
下面的代码来自matplotlib官方。
====================
List of named colors
==================== This plots a list of the named colors supported in matplotlib. Note that
:ref:`xkcd colors <xkcd-colors>` are supported as well, but are not listed here
for brevity. For more information on colors in matplotlib see * the :doc:`/tutorials/colors/colors` tutorial;
* the `matplotlib.colors` API;
* the :doc:`/gallery/color/color_demo`.
""" from matplotlib.patches import Rectangle
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors def plot_colortable(colors, title, sort_colors=True, emptycols=0): cell_width = 212
cell_height = 22
swatch_width = 48
margin = 12
topmargin = 40 # Sort colors by hue, saturation, value and name.
if sort_colors is True:
by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgb(color))),
name)
for name, color in colors.items())
names = [name for hsv, name in by_hsv]
else:
names = list(colors) n = len(names)
print (n)
print (names)
ncols = 4 - emptycols
nrows = n // ncols + int(n % ncols > 0) width = cell_width * 4 + 2 * margin
height = cell_height * nrows + margin + topmargin
dpi = 72 fig, ax = plt.subplots(figsize=(width / dpi, height / dpi), dpi=dpi)
fig.subplots_adjust(margin/width, margin/height,
(width-margin)/width, (height-topmargin)/height)
ax.set_xlim(0, cell_width * 4)
ax.set_ylim(cell_height * (nrows-0.5), -cell_height/2.)
ax.yaxis.set_visible(False)
ax.xaxis.set_visible(False)
ax.set_axis_off()
ax.set_title(title, fontsize=24, loc="left", pad=10) for i, name in enumerate(names):
row = i % nrows
col = i // nrows
y = row * cell_height swatch_start_x = cell_width * col
text_pos_x = cell_width * col + swatch_width + 7 ax.text(text_pos_x, y, name, fontsize=14,
horizontalalignment='left',
verticalalignment='center') ax.add_patch(
Rectangle(xy=(swatch_start_x, y-9), width=swatch_width,
height=18, facecolor=colors[name], edgecolor='0.7')
) return fig plot_colortable(mcolors.BASE_COLORS, "Base Colors",
sort_colors=False, emptycols=1)
plot_colortable(mcolors.TABLEAU_COLORS, "Tableau Palette",
sort_colors=False, emptycols=2) # sphinx_gallery_thumbnail_number = 3
plot_colortable(mcolors.CSS4_COLORS, "CSS Colors") # Optionally plot the XKCD colors (Caution: will produce large figure)
# xkcd_fig = plot_colortable(mcolors.XKCD_COLORS, "XKCD Colors")
# xkcd_fig.savefig("XKCD_Colors.png") plt.show() #############################################################################
#
# .. admonition:: References
#
# The use of the following functions, methods, classes and modules is shown
# in this example:
#
# - `matplotlib.colors`
# - `matplotlib.colors.rgb_to_hsv`
# - `matplotlib.colors.to_rgba`
# - `matplotlib.figure.Figure.get_size_inches`
# - `matplotlib.figure.Figure.subplots_adjust`
# - `matplotlib.axes.Axes.text`
# - `matplotlib.patches.Rectangle`
opencv colors的更多相关文章
- OpenCV 人脸识别 C++实例代码
#include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include & ...
- 学习OpenCV——Surf(特征点篇)&flann
Surf(Speed Up Robust Feature) Surf算法的原理 ...
- OpenCV人脸检测demo--facedetect
&1 问题来源 在运行官网的facedetect这个demo的时候,总是不会出来result的图形,电脑右下角提示的错误是“显示器驱动程序已停止响应,而且已恢复 windows 8(R)”. ...
- OpenCV图像Surf与flann特征点(转载)
Surf(Speed Up Robust Feature) Surf算法的原理 ...
- opencv 人脸识别 (一)训练样本的处理
本文实现基于eigenface的人脸检测与识别.给定一个图像数据库,进行以下步骤: 进行人脸检测,将检测出的人脸存入数据库2 对数据库2进行人脸建模 在测试集上进行recognition 本篇实现 ...
- 《学习OpenCV》练习题第四章第八题ab
这道题是利用OpenCV例子程序里自带的人脸检测程序,做点图像的复制操作以及alpha融合. 说明:人脸检测的程序我参照了网上现有的例子程序,没有用我用的OpenCV版本(2.4.5)的facedet ...
- opencv人脸检测分类器训练小结
这两天在初学目标检测的算法及步骤,其中人脸检测作为最经典的算法,于是进行了重点研究.该算法最重要的是建立人脸检测分类器,因此我用了一天的时间来学习分类器的训练.这方面的资料很多,但是能按照一个资料运行 ...
- opencv 通过摄像头捕捉头部
code: #include <opencv\cv.h> #include <opencv\highgui.h> #include <opencv\cxcore.h> ...
- 访问图像中的像素[OpenCV 笔记16]
再更一发好久没更过的OpenCV,不过其实写到这个部分对计算机视觉算法有所了解的应该可以做到用什么查什么了,所以后面可能会更的慢一点吧,既然开了新坑,还是机器学习更有研究价值吧... 图像在内存中的存 ...
- 修改SR4000自带软件,支持opencv
/*----------------------------------------------------------------------------- * * 版权声明: * 可以任意转载 ...
随机推荐
- 学习Java的第一周总结
经历了一周关于Java的学习后,我想已经初步了解了Java.在这一周中我跟随黑马程序员的脚步初步学习,现在已经安装了jdk环境(当然它不只是一个运行环境,还附带了许多开发工具)并能够用它输出" ...
- Linux安装 JDK (CentOS 7)
Linux安装 JDK 一.Linux安装软件的方式 第一种:二进制发布包安装: 软件已经针对具体平台编译打包发布,只要解压,修改配置即可 第二种: rpm安装 : 软件已经按照redhat的包管理规 ...
- 学习笔记--Java中final关键字
Java中final关键字 关于Java语言中的final关键字: final是一个关键字,表示:最终的,不可改变 final修饰的类无法被继承 final修饰的方法无法被覆盖 final修饰的变量一 ...
- 【郝斌C ST】指针 swap问题
C语言 指针 swap问题 在主函数种实现变量的交换 现在我们把这交换的行为封装进方法中 swap函数确实进行了交换,打印也是10和5了,但是下面a和b的结果还是5和10 - 形参i 和 形参j 并不 ...
- 【Mycat】01 概述
什么是Mycat? 数据库中间件 中间件:是一类连接软件组件和应用的计算机软件,以便于软件各部件之间的沟通. 例子:Tomcat,web中间件. 数据库中间件:连接java应用程序和数据库 为什么要用 ...
- python网络连接报错:ValueError("Unable to determine SOCKS version from %s" % proxy_url) ValueError: Unable to determine SOCKS version from socks://192.168.1.100:1080/
python应用proxy网络连接报错: return super().send(request, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...
- [COCI2013-2014#6] KRUŽNICE 题解
前言 题目链接:洛谷. 题目分析 显然,手模样例发现答案分为以下几个贡献: 所有圆外面的那个大平面,贡献为 \(1\). 每个圆至少被分成一部分,贡献为 \(n\). 如果有一个圆被"拦腰截 ...
- 算法·理论:Manacher 笔记
\(\text{Manacher}\) 来啦! \(\text{Manacher}\) 并没有什么前置知识,比 \(\text{KMP}\) 简单多了. 前置处理 \(\text{Manacher}\ ...
- AtCoder Beginner Contest 315
AtCoder Beginner Contest 315 A - tcdr (atcoder.jp) 一次遍历 #include<bits/stdc++.h> using i64 = lo ...
- 为什么使用#define 而不是用enum定义常量
typedef enum { IOTAG_PORT__A = (0), IOTAG_PORT__B, IOTAG_PORT__C, IOTAG_PORT__F, IOTAG_PORT__ITEMS } ...