You can always rewrite the algorithm, which isn't that complicated for function inRange
.
Another solution could be to simply use inRange
when min[0]<=max[0]
and otherwise do the following:
slit the channels
{hchan,schan,vchan}
of your image usingcv::split
apply
inRange
to the three channels and get maskH, maskS, maskVinRange(hchan,max[0],min[0],maskH)
inRange(schan,min[1],max[1],maskS)
inRange(vchan,min[2],max[2],maskV)
recombine the three masks like this
bitwise_and(maskS,maskV,rangeMask)
bitwise_not(maskH,maskH)
bitwise_and(maskH,rangeMask)
But I personnally think that is an overshoot (and also less efficient than to rewrite the algorithm).