搜索
bottom↓
回复: 32

求助:求WS2812彩灯灯光效果算法或者软件

[复制链接]

出0入55汤圆

发表于 2018-9-15 22:03:08 | 显示全部楼层 |阅读模式
因项目用到WS2812彩灯,编灯光效果的时候发现很麻烦,而且用的数组(如下),很占空间(虽然空间足够),但如果增加减少效果很费劲。所以求助万能的坛子,有没有好用的一些算法或者软件编辑效果的。
另外,项目上的界面是这样的自定义效果,基于什么算法,一直搞不明白,比如那个混合颜色是什么鬼?

  1. /*********************************** 外圈花样定义 *************************************/
  2. const uint8_t rgbO_Mono[][3] =        //r
  3.                                                                 {{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  4.                                                                 ,{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  5.                                                                 ,{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  6.                                                                 ,{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  7.                                                                 //r
  8.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00}
  9.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00}
  10.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00}
  11.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00}
  12.                                                                 //g
  13.                                                                 ,{0x00,0xff,0x00},{0x00,0x00,0x00},{0x00,0xff,0x00},{0x00,0x00,0x00}
  14.                                                                 ,{0x00,0xff,0x00},{0x00,0x00,0x00},{0x00,0xff,0x00},{0x00,0x00,0x00}
  15.                                                                 ,{0x00,0xff,0x00},{0x00,0x00,0x00},{0x00,0xff,0x00},{0x00,0x00,0x00}
  16.                                                                 ,{0x00,0xff,0x00},{0x00,0x00,0x00},{0x00,0xff,0x00},{0x00,0x00,0x00}
  17.                                                                 //g
  18.                                                                 ,{0x00,0x00,0x00},{0x00,0xff,0x00},{0x00,0x00,0x00},{0x00,0xff,0x00}
  19.                                                                 ,{0x00,0x00,0x00},{0x00,0xff,0x00},{0x00,0x00,0x00},{0x00,0xff,0x00}
  20.                                                                 ,{0x00,0x00,0x00},{0x00,0xff,0x00},{0x00,0x00,0x00},{0x00,0xff,0x00}
  21.                                                                 ,{0x00,0x00,0x00},{0x00,0xff,0x00},{0x00,0x00,0x00},{0x00,0xff,0x00}       
  22.                                                                 //b
  23.                                                                 ,{0x00,0x00,0xff},{0x00,0x00,0x00},{0x00,0x00,0xff},{0x00,0x00,0x00}
  24.                                                                 ,{0x00,0x00,0xff},{0x00,0x00,0x00},{0x00,0x00,0xff},{0x00,0x00,0x00}
  25.                                                                 ,{0x00,0x00,0xff},{0x00,0x00,0x00},{0x00,0x00,0xff},{0x00,0x00,0x00}
  26.                                                                 ,{0x00,0x00,0xff},{0x00,0x00,0x00},{0x00,0x00,0xff},{0x00,0x00,0x00}       
  27.                                                                 //b
  28.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0xff},{0x00,0x00,0x00},{0x00,0x00,0xff}
  29.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0xff},{0x00,0x00,0x00},{0x00,0x00,0xff}
  30.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0xff},{0x00,0x00,0x00},{0x00,0x00,0xff}
  31.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0xff},{0x00,0x00,0x00},{0x00,0x00,0xff}                                                               
  32.                                                                 };
  33.                                                                
  34. const uint8_t rgbO_Move[][3] =        //r6
  35.                                                                 {{0xff,0x00,0x00},{0xf0,0x00,0x00},{0xe1,0x00,0x00},{0xd2,0x00,0x00}
  36.                                                                 ,{0xc3,0x00,0x00},{0xb4,0x00,0x00},{0xa5,0x00,0x00},{0x96,0x00,0x00}
  37.                                                                 ,{0x87,0x00,0x00},{0x78,0x00,0x00},{0x69,0x00,0x00},{0x5a,0x00,0x00}
  38.                                                                 ,{0x4b,0x00,0x00},{0x3c,0x00,0x00},{0x2d,0x00,0x00},{0x1e,0x00,0x00}
  39.                                                                
  40.                                                                 ,{0x00,0xff,0x00},{0x00,0xf0,0x00},{0x00,0xe1,0x00},{0x00,0xd2,0x00}
  41.                                                                 ,{0x00,0xc3,0x00},{0x00,0xb4,0x00},{0x00,0xa5,0x00},{0x00,0x96,0x00}
  42.                                                                 ,{0x00,0x87,0x00},{0x00,0x78,0x00},{0x00,0x69,0x00},{0x00,0x5a,0x00}
  43.                                                                 ,{0x00,0x4b,0x00},{0x00,0x3c,0x00},{0x00,0x2d,0x00},{0x00,0x1e,0x00}
  44.                                                                
  45.                                                                 ,{0x00,0x00,0xff},{0x00,0x00,0xf0},{0x00,0x00,0xe1},{0x00,0x00,0xd2}
  46.                                                                 ,{0x00,0x00,0xc3},{0x00,0x00,0xb4},{0x00,0x00,0xa5},{0x00,0x00,0x96}
  47.                                                                 ,{0x00,0x00,0x87},{0x00,0x00,0x78},{0x00,0x00,0x69},{0x00,0x00,0x5a}
  48.                                                                 ,{0x00,0x00,0x4b},{0x00,0x00,0x3c},{0x00,0x00,0x2d},{0x00,0x00,0x1e}
  49.                                                                 };
  50.        
  51. /*********************************** 中间花样定义 *************************************/
  52. //数字0~9
  53. const uint8_t rgbM_Num[][3] =        //0
  54.                                                                 {{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  55.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  56.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  57.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  58.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  59.                                                                         //1
  60.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  61.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  62.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  63.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  64.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  65.                                                                         //2
  66.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  67.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  68.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  69.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  70.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  71.                                                                         //3
  72.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  73.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  74.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  75.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  76.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  77.                                                                         //4
  78.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  79.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  80.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  81.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  82.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  83.                                                                         //5
  84.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  85.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  86.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  87.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  88.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  89.                                                                         //6
  90.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  91.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  92.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  93.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  94.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  95.                                                                         //7
  96.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  97.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  98.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  99.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  100.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  101.                                                                         //8
  102.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  103.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  104.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  105.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  106.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  107.                                                                         //9
  108.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  109.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  110.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  111.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  112.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  113.                                                                 };

  114. const uint8_t rgbM_Pattern1[][3] =        //花样1   内向外扩散
  115.                                                                 {{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  116.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  117.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x55,0x55,0x55},{0x00,0x00,0x00},{0x00,0x00,0x00}
  118.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  119.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  120.                                                                 //
  121.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  122.                                                                 ,{0x00,0x00,0x00},{0x55,0x55,0x55},{0x55,0x55,0x55},{0x55,0x55,0x55},{0x00,0x00,0x00}
  123.                                                                 ,{0x00,0x00,0x00},{0x55,0x55,0x55},{0x00,0x00,0x00},{0x55,0x55,0x55},{0x00,0x00,0x00}
  124.                                                                 ,{0x00,0x00,0x00},{0x55,0x55,0x55},{0x55,0x55,0x55},{0x55,0x55,0x55},{0x00,0x00,0x00}
  125.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  126.                                                                         //
  127.                                                                 ,{0x55,0x55,0x55},{0x55,0x55,0x55},{0x55,0x55,0x55},{0x55,0x55,0x55},{0x55,0x55,0x55}
  128.                                                                 ,{0x55,0x55,0x55},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x55,0x55,0x55}
  129.                                                                 ,{0x55,0x55,0x55},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x55,0x55,0x55}
  130.                                                                 ,{0x55,0x55,0x55},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x55,0x55,0x55}
  131.                                                                 ,{0x55,0x55,0x55},{0x55,0x55,0x55},{0x55,0x55,0x55},{0x55,0x55,0x55},{0x55,0x55,0x55}
  132.                                                                         //r
  133.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  134.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  135.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  136.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  137.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  138.                                                                         //r
  139.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  140.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  141.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  142.                                                                 ,{0x00,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0x00,0x00,0x00}
  143.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  144.                                                                         //r
  145.                                                                 ,{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00}
  146.                                                                 ,{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00}
  147.                                                                 ,{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00}
  148.                                                                 ,{0xff,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0xff,0x00,0x00}
  149.                                                                 ,{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00},{0xff,0x00,0x00}
  150.                                                                         //g
  151.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  152.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  153.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0xff,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  154.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  155.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  156.                                                                         //g
  157.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  158.                                                                 ,{0x00,0x00,0x00},{0x00,0xff,0x00},{0x00,0xff,0x00},{0x00,0xff,0x00},{0x00,0x00,0x00}
  159.                                                                 ,{0x00,0x00,0x00},{0x00,0xff,0x00},{0x00,0x00,0x00},{0x00,0xff,0x00},{0x00,0x00,0x00}
  160.                                                                 ,{0x00,0x00,0x00},{0x00,0xff,0x00},{0x00,0xff,0x00},{0x00,0xff,0x00},{0x00,0x00,0x00}
  161.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  162.                                                                         //g
  163.                                                                 ,{0x00,0xff,0x00},{0x00,0xff,0x00},{0x00,0xff,0x00},{0x00,0xff,0x00},{0x00,0xff,0x00}
  164.                                                                 ,{0x00,0xff,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0xff,0x00}
  165.                                                                 ,{0x00,0xff,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0xff,0x00}
  166.                                                                 ,{0x00,0xff,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0xff,0x00}
  167.                                                                 ,{0x00,0xff,0x00},{0x00,0xff,0x00},{0x00,0xff,0x00},{0x00,0xff,0x00},{0x00,0xff,0x00}
  168.                                                                         //b
  169.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  170.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  171.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0xff},{0x00,0x00,0x00},{0x00,0x00,0x00}
  172.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  173.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  174.                                                                         //b
  175.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  176.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0xff},{0x00,0x00,0xff},{0x00,0x00,0xff},{0x00,0x00,0x00}
  177.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0xff},{0x00,0x00,0x00},{0x00,0x00,0xff},{0x00,0x00,0x00}
  178.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0xff},{0x00,0x00,0xff},{0x00,0x00,0xff},{0x00,0x00,0x00}
  179.                                                                 ,{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00}
  180.                                                                         //b
  181.                                                                 ,{0x00,0x00,0xff},{0x00,0x00,0xff},{0x00,0x00,0xff},{0x00,0x00,0xff},{0x00,0x00,0xff}
  182.                                                                 ,{0x00,0x00,0xff},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0xff}
  183.                                                                 ,{0x00,0x00,0xff},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0xff}
  184.                                                                 ,{0x00,0x00,0xff},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0x00},{0x00,0x00,0xff}
  185.                                                                 ,{0x00,0x00,0xff},{0x00,0x00,0xff},{0x00,0x00,0xff},{0x00,0x00,0xff},{0x00,0x00,0xff}
  186.                                                                 };
  187.                                                                
  188. /************************** 底层初始化 ******************************************/
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入4汤圆

