1

I am new to OpenCv with android .I am trying to make an application which auto detects documents using OpenCv - 2.4.13 . In my app, there is a functionality of detection documents (like Scanbot app) and then convert it to document. So far i am being able to detect documents using opencv in landscape mode. What i need is showing app in portrait mode . Since, by default OpenCv for android working in landscape mode, I want it in portrait mode . I have gone through lots of solutions for that and it worked too but having performance degradation issues (like Camera frame slower down). What i gone through so far is : Rotate camera preview to Portrait Android OpenCV Camera

Rotating Android Camera to Portrait

However ,i am able to change camera orientation in portrait but with some performance degradation issues

Has anyone done this successfully ?

I am also looking for other options to auto detect documents besides OpenCv. I don't know whether it is possible without OpenCv or not.

Is it Possible to auto detect documents without OpenCv ? How ?

Community
  • 1
  • 1
Tech
  • 39
  • 1
  • 6

1 Answers1

0

I have gone through the same problem with opencv and after hours of research i finally found solution . You have to make changes in default opencv class .
Follow this steps: 1) In CameraBridgeViewBase class add following code

Matrix matrix = new Matrix();
matrix.setRotate(90f);
Bitmap bitmap = Bitmap.createBitmap(mCacheBitmap, 0, 0, mCacheBitmap.getWidth(), mCacheBitmap.getHeight(), matrix, true);

2) now in drawbitmap method replace above bitmap with mCacheBitmap , as like below

if (mScale != 0) {
                canvas.drawBitmap(bitmap, new Rect(0,0,bitmap.getWidth(), bitmap.getHeight()),
                        new Rect((int)((canvas.getWidth() - mScale*bitmap.getWidth()) / 2),
                                (int)((canvas.getHeight() - mScale*bitmap.getHeight()) / 2),
                                (int)((canvas.getWidth() - mScale*bitmap.getWidth()) / 2 + mScale*bitmap.getWidth()),
                                (int)((canvas.getHeight() - mScale*bitmap.getHeight()) / 2 + mScale*bitmap.getHeight())), null);
            } else {
                canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()),
                        new Rect((canvas.getWidth() - bitmap.getWidth()) / 2,
                                (canvas.getHeight() - bitmap.getHeight()) / 2,
                                (canvas.getWidth() - bitmap.getWidth()) / 2 + bitmap.getWidth(),
                                (canvas.getHeight() - bitmap.getHeight()) / 2 + bitmap.getHeight()), null);
  }

3) now , In your JavaCameraView class replace following code in initializeCamera method (changing height ,width for Portrait mode)

if ((getLayoutParams().width == ActionBar.LayoutParams.MATCH_PARENT) && (getLayoutParams().height == ActionBar.LayoutParams.MATCH_PARENT))
                    mScale = Math.min(((float)height)/mFrameWidth, ((float)width)/mFrameHeight); 
                else
                    mScale = 0;

and you are done !!

I don't think , there is any alternative other than OpenCv for auto detection of objects

ImLearning
  • 317
  • 1
  • 3
  • 15
  • Thanks a lot @ImLearning , you made my day – Tech Jan 17 '17 at 13:34
  • I am having it too . see this link : http://stackoverflow.com/questions/41712993/drawcontours-around-detected-document-using-opencv-for-android-gives-strange-bug – ImLearning Jan 18 '17 at 07:24