Ask Your Question
0

How to create a Scalar with variable number of channels?

asked 2018-03-28 15:41:57 -0600

Blath gravatar image

I want to create a Scalar which has a variable(integer) number of channels, hopefully all the channels being 0.

int channels = 2;
cv::Scalar(...); //Create Scalar with "channels" number of channels, all with the value of 0
edit retag flag offensive close merge delete

Comments

Did you try all()?

Der Luftmensch gravatar imageDer Luftmensch ( 2018-03-28 15:57:16 -0600 )edit

From what I've tested myself, it returns a 4 channel scalar with all elements set to a given value (which I would set to 0)

Blath gravatar imageBlath ( 2018-03-28 17:28:03 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-03-29 05:48:35 -0600

rwong gravatar image

cv::Scalar can store a maximum of 4 channels, each containing a double-precision floating point value.

https://github.com/opencv/opencv/blob...

It does not remember how many channels it was initialized with. It will always be 4 channels.

A default-constructed Scalar is already initialized with all-zeroes. This is because it has a user-defined constructor that does not require any arguments, and its body does exactly what you'd expect. Code:

https://github.com/opencv/opencv/blob...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-03-28 15:41:57 -0600

Seen: 656 times

Last updated: Mar 29 '18