发表于 2018-9-15 22:09:51 | 显示全部楼层
见过最牛逼的用stm8f003带1024个灯珠,可以做很多花样和速度的

出0入55汤圆

 楼主| 发表于 2018-9-15 22:11:43 | 显示全部楼层
bbandpp 发表于 2018-9-15 22:09
见过最牛逼的用stm8f003带1024个灯珠,可以做很多花样和速度的

我现在用的是STM32F103RET6,定时器PWM+DMA驱动,
空间什么的够用,差在效果的算法。。。搞了好久了。。

出0入0汤圆

发表于 2018-9-15 22:18:33 | 显示全部楼层
jssd 发表于 2018-9-15 22:11
我现在用的是STM32F103RET6,定时器PWM+DMA驱动,
空间什么的够用,差在效果的算法。。。搞了好久了。。 ...

搞个Python脚本生成吧,或者搞个图形工具来生成。因为效果太多了,估计没有现成的简单工具帮你

BWT,你们要什么效果?

出0入4汤圆

发表于 2018-9-15 22:19:41 | 显示全部楼层
jssd 发表于 2018-9-15 22:11
我现在用的是STM32F103RET6,定时器PWM+DMA驱动,
空间什么的够用,差在效果的算法。。。搞了好久了。。 ...

这个核心就是在内置的效果上

