一个分支小任务,讲一讲ColorMap的使用。插件提供了13种固定的渐变色卡,Imgproc.applyColorMap(Mat src, Mat dst, int colormap) 的第三个参数取值范围只能是0-12。如果要使用自定义的色卡,需要使用Core.LUT(Mat src, Mat lut, Mat dst)函数。
* public const int COLORMAP_AUTUMN = 0;
* public const int COLORMAP_BONE = 1;
* public const int COLORMAP_JET = 2;
* public const int COLORMAP_WINTER = 3;
* public const int COLORMAP_RAINBOW = 4;
* public const int COLORMAP_OCEAN = 5;
* public const int COLORMAP_SUMMER = 6;
* public const int COLORMAP_SPRING = 7;
* public const int COLORMAP_COOL = 8;
* public const int COLORMAP_HSV = 9;
* public const int COLORMAP_PINK = 10;
* public const int COLORMAP_HOT = 11;
* public const int COLORMAP_PARULA = 12;
代码
void Start()
{
Mat srcMat = Imgcodecs.imread(Application.dataPath + "/Textures/sample.jpg");
Imgproc.cvtColor(srcMat, srcMat, Imgproc.COLOR_BGR2RGB);
//基础色度图
for (int i = 0; i < 13; i++)
{
Mat dstMat = new Mat();
//Imgproc.applyColorMap(srcMat, dstMat, Imgproc.COLORMAP_JET);
Imgproc.applyColorMap(srcMat, dstMat, i);
Texture2D t2d = new Texture2D(dstMat.width(), dstMat.height());
Sprite sp = Sprite.Create(t2d, new UnityEngine.Rect(0, 0, t2d.width, t2d.height), Vector2.zero);
m_imageList[i].sprite = sp;
m_imageList[i].preserveAspect = true;
Utils.matToTexture2D(dstMat, t2d);
}
}