OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 18 May 2016 08:10:39 -0500Basic operations on mat variable in androidhttp://answers.opencv.org/question/94460/basic-operations-on-mat-variable-in-android/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. Wed, 18 May 2016 07:52:48 -0500http://answers.opencv.org/question/94460/basic-operations-on-mat-variable-in-android/Answer by berak for <p>Initially i used MATLAB for testing my logic and it works smoothly in matlab.</p>
<p>But now i want to implement the same in android with help of OpenCV.</p>
<p>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.</p>
<p>Any help would be very helpful. </p>
http://answers.opencv.org/question/94460/basic-operations-on-mat-variable-in-android/?answer=94461#post-id-94461while 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 !
Wed, 18 May 2016 08:10:39 -0500http://answers.opencv.org/question/94460/basic-operations-on-mat-variable-in-android/?answer=94461#post-id-94461