出0入55汤圆

 楼主| 发表于 2018-9-15 22:22:59 | 显示全部楼层
nanfang2000 发表于 2018-9-15 22:18
搞个Python脚本生成吧,或者搞个图形工具来生成。因为效果太多了,估计没有现成的简单工具帮你

BWT,你 ...

就是一般机台比较炫的效果,比如渐变,闪,转,七彩。。。之类的。。。。
这些我的想法是用固定的数组编好,然后读。。。
但好像匹配不上楼主位的那个界面,主要是混合色不知道怎样处理。。。难道定义另一个数组叠加上去?

出0入4汤圆

发表于 2018-9-15 22:24:41 | 显示全部楼层
混色是背景色的含义吧,估计只能加数组了

出0入55汤圆

 楼主| 发表于 2018-9-15 22:24:58 | 显示全部楼层
bbandpp 发表于 2018-9-15 22:19
这个核心就是在内置的效果上

确实,看别人几百几千种效果,也不知是怎样弄出来的?难不成一个一个数组慢慢弄?想想觉得有点可怕。。。

出0入4汤圆

发表于 2018-9-15 22:34:29 | 显示全部楼层
jssd 发表于 2018-9-15 22:24
确实,看别人几百几千种效果,也不知是怎样弄出来的?难不成一个一个数组慢慢弄?想想觉得有点可怕。。。 ...

这种内推的,应该不会有这么多模式的,一般也就5,6种模式就够了

出0入90汤圆

发表于 2018-9-15 22:41:01 | 显示全部楼层
arduino的这个库不错
https://github.com/kitesurfer1404/WS2812FX

出0入0汤圆

发表于 2018-9-15 22:59:39 | 显示全部楼层
jssd 发表于 2018-9-15 22:24
确实,看别人几百几千种效果,也不知是怎样弄出来的?难不成一个一个数组慢慢弄?想想觉得有点可怕。。。 ...

换个思路,把灯条看成屏幕,放电影
做成动画编辑那种专业软件,一帧一帧的,想怎么搞都行。就是比较耗存储。
有人给过我一个灯光效果的播放文件,几百MB,打开看其实就是一帧一帧的数据。。。

出0入55汤圆

 楼主| 发表于 2018-9-15 23:27:47 | 显示全部楼层
aammoo 发表于 2018-9-15 22:41
arduino的这个库不错
https://github.com/kitesurfer1404/WS2812FX

看起来不错,可是看不懂。。。惭愧了。。

出0入55汤圆

 楼主| 发表于 2018-9-15 23:34:27 | 显示全部楼层
nanfang2000 发表于 2018-9-15 22:59
换个思路,把灯条看成屏幕,放电影
做成动画编辑那种专业软件,一帧一帧的,想怎么搞都行。就是比较耗存 ...

我也是倾向这种,准备写一个小软件,从上到下读一张张彩色图片像素RGB值,存成数组,刷屏时就按这个一帧帧刷,模式搞几种,比如静态,移动,闪烁(也可以看成速度很慢的移动),渐变。。。
只是这样搞,楼主位的混合色不知道怎样搞。。。

出0入0汤圆

发表于 2018-9-15 23:38:12 来自手机 | 显示全部楼层
jssd 发表于 2018-9-15 23:34
我也是倾向这种,准备写一个小软件,从上到下读一张张彩色图片像素RGB值,存成数组,刷屏时就按这个一帧 ...

不太明白楼主位这个图什么意思,混合色什么意思。。难道意思不是纯色?

出0入55汤圆

 楼主| 发表于 2018-9-16 09:58:39 | 显示全部楼层
nanfang2000 发表于 2018-9-15 23:38
不太明白楼主位这个图什么意思,混合色什么意思。。难道意思不是纯色? ...

我也不知道,现在我把基本色当底色,然后叠加上混合色。也就是两组数组了。。。

出0入0汤圆

发表于 2018-9-16 10:59:22 | 显示全部楼层
渐变色用HSL做算法再转回RGB显示啊!  

出0入0汤圆

