Ask Your Question

change Mat element values are slow

asked 2012-12-19 09:25:16 -0600

manssone gravatar image<unsigned short="">(row,col) += 1

Why is that operation so slow? Why is that slower than increasing an INT (or 100 INTs for that matter) for example? If I want to make a lot of this type of calls, what would be the most efficient way?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-12-19 10:10:24 -0600

Michael Burdinov gravatar image

It is slower because it had to do more work. Not just increment the value of INT. First it to need to use row and col to calculate place in memory that should be incremented. It also need to access value in array. Random access to values in arrays is time consuming task. Read this tutorial for short review of how pixels of Mat should be accessed.

edit flag offensive delete link more


So it is the Random Access part that makes it so time consuming? I am building up a projection of an image with range data by taking every range data and transforming that into a row&col and adding 1 to myMat which represents the floorPlane. i.e, a wall will be a bright line. Maybe there is a faster way of achieving the same result?

manssone gravatar imagemanssone ( 2012-12-20 02:22:00 -0600 )edit

I am not sure I understand correctly what you are trying to achieve, but calculation of projection is usually an expensive process, so random access will not be the most time consuming part.

Michael Burdinov gravatar imageMichael Burdinov ( 2012-12-20 05:21:37 -0600 )edit

Please, read the proposed tutorial. It explains the theme perfectly.

Daniil Osokin gravatar imageDaniil Osokin ( 2012-12-20 05:21:45 -0600 )edit

Question Tools


Asked: 2012-12-19 09:25:16 -0600

Seen: 1,887 times

Last updated: Dec 19 '12