15

I am developing a project which requires the image crop feature like camscanner android application,when a picture is taken and when user clicks the crop button, a rectangle overlay should be shown as in camscanner. Where the rectangle path can be stretched to any angle and can perform crop.please do help me with a solution.

I was referring to https://github.com/edmodo/cropper . but this as only rectangle overlay with 4 points.please do help me if any one has a link or solution!!

MBH
  • 16,271
  • 19
  • 99
  • 149
Robin prash
  • 153
  • 1
  • 1
  • 6
  • Have you found any solution? – Mehul Joisar Mar 06 '14 at 06:15
  • possible duplicate of [How to perform Auto crop for document Recognize image using camera?](http://stackoverflow.com/questions/19679768/how-to-perform-auto-crop-for-document-recognize-image-using-camera) – bummi Jul 21 '15 at 07:06

2 Answers2

43

I had a similar requirement and I too didn't find any concrete solution similar to CamScanner, so I have taken the challenge and have implemented a scan library (on top of OpenCV, rich image processing library) similar to CamScanner which can be easily integrated into an existing application, using the library you will be able to select the exact edges in whatever angle and crop the document accordingly from the selected 4 edges and change the perspective transformation of the cropped image.

Github link of the Android ScanLibrary: https://github.com/jhansireddy/AndroidScannerDemo

enter image description here

Community
  • 1
  • 1
jhansi
  • 548
  • 6
  • 13
  • 1
    in crop fragment polygon surface is not automatically detecting edges can you help me in fixing this – Karthik Mar 03 '16 at 07:11
  • @jhansi am using the sam scan library but one small problem is that the rectangle croping is not detecting the full image it detecting from the half the image but when its cropped am getting the full image but if I adjust the rectangle to the edges of the document am getting the half the image, do u have any idea on it, If u need i can post the image for your reference – balajivaishnav Apr 08 '16 at 06:04
  • @Balaji which scan library are you using? Is that been forked from my AndroidScannerDemo repo? – jhansi Apr 09 '16 at 16:51
  • @jhansi nice library you have made. Can you please provide me some link for how can i use OpenCV into my project, any tutorial or reference material – TapanHP Sep 28 '16 at 10:21
  • @jhansi, there are libpng issues for that reason google rejeted the application ,How to solve this issues ? – Suman Oct 14 '16 at 05:23
  • @suman, as you know we have upgraded the openCV to 3.1 which have resolved the libpng issues. – jhansi Oct 23 '16 at 13:38
  • 1
    The main problem of this library is the image orientation is always 90 degree rotated. 2nd problem is, it lacks auto edge detection. – Raptor Nov 15 '16 at 09:12
  • This is the best free open source library there is for this kind of thing. Thank you for contributing – Vulovic Vukasin Mar 02 '17 at 11:57
  • This is great! Thank you so much for this. BTW, does anyone know a similar library that works on iOS? – Jiechao Li May 22 '17 at 11:50
  • is there any way to implement zoom crop magnify lens feature similar to cam scanner ? –  Nov 07 '17 at 09:43
  • @Raptor It does have auto-edge detection although not so robust and the images just worked fine for me, moreover rotating bitmaps is just three lines of code – Saravanabalagi Ramachandran Dec 27 '17 at 01:26
  • i am using this library in my project but after clicking image nothing happens ...crop part is not coming. here is my code https://drive.google.com/open?id=1pKTq0QwxuN1jy9Q1eFSQyr-TUEHFKHtQ can you please help me – Ajinkya kadam Feb 01 '20 at 12:28
  • @jhansi does this work while capturing the images from camera or only after capturing the images? – Cosmic Dev May 12 '20 at 04:27
  • @jhansi you mean while capturing the image the cropper will be displayed on the top of the screen and once i click the image only the part of the screen inside that cropper will be clicked? – Cosmic Dev May 13 '20 at 06:07
  • No @CosmicDev, after you capture the picture you can crop it. – jhansi May 15 '20 at 04:12
1

thanks @jhansi for this amazing library but the problem of this library(Android Scanner Library) is the image orientation is always 90 degree rotated, we can solve it like this.

Solution in Kotlin

In OnActivityResult it gives you bitmap and this bitmap you can pass to "Bitmap.roate" method.

Use it like this: val rotatedBitmap=bitmap.rotate(90f) imageView.setImageBitmap(rotatedBitmap)

Paste this method in your activity: fun Bitmap.rotate(degrees: Float): Bitmap { val matrix = Matrix().apply { postRotate(degrees) } return Bitmap.createBitmap(this, 0, 0, width, height, matrix, true) }

syed dastagir
  • 419
  • 6
  • 8