Ask Your Question
0

Basic operations on mat variable in android

asked 2016-05-18 07:52:48 -0600

mack_emb gravatar image

Initially i used MATLAB for testing my logic and it works smoothly in matlab.

But now i want to implement the same in android with help of OpenCV.

I am looking for a way to simply access the individual pixel values and do simple mathematical operations on the same (addition and multiplication). I found many answers online, but most of them have their specific set of probelm which they simply solved by using some method already available in openCV.

Any help would be very helpful.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-05-18 08:10:39 -0600

berak gravatar image

while this is possible, you clearly should not do per pixel operations, but prefer opencv's high level, hardware optimized functions , especially on android, where it's gross slow.

double [] pixel = mat.get(y,x);
mat.put(x,y, pixel);

in most cases, it's faster, to get all of the pixels into a buffer, operate on that, and put() it back later:

byte [] buffer = new byte[mat.total() * mat.elemSize()];
mat.get(0,0,buffer);
// process buffer ...
mat.put(0,0,buffer);

but again, use add(), subtract(), and the like, whenever possible !

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-05-18 07:52:48 -0600

Seen: 235 times

Last updated: May 18 '16