Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Doing the absolute value is easy, just cv::abs(src, dst). Rounding is slightly harder. You can either iterate over every pixel and use cvRound(), but it's probably better to temporarily go from float to int and then back.

I suggest using convertTo

cv::abs(user_feature_matrix, user_feature_matrix);
user_feature_matrix.convertTo(user_feature_matrix, CV_32S, 100, 0.5);

What this does, is it multiplies the matrix by 100, then adds 0.5, and then converts it to an int. This takes advantage of the fact that rounding is (int)(number+0.5). From here you can convert it back to a float, or just keep using it as an int if that works for you.