0

I'm trying to develop an application, which need to perform a real-time document detection, as it happens in the Office Lens application.

Currently, I can do document detection, but the performance is very poor (3fps), due to the fact that I'm trying to rotate the image to portrait mode.

Has anyone here worked with opencv on android and had the same problem? Portrait mode is a must.

CR235
  • 1
  • 2
  • I solved this in 2 hours. SEE [https://stackoverflow.com/questions/26852711/issues-in-working-with-android-portrait-mode-with-opencv](https://stackoverflow.com/questions/26852711/issues-in-working-with-android-portrait-mode-with-opencv) –  Oct 09 '17 at 09:40

1 Answers1

0

after working several days I think that this works fine.

Matrix matrix = new Matrix();
matrix.preTranslate((canvas.getWidth() - mCacheBitmap.getWidth()) / 2,(canvas.getHeight() - mCacheBitmap.getHeight()) / 2);
matrix.postRotate(90f,(canvas.getWidth()) / 2,(canvas.getHeight()) / 2);
float scale = (float) canvas.getWidth() / (float) mCacheBitmap.getHeight();
matrix.postScale(scale, scale, canvas.getWidth()/2 , canvas.getHeight()/2 );
canvas.drawBitmap(mCacheBitmap, matrix, new Paint());

Insert it at CameraBridgeViewBase.java, after LINE 415:

if (bmpValid && mCacheBitmap != null) {
    Canvas canvas = getHolder().lockCanvas();
    if (canvas != null) {
        canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR);
        //insert here
    }
}

I'm using OpenCV 3.4. Let me know if it works for you. Ask if not. NOTE: This is working only with portrait mode. In this case I dont need landscape mode. I have about -2 fps but It works very good.

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
OctavioCega
  • 166
  • 2
  • 15