Android - I try to get simple access to Mat

asked 2015-03-28 10:07:29 -0600

pkpkpk gravatar image

Hello everybody, I am trying to learn using OpenCV in Android apps. I believe that my code right now go through every element of grayscale Mat (which is camera frame). My question is: Why it is so slow? I get less than 1 fps. Its strange, because Android OpenCV examples works fine on my device.

This is heart of my code:

public void onCameraViewStarted(int width, int height) {
         mGray = new Mat(height, width, CvType.CV_8U);   
     }

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {


         mGray = inputFrame.gray();

         for(int i=0; i<mGray.rows(); i++){
             for (int j=0; j<mGray.cols();j++){
                 n2Pixel = (byte) mGray.get(i, j)[0]; } }
        return mGray;
}

Everything else is the same as in the tutorial (http://docs.opencv.org/doc/tutorials/...)

edit retag flag offensive close merge delete

Comments

i bet, that none of the examples tries to iterate over the pixels like you do above. don't do that!

what are you trying to achieve ? there's probably a builtin function doing that already.

berak gravatar imageberak ( 2015-03-28 10:21:02 -0600 )edit

I want to iterate over pixels because I want to try doing my own algorithms. I was thinking that every OpenCV function (for example threshold) has to iterate over pixels :(. My goal is to find black thing (eg. square) with white frame.

pkpkpk gravatar imagepkpkpk ( 2015-03-28 10:38:56 -0600 )edit

rule #1 : never do like that from java.

(yes, opencv somehow has to iterate, too, but doing that in c++ using optimized sse/neon/ocl code is a total different story.)

berak gravatar imageberak ( 2015-03-28 10:47:49 -0600 )edit