grewe / covid_id

Mobile vision project to create app for crowd shared situation awareness featuring Computer Vision and Machine Learning.
2 stars 7 forks source link

Landscape Display: Fix Image Display not rotated and too small #15

Closed grewe closed 4 years ago

grewe commented 4 years ago

When run in Landscape mode inherited code from TF lite android developer website does not rotate preview / display of camera images and is smaller than superimposed bounding boxes detector activity ---or simple too small in classifier activity.

grewe commented 4 years ago

FIXED.

NOTE: because of the size of the camera it will not fill the entire screen in the landscape mode but, now it is rotated and filled up as much as original portrait does --and most importantly in Detector mode (localize button) the bounding boxes that are drawn and the displayed image match in size.

REASONING: This all had to do with oddly the fact that this base code we inherited from TF Lite only allows the Android Camera 2 api use (supported since Android 5) if the hardware is FULLY compliant which an emulator can not be and many devices (like my android phone) are not. Its odd because there is no inherent use of the camera hardware that requires full features like focusing from software etc. Very odd. I forced the code (not good) to test if the classes under a camera 2 api acceptance situation would work on my device and they seem to ....so, going to leave the code as is...But, frankly it took so long as I assumed were using the newer camera api classes and only found out belated they did not.

THE FIX: Inside LegacyCameraConnectionFragment.java there is an annonymous inner class for

surfaceTextureListener = new TextureView.SurfaceTextureListener() {

handling the display of the images captured by camera of device using the associated TextureView widget (AutoFitTextureView.java). When setting this up you must associate camera and its display orientation and the aspect ratio (width and height). These will be different for Landscape mode than portrait. The inherited code from Tf Lite example was hardcoded to portrait mode. NOW, determine device orientation and rotate the camera.setDisplayOrientation(X) to appropriate angle so the display in the associated TextureView will be oriented correctly AND also set either w,h or h,w for landscape or portrait class respectively.