2

I use OpenCV for developing in Javascript.

I am trying to detect variations of orange RGB color between (255, 80, 0) and (255, 170, 0) in any image.

I was trying to do the same as here https://docs.opencv.org/3.3.1/db/d64/tutorial_js_colorspaces.html, but it not working when I changed from black detection to orange detection.

I tried the following code and many others combinations, but have got unexpected.

So, how to choose the limits for ORANGE color?

Here goes the javascript code:

let lower = [230, 155, 0, 0];
let higher = [255, 195, 25, 255];
let src = cv.imread('canvasInput');
let dst = new cv.Mat();
let low = new cv.Mat(src.rows, src.cols, src.type(), lower);
let high = new cv.Mat(src.rows, src.cols, src.type(), higher);
cv.inRange(src, low, high, dst);
cv.imshow('canvasOutput', dst);
src.delete(); dst.delete(); low.delete(); high.delete(); 

This is the unexpected result

1 Answer 1

1

If orange is about [255, 170, 0] in RGB space I would suggest to widen your range around that:

let lower = [230, 155, 80, 0];
let higher = [255, 195, 120, 255];

In your settings your orange needs to have exactly R=255 and B=0, that is not going to happen in real images. I do not know what the fourth parameter selects (alpha channel?) so it is all in range.

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

3 Comments

I dont know about fourth parameter. I tried to find any documentations about cv.Mat. With no success...
Also, I tried to use your recomendation and nothing happens. I will update my post
I used a color picker to check the orange in your image and adjusted the range accordingly (more blue) in my answer.

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.