0

I want to mutiply 2 with each element of vec3 in opencv as we do in Matlab simplt by ".*". I searched alot but didn't find any command is their any command for this or not in opencv? thanks in advance for any help.

i1000123
  • 83
  • 1
  • 2
  • 11

1 Answers1

0

This answer would suggest you can just use the * assignment operator in C++.

If you are using Java I don't think this is possible, you can only multiply a Mat by another Mat.

So you would need to create a new Mat instance of the same size and type, initialised with the scalar value you want to multiply by.

You can easily create a funcion to do this:

public Mat multiplyScalar(Mat m, double i)
{
    return m = m.mul(new Mat((int)m.size().height, (int)m.size().width, m.type(), new Scalar(i)));
}

Then x = multiplyScalar(x, 5); will multiply each element by 5.

Community
  • 1
  • 1
James Barnett
  • 5,039
  • 3
  • 15
  • 18