I was wondering if there is an efficient way to detect similar colors?
I've been trying to find solutions, and the best "solution" I have found is this StackOverflow question:
How to determine if a color is close to another color
But, It seems to be detecting black more than the color I assigned, also with the threshold on low.
Here is my code:
COLORREF color_yellow = (255, 255, 0);
COLORREF color;
bool ColorsAreClose(COLORREF Colora, COLORREF Colorz, int threshold = 70)
{
int r = (int)GetRValue(Colora) - GetRValue(Colorz),
g = (int)GetGValue(Colora) - GetGValue(Colorz),
b = (int)GetBValue(Colora) - GetBValue(Colorz);
return (r * r + g * g + b * b) <= threshold * threshold;
}
int main(){
while (true) {
if (ColorsAreClose(color, color_yellow) == true) {
std::cout << "true";
}
}
}