人类的感知不是为了观察灰度图像的细微变化而建立的。 人眼对观察颜色之间的变化更敏感,因此您经常需要重新着色灰度图像以获取有关它们的线索。 OpenCV 现在带有各种颜色图来增强计算机视觉应用程序的可视化。
在 OpenCV 中,您只需要 applyColorMap 即可在给定图像上应用颜色图。 以下示例代码从命令行读取图像的路径,在其上应用 Jet 颜色图并显示结果:
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
#include <iostream>
using namespace std;
int main(int argc, const char *argv[])
{
// We need an input image. (can be grayscale or color)
if (argc < 2)
{
cerr << "We need an image to process here. Please run: colorMap [path_to_image]" << endl;
return -1;
}
Mat img_in = imread(argv[1]);
if(img_in.empty())
{
cerr << "Sample image (" << argv[1] << ") is empty. Please adjust your path, so it points to a valid input image!" << endl;
return -1;
}
// Holds the colormap version of the image:
Mat