当前位置:网站首页>opencv自带颜色操作
opencv自带颜色操作
2022-07-24 17:05:00 【什么时候上岸?】
示例代码如下:
void demo::color_style(Mat& image)
{
int colormap[] = {
COLORMAP_AUTUMN,
COLORMAP_BONE,
COLORMAP_CIVIDIS,
COLORMAP_COOL,
COLORMAP_HOT,
COLORMAP_HSV,
COLORMAP_INFERNO,
COLORMAP_JET,
COLORMAP_MAGMA,
COLORMAP_OCEAN,
COLORMAP_PARULA,
COLORMAP_PINK,
COLORMAP_PLASMA,
COLORMAP_RAINBOW,
COLORMAP_SPRING,
COLORMAP_SUMMER,
COLORMAP_TWILIGHT,
COLORMAP_TWILIGHT_SHIFTED,
COLORMAP_VIRIDIS,
COLORMAP_WINTER};
Mat dsc;
int index = 0;
while (true)
{
int c = waitKey(500);
if (c == 27)
break;
applyColorMap(image, dsc, colormap[index % 20]);
index++;
imshow("图像类型", dsc);}
}
这里的重点是applyColorMap()函数,它声明在imgproc.hpp
CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, int colormap);
在上面这个函数的定义前面,我们还可以看到下面内容:
enum ColormapTypes
{
COLORMAP_AUTUMN = 0, //!< 
COLORMAP_BONE = 1, //!< 
COLORMAP_JET = 2, //!< 
COLORMAP_WINTER = 3, //!< 
COLORMAP_RAINBOW = 4, //!< 
COLORMAP_OCEAN = 5, //!< 
COLORMAP_SUMMER = 6, //!< 
COLORMAP_SPRING = 7, //!< 
COLORMAP_COOL = 8, //!< 
COLORMAP_HSV = 9, //!< 
COLORMAP_PINK = 10, //!< 
COLORMAP_HOT = 11, //!< 
COLORMAP_PARULA = 12, //!< 
COLORMAP_MAGMA = 13, //!< 
COLORMAP_INFERNO = 14, //!< 
COLORMAP_PLASMA = 15, //!< 
COLORMAP_VIRIDIS = 16, //!< 
COLORMAP_CIVIDIS = 17, //!< 
COLORMAP_TWILIGHT = 18, //!< 
COLORMAP_TWILIGHT_SHIFTED = 19 //!< 
};
可以发现在定义colormap(色度图)的时候,用了枚举,所以在我们的代码里面可以定义一个int类型的数组来存储20种colormap。
数组的索引是从0开始的,所以是index%20,如果是index%21就会报错。
applyColormap()函数第一个参数是输入的图像,第二个参数是输出的图像,第三个参数是提供的色彩图代码值。(就是colormap中的枚举类型)
applyColorMap()函数还有另一个用法:
CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, InputArray userColor);
userColor:自定义的色彩(CV_8UC1 or CV_8UC3 and size 256)。
结果展示:

over!!!
边栏推荐
- 快速入门
- How to effectively avoid memory leakage when customizing the handler?
- 内核开发
- IP的概念,IP的分类,IP复用技术
- GDB online debugging of work notes
- CANN训练营学习2022第二季 模型系列 动漫风格化和AOE ATC调优
- 为什么被调函数内部不能用 sizeof(arr) / size(arr[0]) 计算数组长度?
- IP day 13 notes
- Axi protocol (2): five channels and two transactions of Axi architecture
- 【时序逻辑电路】——计数器
猜你喜欢

ArcGIS pixel size changed from 0.00025 to meters

Duplicate content in lookup table

Method of querying comma separated strings in a field by MySQL

quick get start

会议OA项目进度(一)

Buffer overflow vulnerability lab experiment record

查数据库实际数据增长情况

我们为什么要推出Getaverse?

Live review | wonderful playback of Apache pulsar meetup (including PPT download)

Apachecon Asia 2022 opens registration: pulsar technology issues make a big debut
随机推荐
804. Unique Morse code word
MODIS data WGet Download
工信安全中心牵头搭建数据流通平台 蚂蚁集团等厂商提供技术支持
安全:如何为行人提供更多保护
量化框架backtrader之一文读懂Indicator指标
PS pull out logo
Explain Apache Hudi schema evolution in detail
Amd Ruilong 7000 is expected to be available on September 15, and the 3D cache version will have to wait
EF miscellaneous
AI opportunities for operators: expand new tracks with large models
Check the actual data growth of the database
The latest Zhejiang construction safety officer simulation question bank and answers in 2022
ufw 端口转发
安全的证券公司有哪些?我想在手机上买股票
JSP custom tag library -- select tag
【零基础】充分理解WebGL(八)
Duplicate content in lookup table
Axi protocol (3): handshake mechanism and implementation details of Axi architecture
Long awaited full platform support - Open Source im project uniapp update of openim
GDB online debugging of work notes