// => hue and normalize, if null, may be created and assigned // <= ROI private CvMat detectROI(CvMat input, ref CvMat hue, ref CvMat normalize) { // TODO : Like I said above, if I get the minimum/maximum values, I have an accurate lowerBound/upperBound pair to work with!!! CvMat roi; CvScalar lowerBound; CvScalar upperBound; // IDEA 3: // Determine if I should check for "features" in the "thresholded" image, or in a cropped grayscale version of the original one!! // For now, lets search the thresholded one... if (boxEstimationType == BoxEstimationType.HUE) { roi = MatOps.CopySize(input, MatrixType.U8C1); lowerBound = boxEstimatedValue - floodHueTolerance / 1; // TODO : this should be +-(MAX VALUE) upperBound = boxEstimatedValue + floodHueTolerance / 1; if (hue == null) { hue = MatOps.BGRtoHue(input); } hue.InRangeS(lowerBound, upperBound, roi); } else if (boxEstimationType == BoxEstimationType.NORMALIZE) { // TODO : must investigate, range doesn't return anything roi = MatOps.CopySize(input, MatrixType.U8C1); lowerBound = boxEstimatedValue - floodNormTolerance; upperBound = boxEstimatedValue + floodNormTolerance; if (normalize == null) { normalize = MatOps.MyNormalize(input); } normalize.InRangeS(lowerBound, upperBound, roi); } else { // Couldn't estimate either way? We are off to a bad start, but lets try to see if features can be extracted anyway. roi = MatOps.ConvertChannels(input); // we are already losing valuable info here!! } return(roi); }
// Threshold the image based on the HSV value // From and To are CvScalars of 3 values {Hue, Saturation, and (Brightness) Value) CvMat GetThresholdedImage(CvMat img, CvScalar from, CvScalar to) { // Hue, Saturation, Value or HSV is a color model that describes colors (hue or tint) // in terms of their shade (saturation or amount of gray) // and their brightness (value or luminance). // Hue is expressed as a number from 0 to 360 degrees representing hues of red (starts at 0), // yellow (starts at 60), green (starts at 120), cyan (starts at 180), // blue (starts at 240), and magenta (starts at 300). // Saturation is the amount of gray (0% to 100%) in the color. // Value (or Brightness) works in conjunction with saturation and // describes the brightness or intensity of the color from 0% to 100%. CvMat imgHsv = ConvertToHSV(img); CvMat imgThreshed = new CvMat(img.Rows, img.Cols, MonoColorMatrix); imgHsv.InRangeS(from, to, imgThreshed); return(imgThreshed); }