Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You need to use the .mul() method.

Examples:

std::cerr << "test opencv: " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << std::endl;
cv::Vec3i aa, bb; 
aa[0] = aa[1] = aa[2] = 2;
bb[0] = bb[1] = bb[2] = 3;
// try multiplication of vectors
cv::Vec3i ab = aa.mul(bb);
std::cerr << "1. " << aa << " .* " << bb << " = " <<  ab << std::endl;
// try multiplication of scalars
cv::Scalar cc = cv::Scalar(aa).mul(cv::Scalar(bb));
std::cerr << "2. " << cv::Scalar(aa) << " .* " << cv::Scalar(bb) << " = " <<  cc << std::endl;
// try multiplication of matrices
cv::Mat ccc  = cv::Mat(aa).mul( cv::Mat(bb) );
std::cerr << "3. " << cv::Mat(aa) << " .* " << cv::Mat(bb) << " = " <<  ccc << std::endl;

Output:

test opencv: 2.4.7
1. [2, 2, 2] .* [3, 3, 3] = [6, 6, 6]
2. [2, 2, 2, 0] .* [3, 3, 3, 0] = [6, 6, 6, 0]
3. [2; 2; 2] .* [3; 3; 3] = [6; 6; 6]

You need to use the .mul() method. Note that afaik mixing of the types (e.g. Scalar.mul(Vec3i)) won't work.

Examples:

std::cerr << "test opencv: " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << std::endl;
cv::Vec3i aa, bb; 
aa[0] = aa[1] = aa[2] = 2;
bb[0] = bb[1] = bb[2] = 3;
// try multiplication of vectors
cv::Vec3i ab = aa.mul(bb);
std::cerr << "1. " << aa << " .* " << bb << " = " <<  ab << std::endl;
// try multiplication of scalars
cv::Scalar cc = cv::Scalar(aa).mul(cv::Scalar(bb));
std::cerr << "2. " << cv::Scalar(aa) << " .* " << cv::Scalar(bb) << " = " <<  cc << std::endl;
// try multiplication of matrices
cv::Mat ccc  = cv::Mat(aa).mul( cv::Mat(bb) );
std::cerr << "3. " << cv::Mat(aa) << " .* " << cv::Mat(bb) << " = " <<  ccc << std::endl;

Output:

test opencv: 2.4.7
1. [2, 2, 2] .* [3, 3, 3] = [6, 6, 6]
2. [2, 2, 2, 0] .* [3, 3, 3, 0] = [6, 6, 6, 0]
3. [2; 2; 2] .* [3; 3; 3] = [6; 6; 6]