1

I need a way to threshold or combine 2 inRange() functions to detect the range of a red color in HSV color space

In HSV space, the red color wraps around 180. So i need the H values to be both in [0,10] and [170, 180].

How to combine these to functions:

inRange(hsv, Scalar(0, 70, 50), Scalar(10, 255, 255), mask1);
inRange(hsv, Scalar(170, 70, 50), Scalar(180, 255, 255), mask2);

If it is not possible to combine them how to Threshold values to get the desired output of red color.

J.doe
  • 33
  • 6
  • The range should be 0 to 360, or -180 to 180, not 0-180. – kshetline May 01 '18 at 06:19
  • opencv `H` range lies between 0-180 – J.doe May 01 '18 at 06:21
  • Tried with `OR`? – Usagi Miyamoto May 01 '18 at 06:32
  • Weird system! Anyway, can you manipulate the hue value for the purpose of this task to subtract 180 from any value over 90, making the range -90 to 90, then test for the hue range [-10, 10]? – kshetline May 01 '18 at 06:33
  • This is how to achieve that in [C++ Code](https://stackoverflow.com/questions/32522989/opencv-better-detection-of-red-color) And this is also a similar [question](https://stackoverflow.com/questions/50105075/how-to-perform-a-union-operation-in-java-opencv) that no one answered it correctly – J.doe May 01 '18 at 06:40
  • @UsagiMiyamoto i need to do `OR` but it seems to be not possible in `openCV Java` check the two previous links i provided, were discussing how to do an `OR` operation. – J.doe May 01 '18 at 06:43
  • @J.doe The link at your linked question does exactly what you need: https://docs.opencv.org/java/2.4.2/org/opencv/core/Core.html#bitwise_or(org.opencv.core.Mat,%20org.opencv.core.Mat,%20org.opencv.core.Mat) – Usagi Miyamoto May 03 '18 at 14:12
  • @J.doe Did you find any solution for this problem ? – Assegd Jun 13 '19 at 07:27

0 Answers0