【问题标题】:Find a particular color in a 2D image在 2D 图像中查找特定颜色
【发布时间】:2014-11-14 16:41:02
【问题描述】:

有哪些算法可以检测或查找图像中的特定颜色 (RGB)。检测将被特意用作标记,以找到随后将使用的特定颜色的位置。

【问题讨论】:

    标签: image-processing graphics computer-vision


    【解决方案1】:

    如果您知道颜色,您可以直接查找:

    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;
           }
          }
     }
    

    【讨论】:

    • 不怎么样?你可以自己翻译。您还应该更新帖子中的标签以指示C#。这样人们就不会在你不想要的语言上浪费时间。
    • 现在你正在输入 SO:Homework。新的社区网站。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多