有哪些算法可以检测或找到图像中的特定颜色(RGB)。该检测将被有目的地用作标记,以找到随后将使用的特定颜色的位置。
答案 0 :(得分:0)
如果您知道颜色,您可以查找它:
C ++
glm::vec3 targetColor(1.0f,0,0);//(red,blue,green)
float accepted_color_distance = 0.1f;
/*how much must look the colors alike? distance 0 means the colors must be equal,
but there are numeric precission problems. Use 0.0001f or
something instead of 0.*/
bool markersFound[image.rows][image.cols]; //true means pixel y,x is a markers
for(unsigned int a = 0; a < image.rows; a++) //init markersFound with false
{
for(unsigned int b = 0; b < image.cols; b++)
{
bool markersFound[a][b] = false;
}
}
for(unsigned int a = 0; a < image.rows; a++)
{
for(unsigned int b = 0; b < image.rows; b++)
{
glm::vec3 currentColor = image.at(a,b);
float color_distance = glm::distance(currentColor, targetColor);
if(color_distance < accepted_color_distance) //if a marker is found save it
{
bool markersFound[a][b] = true;
}
}
}