C#: Detecting All Shades Of Violet [closed]

asked 2018-06-09 08:47:43 -0500

G'day, I'm trying to detect if an image has any shades of Violet in it.

I made this in C# however, after some research, I came across this library and was wondering if it could help to improve what I already have?

I did see that it can detect a Red stop sign, but what about all the different shades of red?

private bool Process(Image image)
    {
        using (Bitmap bitmap = new Bitmap(image))
        {
            int infected = 0;
            int total = 0;

            LockBitmap lockBitmap = new LockBitmap(bitmap);
            lockBitmap.LockBits();

            for (int x = 0; x != lockBitmap.Width; x++)
            {
                for (int y = 0; y != lockBitmap.Height; y++)
                {
                    if (lockBitmap.GetPixel(x, y).GetHue() + 25 > Color.FromKnownColor(KnownColor.Violet).GetHue() + 20) //need to fine tune.
                    {
                        infected++;
                    }
                    total++;
                }
            }

            lockBitmap.UnlockBits();

            Console.WriteLine(infected.ToString());
            Console.WriteLine(total.ToString());

            if (infected > 450) //need to fine tune.
            {
                MessageBox.Show("Damaged");
                return true;
            }
            else
            {
                MessageBox.Show("Not Damaged");
                return false;
            }
        }
    }

Here are some of the images I'm working with.
Image0 <-- This image as far as I can tell detects the violet colour(s)
Image1 <-- This one does too
Image2
This one does too, which seems pretty weird because unless my eyes need checking, I cant see any violet.
Image3
This one doesn't detect any violet.

What can I do to make sure that it only detects violet (any shade of violet) that we humans can see?
Thanks in advanced.

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2018-06-09 08:51:47.138319

Comments

sorry, but we cannot help you with it, since it is not related to opencv at all.

berak gravatar imageberak ( 2018-06-09 08:51:26 -0500 )edit

actually, abi, I was looking for a method that OpenCV might have and or if it was capable of doing so

Andrew Eberle gravatar imageAndrew Eberle ( 2018-06-09 08:53:37 -0500 )edit

there is no support for c#, either.

but usually, you'd filter a hsv range using inRange()

berak gravatar imageberak ( 2018-06-09 08:57:03 -0500 )edit