Click here to Skip to main content
15,879,050 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Built a tensorflow model to detect objects and then got model to run in an android device. The app in android now detects objects and on button click takes screenshot of the layout and gives the bounding boxes in the image view. Now i need to derive an editable matrix structure from this screenshot of bounding boxes. Below i am sharing the code i used for taking screenshot, which is stored in a class and then called in the main activity in android studio.

Expected results are a dynamic matrix or grid structure based on the bounding boxes ( which are always dynamic in terms of position and numbers )

sample screenshot link:

https://i.stack.imgur.com/gxEse.jpg
[^]

What I have tried:

Screenshot functionality:

public static Bitmap bitmap;


public static Bitmap getScreenShot(View view) {
View screenView = view.getRootView();
screenView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
screenView.setDrawingCacheEnabled(false);
return bitmap;

}

public static Bitmap takeScreenshot(View v) {

Bitmap screenshot = null;

try {
int width = v.getMeasuredWidth();
int height = v.getMeasuredHeight();

screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

Canvas c = new Canvas(screenshot);
v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
v.draw(c);


} catch (Exception e) {
e.printStackTrace();
}
return screenshot;
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900