九、OpenCV自带colormap

项目功能实现:每隔1500ms轮流自动播放不同风格图像显示,按下Esc键退出

按照之前的博文结构来,这里就不在赘述了

一、头文件

colormap.h

#pragma once
#include
using namespace cv;

class ColorMap {
public:
	void color_map(Mat& image);
};

二、函数实现

colorsapces.cpp

#include"colormap.h"
#include
#include


void ColorMap::color_map(Mat& image) {
	
	int color_map[] = {
		COLORMAP_AUTUMN,
		COLORMAP_BONE,
		COLORMAP_CIVIDIS,
		COLORMAP_COOL,
		COLORMAP_DEEPGREEN,
		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_TURBO,
		COLORMAP_TWILIGHT,
		COLORMAP_TWILIGHT_SHIFTED,
		COLORMAP_VIRIDIS,
		COLORMAP_WINTER
	};

	Mat result;
	int index = 0;

	while (true) {
		int key = waitKey(1500);
		if (key == 27) {//Esc
			break;
		}
		applyColorMap(image, result, color_map[index % 21]);//这里有22种类型,循环播放
		index++;
		imshow("colormap", result);
	}

}

三、主函数

yy_main.cpp

#include 
#include 
#include "colormap.h"

using namespace cv;
using namespace std;

int main(int argc, char** argv) {
	Mat src = cv::imread("E:/C++_workspace/beyond.jpg", IMREAD_COLOR);

	if (src.empty()) {
		printf("load image is false...\n");
		return -1;
	}

	namedWindow("yanyu", WINDOW_FREERATIO);
	imshow("yanyu", src);

	ColorMap yy;
	yy.color_map(src);

	waitKey(0);
	destroyAllWindows();

	return 0;
}


项目结构如下:
九、OpenCV自带colormap_第1张图片
运行结果如下:
九、OpenCV自带colormap_第2张图片

你可能感兴趣的:(OpenCV4.8,&&,C++,&&,VS,opencv,人工智能,计算机视觉)