标记未定义的颜色,并且颜色匹配系统中不存在样品
Flag undefined colors and no sample present from color matching system
通过颜色传感器,我使用欧几里得距离(最近距离(方法将塑料色板与数组中预定义的颜色调色板进行匹配。当识别颜色时,线性致动器移动。即使对于相当相似的柔和颜色,这也很好用。
但是,如何针对以下情况进行编码:1.传感器前面没有色板或2.颜色不在阵列中?我需要生成"无样本"(1.(或"未找到匹配项"(2.(消息,并且在这两种情况下执行器都不会移动。
就像现在一样,当传感器上没有色板时,代码从环境光中找到最接近的等效物,并且执行器移动 (1.(,当不匹配的色板位于传感器上方时,代码找到最接近的等效物并且执行器移动 (2.(。在这两种情况下,除了输出上述消息外,什么都不应该发生。
感谢您的一些提示!
const int SAMPLES[12][5] = { // Values from colour "training" (averaged raw r, g and b; averaged raw c; actuator movement)
{8771, 6557, 3427, 19408, 10},
{7013, 2766, 1563, 11552, 20},
{4092, 1118, 1142, 6213, 30},
{4488, 1302, 1657, 7357, 40},
{3009, 1846, 2235, 7099, 50},
{2650, 3139, 4116, 10078, 60},
{ 857, 965, 1113, 2974, 70},
{ 964, 2014, 2418, 5476, 80},
{1260, 2200, 1459, 5043, 90},
{4784, 5898, 3138, 14301, 100},
{5505, 5242, 2409, 13642, 110},
{5406, 3893, 1912, 11457, 120}, // When adding more samples no particular order is required
};
byte findColour(int r, int g, int b) {
int distance = 10000; // Raw distance from white to black (change depending on selected integration time and gain)
byte foundColour;
for (byte i = 0; i < samplesCount; i++) {
int temp = sqrt(pow(r - SAMPLES[i][0], 2) + pow(g - SAMPLES[i][1], 2) + pow(b - SAMPLES[i][2], 2)); // Calculate Euclidean distance
if (temp < distance) {
distance = temp;
foundColour = i + 1;
}
}
return foundColour;
}
表中何时存在颜色可以通过最佳匹配的距离来决定。当它的距离大于某个阈值时,则返回一些指示"未找到"的值,例如 -1 或 255。
还要存储传感器在没有样品的情况下检测到的任何内容(在校准期间(,当这是最佳匹配时,返回一些指示"无样品"的值,例如 0。
相关文章:
- C++,系统无法执行指定的程序
- 在UNIX系统中使用DIR查找文件的字节大小
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 错误处理.将系统错误代码映射到泛型
- 当系统的卷被修改时,如何修改WASAPI环回捕获卷
- 如何在内核C++中使用1920x1080x16M图形或类似的16M颜色?(VGA)
- 如何在24位SDL_Surface上设置像素的颜色
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- 在C++游戏中与库存系统作斗争
- 文件系统:复制功能的速度秘诀是什么
- c++17文件系统::recursive_directory迭代器()在mac上没有给出这样的目录,但在windows上
- 在gtest.中使用fff.h模拟系统API
- 如何制作无限制照明系统
- 如何从SDL_Surface获取特定像素的颜色
- 标记未定义的颜色,并且颜色匹配系统中不存在样品
- C++函数系统(命令)的输出在Linux终端中不显示颜色
- 为什么通过系统("color YX")更改控制台应用程序中C++颜色不是最佳解决方案?
- 如何将系统颜色更改为默认颜色?
- 混合两个粒子系统的颜色
- 更换为系统("颜色")