Android - I try to get simple access to Mat
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/...)
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.
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.
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.)