发表于 2018-9-16 16:31:24 来自手机 | 显示全部楼层
有个来源的库忘了叫什么了可以实现很多效果

出0入0汤圆

发表于 2018-9-16 16:31:48 来自手机 | 显示全部楼层
用的是spi+dma驱动

出0入0汤圆

发表于 2018-9-16 20:26:38 | 显示全部楼层
jssd 发表于 2018-9-15 22:11
我现在用的是STM32F103RET6,定时器PWM+DMA驱动,
空间什么的够用,差在效果的算法。。。搞了好久了。。 ...

SPI+DMA可以很高效的驱动,spi速度设置为合适的频率,1bit变成3bit就可以。

出0入55汤圆

 楼主| 发表于 2018-9-16 20:34:37 | 显示全部楼层
kakarotto 发表于 2018-9-16 20:26
SPI+DMA可以很高效的驱动,spi速度设置为合适的频率,1bit变成3bit就可以。

sip也弄过,确实是可以,只是有一个我不是很满意,多了几个没用的IO脚,pwm只要一个io就行

出0入55汤圆

 楼主| 发表于 2018-9-16 20:35:16 | 显示全部楼层
Pupil 发表于 2018-9-16 16:31
有个来源的库忘了叫什么了可以实现很多效果

是楼上那个吗?

出0入0汤圆

发表于 2018-9-18 13:36:00 | 显示全部楼层
jssd 发表于 2018-9-16 20:35
是楼上那个吗?

你查下fastled,github上的,好像还见过几个,一时找不到
头像被屏蔽

出0入0汤圆

发表于 2018-9-21 09:01:39 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

出0入0汤圆

发表于 2018-9-26 14:18:18 | 显示全部楼层
这个问题好,也想知道需要怎么做。

出0入4汤圆

发表于 2018-9-28 10:14:30 | 显示全部楼层
WS2812FX 有54种样式,支持分段,速度调节,色彩设置,建议用arduino看看效果先。移植到F030上面,空间爆了。

出0入0汤圆

发表于 2018-10-12 13:50:12 | 显示全部楼层
为啥的我置低刷新要300US才行?

出0入4汤圆

发表于 2018-10-12 13:52:43 | 显示全部楼层
gmyu 发表于 2018-9-28 10:14
WS2812FX 有54种样式,支持分段,速度调节,色彩设置,建议用arduino看看效果先。移植到F030上面,空间爆了 ...

WS2812FX ?这是个什么东东?有开源的吗?

出0入4汤圆

发表于 2018-10-12 13:54:02 | 显示全部楼层
我见过最NB的是用STM8实现,分段,变色,流星这些效果

出0入0汤圆

发表于 2018-10-21 15:55:37 来自手机 | 显示全部楼层
用SD卡读,然后直接发,行不行?

出0入0汤圆

发表于 2018-10-21 15:55:55 来自手机 | 显示全部楼层
效果就用软件做

出0入4汤圆

发表于 2018-11-12 11:22:34 | 显示全部楼层
楼主,最后效果做出来了吗

出0入55汤圆

 楼主| 发表于 2018-11-12 16:39:44 | 显示全部楼层
本帖最后由 jssd 于 2018-11-12 16:47 编辑
bbandpp 发表于 2018-11-12 11:22
楼主,最后效果做出来了吗


没有按图的做了。写了个小软件,把所有的数据都做成数组,然后直接用了。这样的后果是code变成了300+K。。。

看下面

