SMACC2
Loading...
Searching...
No Matches
colour.hpp
Go to the documentation of this file.
1// Copyright 2026 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <opencv2/core.hpp>
18
19#include <string>
20#include <vector>
21
22namespace cl_rgb
23{
24
25// A colour word and where it lies in Lab (L 0 to 100, a and b around 0).
27{
28 std::string name;
29 cv::Vec3d lab;
30};
31
32// The everyday colour words, each at the Lab value of its pure sRGB colour.
33const std::vector<NamedColour> & basicColours();
34
35// The word whose colour is nearest to the given one. Colours with little chroma are told
36// apart by lightness (black, gray, white); the others by hue, so that shading does not turn
37// one colour into another.
38std::string colourName(const cv::Vec3d & lab);
39
40// How far a colour is from a colour word: 0 for the word's own colour, larger the further.
41// Infinite for a word that is not among basicColours().
42double colourCost(const cv::Vec3d & lab, const std::string & name);
43
44// Gives each of the named colours one of the seen colours, no seen colour twice, so that the
45// costs add up to the least. For a scene whose colours are known by name beforehand: a dark
46// blue is then "blue" because nothing else there is, though alone it would be called purple.
47// Returns the index into `seen` for each name, or nothing when there are fewer seen than named.
48std::vector<int> matchColours(
49 const std::vector<cv::Vec3d> & seen, const std::vector<std::string> & names);
50
51} // namespace cl_rgb
double colourCost(const cv::Vec3d &lab, const std::string &name)
Definition colour.cpp:56
std::vector< int > matchColours(const std::vector< cv::Vec3d > &seen, const std::vector< std::string > &names)
Definition colour.cpp:108
std::string colourName(const cv::Vec3d &lab)
Definition colour.cpp:35
const std::vector< NamedColour > & basicColours()
Definition colour.cpp:23
std::string name
Definition colour.hpp:28