HSV White Color Range In JS - OpenCV Q&A Forum

First time here? Check out the FAQ!

Hi there! Please sign in help OpenCV answers logo faq tags users badges This forum is disabled, please visit https://forum.opencv.org
ALL UNANSWERED Ask Your Question
0 HSV white color range in JS edit
  • cv.inRange
  • opencvjs
  • HSV
  • inRange
  • javascript

asked 2019-12-05 01:59:35 -0600

Lucy8 gravatar image Lucy8 24 2 4

I would like to track white color using webcam and Opencv.js. Here is the question/answer with python. I want to do exactly the same with javascript and tried this

const hsv = new cv.Mat(); cv.cvtColor(initialImage, hsv, cv.COLOR_BGR2HSV) const lower_white = [0, 0, 0]; const upper_white = [0, 0, 255]; const low = new cv.Mat(hsv.rows, hsv.cols, hsv.type(), lower_white); const high = new cv.Mat(hsv.rows, hsv.cols, hsv.type(), upper_white); const dst = new cv.Mat(); cv.inRange(hsv, low, high, dst);

But it doesn't work. I'm getting the following error

Uncaught TypeError: Incorrect number of tuple elements for Scalar: expected=4, actual=3

Error is occurring on this line

const low = new cv.Mat(hsv.rows, hsv.cols, hsv.type(), lower_white);

The problem is that it wants lower_white array to have 4 elements instead of 3.

What is the 4th element in HSV format?

I also tried to put the 4th element from 0 to 255

const lower_white = [0, 0, 0, 0]; const upper_white = [0, 0, 255, 255];

In this case, there is no error but it doesn't seem right. It doesn't work. Any suggestions or explanations of what should be lower_white and upper_white values?

edit retag flag offensive close merge delete add a comment

3 answers

Sort by » oldest newest most voted 2

answered 2019-12-05 04:02:53 -0600

mvuori gravatar image mvuori 542 1 7

Nobody seems to know about the 4th element, but if I had to guess, JS stores even HSV images in four channels (unlike other platforms), and the fourth is the alpha channel.

edit flag offensive delete link more add a comment 1

answered 2019-12-05 02:54:39 -0600

berak gravatar image berak 32993 7 81 312

I would like to track white color

maybe you think about that again. -- white is not really a "color", it can be any hue value in hsv.

iif you're just begin coding with this, start with an easier color, like yellow or pink

edit flag offensive delete link more add a comment 0

answered 2020-12-19 17:45:05 -0600

taesookim0412 gravatar image taesookim0412 1

The way you created your ranges is incorrect, and initializing a Mat from a 3 column array instead of a 4 column array gives the error

"Incorrect number of tuple elements for Scalar: expected=4, actual=3",

The way to create the range works through using the factory method matFromArray(). the ranges must be created by

const low = cv.matFromArray(hsv.rows, hsv.cols, hsv.type(), lower_white);

instead of

const low = new cv.Mat(hsv.rows, hsv.cols, hsv.type(), lower_white);

https://docs.opencv.org/3.4/de/d06/tu...

edit flag offensive delete link more add a comment

Links

Official site

GitHub

Wiki

Documentation

Question Tools

Follow 1 follower

subscribe to rss feed

Stats

Asked: 2019-12-05 01:59:35 -0600

Seen: 21,832 times

Last updated: Dec 19 '20

Related questions

How to use InRange at Different Color Space and Range.

Need to know the HSV value.

Hough Transform after removal of color [closed]

Create a HSV Range Palette

What's the best way to segment different coloured blobs?

Counting the number of colours in an image

How to get histogram of a rectangular area (ROI) of an image?

How to find the two most dominant colors in an image?

HSV-Range iOS vs. Mac OS [closed]

Core inRange

Copyright OpenCV foundation, 2012-2018. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license. about | faq | help | privacy policy | terms of service Powered by Askbot version 0.10.2  gravatar image ( 2025-12-15 02:20:34 -0600 )editnone×

Từ khóa » Hsv Color Space White