js css html

C#:Opencv自带颜色表操作

2022-09-15  本文已影响0人  大龙10

《学习OpenCV(中文版)》

作者:(美)布拉德斯基(Bradski,G.)
(美)克勒(Kaehler,A.) 著
出版社:清华大学出版社
出版时间:2009年10月

参考资料:https://blog.csdn.net/hy_z_/article/details/103681088
https://blog.csdn.net/CAI____NIAO/article/details/120734191

一、Cv2.ImRead报错

二、Opencv自带颜色表操作

namespace CvSharpDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            ColormapTypes[] color_map = new ColormapTypes[Enum.GetValues(typeof(ColormapTypes)).Length];

            int index = 0;
            foreach (ColormapTypes temp in Enum.GetValues(typeof(ColormapTypes)))
            {
                color_map[index] = temp;
                index++;
            }
            index = 0;
            Mat src = Cv2.ImRead(@"e:\opencv\bgra.png", ImreadModes.AnyColor);
            Cv2.ImShow("src image", src);
            int key;
            Cv2.NamedWindow("output image", WindowFlags.AutoSize);
            Mat output_image = new Mat(src.Size(), src.Type());
            while (true)
            {
                key = Cv2.WaitKey(500);
                if (key == 27) break;//跳出while循环
                Cv2.ApplyColorMap(src, output_image, color_map[index % color_map.Length]);
                index++;
                if (index >= color_map.Length) index = 0;
                Cv2.ImShow("outputimage", output_image);

            }
            Cv2.DestroyAllWindows();
        }
}

三、运行结果

上一篇 下一篇

猜你喜欢

热点阅读