I wrote a camera app using the camera API2. I can take a picture from the specific things. Then I know that there is important information in a specific location in my picture( I do not need to select the important area, I already know which part is crucial).I want to have only important part of my picture and use this part for my OCR application. My question is how to separate specific part of picture. Some people suggested me to crop the taken photo using com.android,camera.action.CROP. However I read in many places, that this method might not work in all android devices. Does any one know How should I do this? Does android support such an action?? Is that possible to crop the bytes file before saving the picture? or should I use third party library like Open-CV to do this stuff. Thanks in advance
Asked
Active
Viewed 323 times
0
-
exactly you want to crop the image pragmatically ???? – AmeeJoshi Nov 16 '16 at 12:52
2 Answers
0
if you are having starting point x and y and height and width of image or you are having four point to form a rectangle for copping image then you can use this piece of code
private void cropBitmap1(int startX, int startY, int width, int height, Bitmap bmp) {
// widht=x+x2 height=y+Y2
Bitmap source = bmp;
//Log.w("TAG","widths "+widths +" width"+width+" heights"+heights+" height"+height+" x"+startX +" y"+startY);
Bitmap resized = Bitmap.createBitmap(source, startX, startY, width, height);
//save the image or execute for ocr using tesseract
}
if you do not know those four points then go for Opencv so that you can use training file to get those points

Abhishek
- 16
- 2
0
If you want to use library, I would recommend the theartofdev library. Put this dependency in app gradle
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
For selection of image
CropImage.activity().start(getContext(), this);
This will redirect to open or capture image. User can crop it, after which the result can be easily obtained by
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == -1) {
Uri resultUri = result.getUri();
// TODO your stuff here. Cropped image will come here as resultant
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Exception error = result.getError();
}
}
}
This is the easiest way. You can crop any image here.

Shubham Jaiswal
- 156
- 3