0

I have to make a macros, it should detect object by color on the certain area on the picture of the screen. Further, I need to continue execute code if object has been detected.

    Image<Bgr, Byte> imgWindowScreen;
    Image<Gray, Byte> imgWindowScreenProcessed;
    Bitmap bmpScreenshot;
    System.Drawing.Graphics gfxScreenshot;
    Size size = new Size(400, 120);

bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                           Screen.PrimaryScreen.Bounds.Height,
                           PixelFormat.Format32bppArgb);

gfxScreenshot = Graphics.FromImage(bmpScreenshot);

gfxScreenshot.CopyFromScreen(700, 347, 0, 0, size);

imgWindowScreen = new Image<Bgr, Byte>(bmpScreenshot);

imgWindowScreenProcessed = imgWindowScreen.InRange(new Bgr(3, 25, 82),
                                         new Bgr(50, 98, 200));

Is it right I have choosen the area? I have a upper left point and I need to get something like that: enter image description here

How to define that imgWindowScreenProcessed has a pixels of searched color? I need to build a following structure:

if (picture has pixels of searched color) {...}
else {...}
2
  • Could you please clarify, do you only need to detect the object of a specific color? Commented Apr 4, 2019 at 11:02
  • @БолатТлеубаев I need to detect color and then, if color has been detected, I need do something Commented Apr 6, 2019 at 15:20

1 Answer 1

1

Here you may find the Python implementation of HSV thresholding. I understand that you need it on another language, however you might get some insights on logic of the implementation as it shows a simple case. Here you can find a deeper C++ implementation

After you have obtained the binary image, where pixels of desired color are 1 and other pixels are 0, you may play with morphology to enhance the image here, and get proper regions of interest.

Then, when you have an in image you may want to see the location of the object. You may use findContours() function to get the location of the object.

I usually do work with OpenCV in Python, but hope that this may also be helpful! :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.