Ask Your Question
1

I want to know if there is round off function in opencv.

asked 2016-06-30 12:47:25 -0600

davidkim gravatar image

updated 2016-07-01 04:39:28 -0600

pklab gravatar image

I read double type data and I want to normalize it.

But before that I need to round off , I mean I want to remove digit under the point.

in C++, there is floor and ceil , but it doesn't work in a matrix.

Please tell me is there ceil or floor function for a matrix.

Thnx

edit retag flag offensive close merge delete

Comments

Ow just convert your double matrix into a int8 or int 32 matrix and it will round for you :)

StevenPuttemans gravatar imageStevenPuttemans ( 2016-06-30 13:45:32 -0600 )edit

i'm looking for how to define it.. in http://docs.opencv.org/2.4/modules/co...

Mat matrix1(Size(256, 256), CV_64F, matrix); //change array to matrix

I made matrix which is defined like that, matrix is double type number.

If it is ok could u tell me how to write to int8 or 32..?

thnx a lot :)

davidkim gravatar imagedavidkim ( 2016-06-30 14:05:48 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
2

answered 2016-07-01 04:38:02 -0600

pklab gravatar image

updated 2016-07-01 04:48:07 -0600

berak gravatar image

Example 1)

Mat srcMatrix(Size(256, 256), CV_64FC1, matrix); 
Mat dstMatrix(srcMatrix.size(),CV_8UC1);
double scale=1.0;
double offset=0.0;
//dstMatrix = srcMatrix * scale  + offset
srcMatrix.convertTo(dstMatrix, dstMatrix.type(),scale,offset);

Example 2) you could avoid to specify size and type for dstMatrix:

Mat dstMatrix;
srcMatrix.convertTo(dstMatrix, CV_8UC1,scale,offset);

in both cases convertTo performs round (not trunc/ceil). See also this answer.

edit flag offensive delete link more
0

answered 2016-07-01 05:11:34 -0600

Converting a 64bit floating point matrix into a integer matrix is quite straightforward.

Mat matrix1(Size(256,256), CV_64F, matrix);
Mat matix_reduced_precision;
matrix1.convertTo(matrix_reduced_precision, CV_8U);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-06-30 12:47:25 -0600

Seen: 4,274 times

Last updated: Jul 01 '16