0

I'm using template matching to detect brown color image and set a threshold of 0.7 to accept right match. I created a few templates for brown color image but every time I inspect a new brown image with template I'm getting low scores 0.4 even if there is a very little difference in image may be some spot or lighting. I tried a lot but not able to detect. Due to different scores every time I need to add a lot of templates to achieve the same.

I'm converting the image to gray scale and doing some pre-processing

    Image<Gray, byte> grayFrameimgModelROIvariable = ((Image<Bgr, byte>)imgModelROIPic.Image).Convert<Gray, byte>();
    Image<Gray, byte> grayFrameimgInspTemplateVariable = ((Image<Bgr, byte>)imgInspectedROIPic.Image).Convert<Gray, byte>();

    grayFrameimgModelROIvariable.PyrDown();
    grayFrameimgModelROIvariable.PyrUp();

    grayFrameimgInspTemplateVariable.PyrDown();
    grayFrameimgInspTemplateVariable.PyrUp();

    grayFrameimgModelROIvariable._SmoothGaussian(3);
    grayFrameimgInspTemplateVariable._SmoothGaussian(3);

Please help

BHawk
  • 2,382
  • 1
  • 16
  • 24
Shayer
  • 3
  • 2

1 Answers1

0

@Shabbir, Are you using a grayscale image to try and differentiate between brown and blue? If so, IMPO, that may not be the best solution. If it were me, I would use the H (Hue) of HSV color scale to make that determination then switch to grayscale.

This article Color spaces in OpenCV might be of some use.

Doug

AeroClassics
  • 1,074
  • 9
  • 19
  • Thanks Dough I m using template matching and using greyscale images only. I tried to use Hue component and able to detect blue color using Range method as below – Shayer Dec 24 '17 at 06:08
  • CvInvoke.CvtColor((Image)imgInspectedROIPic.Image, hsv, ColorConversion.Bgr2Hsv); Mat[] channels = hsv.Split(); Image imageHSVDest = new Image(hsv.Width, hsv.Height); CvInvoke.InRange(hsv, new ScalarArray(new MCvScalar(110, 100, 0)), new ScalarArray(new MCvScalar(130, 255, 255)), imageHSVDest); – Shayer Dec 24 '17 at 06:09
  • But for brown color not able to find the same using below range for brown color detection CvInvoke.InRange(hsv, new ScalarArray(new MCvScalar(10, 100, 20)), new ScalarArray(new MCvScalar(20, 255, 200)), imageHSVDest); – Shayer Dec 24 '17 at 06:14