生成图片和数组的小软件,使用opencv2413
  1. /***********************************************************************
  2. * OpenCV 2.3.1 example
  3. * By Quarryman 2012
  4. ***********************************************************************/
  5. #include <stdio.h>
  6. #include "stdlib.h"
  7. #include <tchar.h>
  8. #include <Windows.h>
  9. #include <fstream>
  10. #include <iostream>
  11. #include <string>
  12. #include<iomanip>
  13. #include <opencv2\opencv.hpp>
  14. #include<shlwapi.h>


  15. using namespace cv;
  16. using namespace std;
  17. //
  18. //
  19. //ofstream outfile("ws2812Dat.c", ios::trunc);
  20. //
  21. //const int LEDNUM = 100;
  22. //
  23. //void get_setImagePixel(string imagePath)
  24. //{
  25. //        /********** 截取名称字符串 *******************/
  26. //        int dex = imagePath.find_last_of('\\');
  27. //        cout << dex << endl;
  28. //        string name = imagePath.substr(dex+1);
  29. //        cout << name << endl;
  30. //        dex = name.find('.');
  31. //        name = name.substr(0,dex);
  32. //        cout << name << endl;
  33. //
  34. ////  Mat image = imread(imagePath , 0);
  35. //    Mat image = imread(imagePath, 1);
  36. //    //得宽高
  37. //    int w = image.cols;
  38. //    int h = image.rows;
  39. //        int stepw = w/LEDNUM;
  40. //        int i,j;
  41. //    int channels = image.channels();
  42. //        //灰度图,像素为单通道
  43. //        if (channels == 1)
  44. //        {
  45. ////            int pixel = image.at<uchar>(x, y);
  46. ////            cout << "灰度图像,处的灰度值为" << pixel << endl;
  47. //        }
  48. //        else
  49. //        {
  50. //            //通过实验,彩色图像的默认存储是bgr, 且存储的格式如下
  51. //                        outfile << "const unsigned char " << name <<"[][3]" << " = {"  <<endl;
  52. //
  53. //                        for(j=0;j<h;j+=stepw)
  54. //                        {
  55. //                                outfile << "        ";
  56. //                                for(i=0;i<w;i+=stepw)
  57. //                                {
  58. //                                        int b = image.at<Vec3b>(j, i)[0]; // b = image.at<uchar>(x,y*3);
  59. //                                        int g = image.at<Vec3b>(j, i)[1]; //g = image.at<uchar>(x, y * 3 + 1);
  60. //                                        int r = image.at<Vec3b>(j, i)[2]; //r = image.at<uchar>(x, y * 3 + 1);
  61. //                                        image.at<Vec3b>(j, i)[0] = 255;
  62. //                                        image.at<Vec3b>(j, i)[1] = 255;
  63. //                                        image.at<Vec3b>(j, i)[2] = 255;
  64. //                                        outfile << "{0x" << setw(2)<< setfill('0') << hex << r << ",0x" << setw(2)<<setfill('0') << hex  << g << ",0x" << setw(2)<< setfill('0') << hex  << b << "},";
  65. //                                }
  66. //                                outfile << endl;
  67. //                        }
  68. //                        outfile << "        };"  <<endl;
  69. //         }
  70. //
  71. //    imshow("cc", image);
  72. //        outfile.close();
  73. //}
  74. //
  75. //string TCHAR2STRING(TCHAR* str)
  76. //{
  77. //        std::string strstr;
  78. //        try
  79. //        {
  80. //                int iLen = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
  81. //
  82. //                char* chRtn = new char[iLen * sizeof(char)];
  83. //
  84. //                WideCharToMultiByte(CP_ACP, 0, str, -1, chRtn, iLen, NULL, NULL);
  85. //
  86. //                strstr = chRtn;
  87. //        }
  88. //        catch (std::exception e)
  89. //        {
  90. //        }
  91. //
  92. //        return strstr;
  93. //}
  94. //
  95. //int main()
  96. //{
  97. //////        int x=::MessageBox(NULL, TEXT("将在20秒后关机,确定执行吗?"), TEXT("操作提示"), 1);
  98. ////        TCHAR szBuffer[MAX_PATH] = {0};
  99. ////        OPENFILENAME file = {0};
  100. ////        file.hwndOwner = NULL;
  101. ////        file.lStructSize = sizeof(file);
  102. ////        file.lpstrFilter = _T("jpg文件(*.jpg)\0*.jpg\0所有文件(*.*)\0*.*\0");//要选择的文件后缀
  103. //////        file.lpstrInitialDir = _T("C:\");//默认的文件路径
  104. ////        file.lpstrFile = szBuffer;//存放文件的缓冲区
  105. ////        file.nMaxFile = sizeof(szBuffer) / sizeof(*szBuffer);
  106. ////        file.nFilterIndex = 0;
  107. ////        file.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER ;//标志如果是多选要加上OFN_ALLOWMULTISELECT
  108. ////        BOOL bSel = GetOpenFileName(&file);
  109. //////        cout << file.lpstrFile << endl;
  110. //////        cout << szBuffer << endl;
  111. ////        string imagename = TCHAR2STRING(szBuffer);
  112. ////        cout << imagename << endl;
  113. ////
  114. //////        string imagename = "eeee.jpg";   //此处需要填写绝对地址,我测试时使用相对地址出错。
  115. ////        get_setImagePixel(imagename);
  116. //
  117. //        //读入图像
  118. //        //Mat img = imread(imagename);
  119. // //
  120. //        ////如果读入图像失败
  121. //        //if(img.empty())
  122. //        //{
  123. //        //        return -1;
  124. //        //}
  125. // //
  126. //        ////创建窗口
  127. //        //namedWindow("image",1);
  128. // //
  129. //        ////显示图像
  130. //        //imshow("image", img);
  131. //
  132. //        //等待按键,按键盘任意键返回
  133. //        waitKey();
  134. //
  135. //        return 0;
  136. //
  137. //       //错误指出: feihongmeilian
  138. //       //经本人验证,string imagename = "lena.jpg";  处是可以使用相对地址,本人使用环境为OpenCV 2.4.3
  139. //       //图片为meinv.jpg置于代码文件所在文件夹的上一级文件夹中,string imagename = "..\\meinv.jpg"  图片可正常显示。
  140. //      //需提醒注意的是 双引号“” 中出现的第一个 斜杠 \ 被视作转义字符
  141. //}


  142. //#include <opencv2/opencv.hpp>
  143. //#include<opencv2/imgproc/imgproc.hpp>
  144. //#include<iostream>

  145. //using namespace std;
  146. //using namespace cv;
  147. //

  148. //int main()
  149. //{
  150. //        Mat img;
  151. //        img = imread("pic180x509.bmp");
  152. //        for (int i = 0; i < 3; i++)
  153. //        {
  154. //                Mat bgr(img.rows, img.cols, CV_8UC3, Scalar(0, 0, 0));
  155. //                Mat temp(img.rows, img.cols, CV_8UC1);
  156. //                Mat out[] = { bgr };
  157. //                int from_to[] = { i,i };
  158. //                mixChannels(&img, 1, out, 1, from_to,1);
  159. //                //获得其中一个通道的数据进行分析
  160. //                imshow("1 channel", bgr);
  161. //                waitKey();
  162. //        }
  163. //}
  164. //
  165. //int main()  
  166. //{  
  167. //    //载入图像  
  168. //    IplImage* img=cvLoadImage("pic180x509.bmp",1);  
  169. //    //cvCreateImage(size,depth,channels)函数,depth 图像元素的位深度,IPL_DEPTH_8U 表示无符号8位整型  
  170. //    IplImage* Bimg=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);//1为有1个通道  
  171. //    IplImage* Gimg=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);  
  172. //    IplImage* Rimg=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);  
  173. //  
  174. //    IplImage* pImg1=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);//3为有3个通道  
  175. //    IplImage* pImg2=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);  
  176. //    IplImage* pImg3=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);  
  177. //    //将RGB图像分离  
  178. //    //cvSplit( const CvArr* src,CvArr* dst0,CvArr* dst1,CvArr* dst2,CvArr* dst3 )函数  
  179. //    //复制src的各个通道到图像dst0,dst1,dst2和dst3中  
  180. //    cvSplit(img,Bimg,Gimg,Rimg,0);  
  181. //    //目标图像必须与源图像在大小和数据类型上匹配  
  182. //    //输入多通道,输出为B,G,R单通道  
  183. //  
  184. //    //在合成之前需要清零  
  185. //    cvSetZero(pImg1);  
  186. //    cvSetZero(pImg2);  
  187. //    cvSetZero(pImg3);  
  188. //    //将三个通道合成  
  189. //    //输入参数为B,G,R单通道,最后一个为输出  
  190. //    //cvMerge( const CvArr* src0, const CvArr* src1,const CvArr* src2, const CvArr* src3,CvArr* dst );  
  191. //    cvMerge(Bimg,0,0,0,pImg3);  
  192. //    cvMerge(0,Gimg,0,0,pImg2);  
  193. //    cvMerge(0,0,Rimg,0,pImg1);  
  194. //      
  195. //    cvNamedWindow("RGB",1);  
  196. //    cvShowImage("RGB",img);  
  197. //  
  198. //    cvNamedWindow("R",1);  
  199. //    cvShowImage("R",pImg1);  
  200. //  
  201. //    cvNamedWindow("G",1);  
  202. //    cvShowImage("G",pImg2);  
  203. //  
  204. //    cvNamedWindow("B",1);  
  205. //    cvShowImage("B",pImg3);  
  206. //  
  207. //    //HSV图像处理  
  208. //    IplImage* hsv=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);  
  209. //  
  210. //    //将RGB图像转为HSV图像的函数  
  211. //    cvCvtColor(img,hsv,CV_BGR2HSV);  
  212. //  
  213. //    IplImage* Himg=cvCreateImage(cvGetSize(hsv),IPL_DEPTH_8U,1);  
  214. //    IplImage* Simg=cvCreateImage(cvGetSize(hsv),IPL_DEPTH_8U,1);  
  215. //    IplImage* Vimg=cvCreateImage(cvGetSize(hsv),IPL_DEPTH_8U,1);  
  216. //  
  217. //    IplImage* HSV1=cvCreateImage(cvGetSize(hsv),IPL_DEPTH_8U,3);//3个通道  
  218. //    IplImage* HSV2=cvCreateImage(cvGetSize(hsv),IPL_DEPTH_8U,3);  
  219. //    IplImage* HSV3=cvCreateImage(cvGetSize(hsv),IPL_DEPTH_8U,3);  
  220. //    //用法同上  
  221. //    cvSplit(hsv,Vimg,Simg,Himg,0);  
  222. //  
  223. //    cvNamedWindow("V",1);  
  224. //    cvShowImage("V",Vimg);  
  225. //  
  226. //    cvNamedWindow("S",1);  
  227. //    cvShowImage("S",Simg);  
  228. //  
  229. //    cvNamedWindow("H",1);  
  230. //    cvShowImage("H",Himg);  
  231. //  
  232. //    cvNamedWindow("HSV",1);  
  233. //    cvShowImage("HSV",hsv);  
  234. //  
  235. //    cvWaitKey(0);  
  236. //    //RGB RELEASE  
  237. //    cvReleaseImage(&img);  
  238. //    cvReleaseImage(&Rimg);  
  239. //    cvReleaseImage(&Gimg);  
  240. //    cvReleaseImage(&Bimg);  
  241. //  
  242. //    cvReleaseImage(&pImg1);  
  243. //    cvReleaseImage(&pImg2);  
  244. //    cvReleaseImage(&pImg3);  
  245. //    //HSV RELEASE  
  246. //    cvReleaseImage(&hsv);  
  247. //    cvReleaseImage(&Himg);  
  248. //    cvReleaseImage(&Simg);  
  249. //    cvReleaseImage(&Vimg);  
  250. //  
  251. //    cvReleaseImage(&HSV1);  
  252. //    cvReleaseImage(&HSV2);  
  253. //    cvReleaseImage(&HSV3);  
  254. //  
  255. //    return 0;  
  256. //}  


  257. struct BGR
  258. {
  259.     uchar b;
  260.     uchar g;
  261.     uchar r;
  262. };

  263. struct HSV
  264. {
  265.     int h;
  266.     double s;
  267.     double v;
  268. };

  269. bool IsEquals(double val1 , double val2)
  270. {
  271.     return fabs(val1 - val2) < 0.001;
  272. }

  273. // BGR(BGR: 0~255)转HSV(H: [0~360), S: [0~1], V: [0~1])
  274. void BGR2HSV(BGR &bgr, HSV &hsv)
  275. {
  276.     double b, g, r;
  277.     double h, s, v;
  278.     double min, max;
  279.     double delta;

  280.     b = bgr.b / 255.0;
  281.     g = bgr.g / 255.0;
  282.     r = bgr.r / 255.0;

  283.     if (r > g)
  284.     {
  285.          max = MAX(r, b);
  286.          min = MIN(g, b);
  287.     }
  288.     else
  289.     {
  290.          max = MAX(g, b);
  291.          min = MIN(r, b);
  292.     }

  293.     v = max;
  294.     delta = max - min;

  295.     if (IsEquals(max, 0))
  296.     {
  297.          s = 0.0;
  298.     }
  299.     else
  300.     {
  301.          s = delta / max;
  302.     }

  303.     if (max == min)
  304.     {
  305.          h = 0.0;
  306.     }
  307.     else
  308.     {
  309.          if (IsEquals(r, max) && g >= b)
  310.          {
  311.               h = 60 * (g - b) / delta + 0;
  312.          }
  313.          else if (IsEquals(r, max) && g < b)
  314.          {
  315.               h = 60 * (g - b) / delta + 360;
  316.          }
  317.          else if (IsEquals(g, max))
  318.          {
  319.               h = 60 * (b - r) / delta + 120;
  320.          }
  321.          else if (IsEquals(b, max))
  322.          {
  323.               h = 60 * (r - g) / delta + 240;
  324.          }
  325.     }

  326.     hsv.h = (int)(h + 0.5);
  327.     hsv.h = (hsv.h > 359) ? (hsv.h - 360) : hsv.h;
  328.     hsv.h = (hsv.h < 0) ? (hsv. h + 360) : hsv.h;
  329.     hsv.s = s;
  330.     hsv.v = v;
  331. }

  332. // HSV转BGR
  333. void HSV2BGR(HSV &hsv, BGR &bgr)
  334. {
  335.     int h = hsv.h;
  336.     double s = hsv. s;
  337.     double v = hsv. v;
  338.     double b = 0.0;
  339.     double g = 0.0;
  340.     double r = 0.0;

  341.     int flag = (int)abs(h / 60.0);
  342.     double f = h/60.0 - flag;
  343.     double p = v * (1 - s);
  344.     double q = v * (1 - f*s);
  345.     double t = v * (1 - (1- f)*s);

  346.     switch (flag)
  347.     {
  348.     case 0:
  349.          b = p;
  350.          g = t;
  351.          r = v;
  352.          break;
  353.     case 1:
  354.          b = p;
  355.          g = v;
  356.          r = q;
  357.          break;
  358.     case 2:
  359.          b = t;
  360.          g = v;
  361.          r = p;
  362.          break;
  363.     case 3:
  364.          b = v;
  365.          g = q;
  366.          r = p;
  367.          break;
  368.     case 4:
  369.          b = v;
  370.          g = p;
  371.          r = t;
  372.          break;
  373.     case 5:
  374.          b = q;
  375.          g = p;
  376.          r = v;
  377.          break;
  378.     default:
  379.          break;
  380.     }

  381.     int blue = int(b * 255);
  382.     bgr.b = (blue > 255) ? 255 : blue;
  383.     bgr.b = (blue < 0) ? 0 : bgr.b;

  384.     int green = int(g * 255);
  385.     bgr.g = (green > 255) ? 255 : green;
  386.     bgr.g = (green < 0) ? 0 : bgr.g;

  387.     int red = int(r * 255);
  388.     bgr.r = (red > 255) ? 255 : red;
  389.     bgr.r = (red < 0) ? 0 : bgr.r;
  390. }

  391. ofstream outfile("data.c", ios::trunc);

  392. int main()
  393. {
  394.     string imgName = "pic360x201.bmp";
  395.     Mat img = cv::imread(imgName);
  396.     Mat tmp = img.clone();

  397.     if (img.data == NULL)
  398.     {
  399.          cout<< "Could not open or find the image"<<endl;
  400.          return -1;
  401.     }
  402.         outfile << "const unsigned char " << "monoBW" <<"[][3]" << " = {" << " /*256*1*/" <<endl;
  403.         for(int i=0;i<256;i++)
  404.         {
  405.                 outfile << "{0x" << setw(2)<< setfill('0') << hex << i << ",0x" << setw(2)<<setfill('0') << hex  << i << ",0x" << setw(2)<< setfill('0') << hex  << i << "},";
  406.         }
  407.         outfile << " };"  <<endl;
  408.         outfile <<endl;
  409.     // 色彩空间转换>>自己实现
  410.     int row = img.rows;
  411.     int col = img.cols * img.channels();
  412.     uchar * pImg = NULL;
  413.     BGR bgr;
  414.     HSV hsv;

  415.         outfile << "const unsigned char " << "hsv" <<"[][3]" << " = {" << " /*360*201*/" <<endl;
  416.         outfile << "        ";
  417.     for (int j = 0; j < col/3; j++)
  418.         {
  419.                 outfile << "/*     " << setw(3)<< setfill('0') << j << "     */" ;
  420.         }
  421.         outfile << endl;

  422.          for (int i = 0; i < row/2+1; i++)
  423.     {
  424.                 outfile << "/* " << setw(3)<< setfill('0')  << dec << i << "*/ " ;
  425.         pImg = img.ptr<uchar>(i);// 遍历时用img.at()效率会降很多, 很耗时
  426.         for (int j = 0; j < col; j+=3)
  427.         {
  428.             //bgr.b = pImg[j];
  429.             //bgr.g = pImg[j + 1];
  430.             //bgr.r = pImg[j + 2];
  431.             //bgr.b = 0;
  432.             //bgr.g = 0;
  433.             //bgr.r = 0;
  434.             //BGR2HSV(bgr, hsv);
  435.             hsv.h = j/3;//调整色相 +60.取值范围为[0, 360)
  436.             hsv.h = (hsv.h > 359) ? (hsv.h - 360) : hsv.h;
  437.             hsv.h = (hsv.h < 0)   ? (hsv.h + 360) : hsv.h;

  438.                         hsv.s = 1;

  439.                         hsv.v = i/100.0;//调整色相 +60.取值范围为[0, 360)
  440.             hsv.v = (hsv.v > 1) ? 1 : hsv.v;
  441.             hsv.v = (hsv.v < 0) ? 0 : hsv.v;
  442.             HSV2BGR( hsv, bgr);
  443.             pImg[j] = bgr.b;
  444.             pImg[j + 1] = bgr.g;
  445.             pImg[j + 2] = bgr.r;
  446.                         int b = bgr.b;
  447.                         int g = bgr.g;
  448.                         int r = bgr.r;
  449.                         outfile << "{0x" << setw(2)<< setfill('0') << hex << r << ",0x" << setw(2)<<setfill('0') << hex  << g << ",0x" << setw(2)<< setfill('0') << hex  << b << "},";
  450.         }
  451.                 outfile << endl;
  452.     }

  453.         for (int i = row/2+1; i < row; i++)
  454.     {
  455.                 outfile << "/* " << setw(3)<< setfill('0')  << dec << i << "*/ " ;
  456.         pImg = img.ptr<uchar>(i);// 遍历时用img.at()效率会降很多, 很耗时
  457.         for (int j = 0; j < col; j+=3)
  458.         {
  459.             //bgr.b = pImg[j];
  460.             //bgr.g = pImg[j + 1];
  461.             //bgr.r = pImg[j + 2];
  462.             //bgr.b = 255;
  463.             //bgr.g = 255;
  464.             //bgr.r = 255;
  465.             //BGR2HSV(bgr, hsv);
  466.             hsv.h = j/3;//调整色相 +60.取值范围为[0, 360)
  467.             hsv.h = (hsv.h > 359) ? (hsv.h - 360) : hsv.h;
  468.             hsv.h = (hsv.h < 0)   ? (hsv.h + 360) : hsv.h;
  469.                         hsv.s = 1-(i-100)/100.0;//调整色相 +60.取值范围为[0, 360)
  470.             hsv.s = (hsv.s > 1) ? 1 : hsv.s;
  471.             hsv.s = (hsv.s < 0) ? 0 : hsv.s;
  472.                         hsv.v = 1;
  473.             HSV2BGR( hsv, bgr);
  474.             pImg[j] = bgr.b;
  475.             pImg[j + 1] = bgr.g;
  476.             pImg[j + 2] = bgr.r;
  477.                         int b = bgr.b;
  478.                         int g = bgr.g;
  479.                         int r = bgr.r;
  480.                         outfile << "{0x" << setw(2)<< setfill('0') << hex << r << ",0x" << setw(2)<<setfill('0') << hex  << g << ",0x" << setw(2)<< setfill('0') << hex  << b << "},";
  481.         }
  482.                 outfile << endl;
  483.     }

  484.         outfile << "        };"  <<endl;

  485.    // for (int i = 0; i < row; i++)
  486.    // {
  487.    //     pImg = img.ptr<uchar>(i);// 遍历时用img.at()效率会降很多, 很耗时
  488.    //     for (int j = 0; j < col; j+=3)
  489.    //     {
  490.    //         bgr.b = pImg[j];
  491.    //         bgr.g = pImg[j + 1];
  492.    //         bgr.r = pImg[j + 2];
  493.    //         BGR2HSV(bgr, hsv);
  494.    //         //hsv.h = hsv.h + 60;//调整色相 +60.取值范围为[0, 360)
  495.    //         //hsv.h = (hsv.h > 359) ? (hsv.h - 360) : hsv.h;
  496.    //         //hsv.h = (hsv.h < 0)   ? (hsv.h + 360) : hsv.h;
  497.                         //hsv.s =  hsv.s + 0.1;//调整色相 +60.取值范围为[0, 360)
  498.    //         hsv.s = (hsv.s > 1) ? 1 : hsv.s;
  499.    //         hsv.s = (hsv.s < 0)   ? 0 : hsv.s;
  500.    //         HSV2BGR( hsv, bgr);
  501.    //         pImg[j] = bgr.b;
  502.    //         pImg[j + 1] = bgr.g;
  503.    //         pImg[j + 2] = bgr.r;
  504.    //     }
  505.    // }
  506.     imshow("my", img);
  507.         cv::imwrite("output.bmp",img);

  508.     // 色彩空间转换>>调用OpenCV
  509. //    cvtColor(tmp, tmp, CV_BGR2HSV);
  510. //    vector<Mat> channels;
  511. //    split(tmp, channels);
  512. ////    channels[0] += 60;// 调整色相 +30.这里没有做范围判断,opencv的h取值范围为[0, 180)
  513. //        channels[2] += 200;// 调整色相 +30.这里没有做范围判断,opencv的h取值范围为[0, 180)
  514. //    merge(channels, tmp);
  515. //    cvtColor(tmp, tmp, CV_HSV2BGR);
  516. //    imshow("opencv", tmp);
  517.     cv::waitKey();
  518.    
  519.     return 0;
  520. }
复制代码


生成的数组


生成的图片


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入53汤圆

发表于 2022-10-9 16:30:49 | 显示全部楼层
bbandpp 发表于 2018-10-12 13:54
我见过最NB的是用STM8实现,分段,变色,流星这些效果
(引用自28楼)

有出处吗  或者效果
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-30 11:11

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表