You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Android Detect App does not draw overlay correctly. #10348
Have I written custom code (as opposed to using a stock example script provided in TensorFlow): [No] Further troubleshooting shows a minor change may cause this.
OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Android 7.1
TensorFlow installed from (source or binary): N/A (Nightly apk)
TensorFlow version (use command below): 1.1,1.2
Phone Hardware: Pixel C Tablet
Exact command to reproduce: Use the Detect App and move your target off centre
Describe the problem
Due to how the Detect act appears to process it's imagery and camera fragments etc it means that the overlay that's drawn drifts from the target when off centre. (Will try to post pics when I can.)
Part of this issue appears to be the fact that camera preview shown in the app is oddly cropped and squished from what the app actually sees (from debug view). Because of this, when the overlays are drawn they do not match the camera feed below. (Noticeable when your target object is towards the edge of the input)
Source code / logs
To reproduce, install the app, load up an image of a human on google images and move your camera so it's on the edge. It doesn't line up with the camera preview. Moving this from side to side helps show the problem.
I have spent many hours at work trying to understand why this is. Unfortunately I find the source code very difficult to work with and understand how it at all works. I've had to start again but I came across this bug.
@jubjamie Some screenshots would be very helpful as I don't have a device on hand to verify this with. It's possible this is a bug in how those devices report the camera or display orientation and the code mixes up width and height, or something of that nature.
When you turn on debug visualizations (using the volume keys), what do you see in the thumbnail view? It should be rendering static detections there.
@andrewharp Curiously i'm not getting the same behaviour from my 6P today. However the Pixel C is giving me trouble. It looks like it's to do with how the camera feed is displayed as it is being cropped and squished but the overlay goes on as if it hasn't it.
Using the debug view is fine and shows that the camera preview feed is being cropped as I can see much more in the debug view than the main view.
I also have a feeling that this cropping may happen because I have to force the rotation on the Pixel C as it reports the rotation to be 3 deg. I have to manually set sensorOrientation to 90 for it to capture images the correct way up.
Screenshots:
The target centred.
The target off-centre. See how the overlay "drifts". It looks like it's because the image preview camera feed has been cropped and stretched past the screen.
With debug on this time.
Notice how in the debug window we see that there is some grass to the left of the target. However in our preview window we see that the image is cut of right up to the target. However, we can see that the yellow overlay looks likes it's in the right position if we were given the debug view.
I believe that there is a problem with how the camera view is created and that it's partly to do with the screenOrientation. For some reason the Pixel C will report a rotation of 3 (in the debug view) and have the image rotated by 90 (or 87) degrees when using the default app. The only solution I have found to get the app to "see" pictures in the correct orientation is to change sensorOrientation to this:
While this appears to be partly caused by the hardware (we have tried on two different Pixel C's) there is also some kind of bug with how the camera feed is drawn. I'm really struggling to understand how it's done in the code so hopefully you can help.
@jubjamie Thanks for the details. Sounds like a bug in the device's camera implementation. 3 is obviously an invalid value for SENSOR_ORIENTATION, so maybe it makes sense to default to the most common setting of 90 when the value % 90 != 0?
However given the undesired squashing and stretching of the image it might be best just to force the pixel C to use the camera 1 API. See #8736 for a partially implemented PR -- if you patch that in, does it resolve the issue?
@andrewharp Not sure i'll get a chance to look at using camera 1 today but reading through that PR it looks like it is incomplete? Do you have any idea if it's at a usable point yet? I'm not a big java person so after going through the commit I couldn't work out if it was suitable yet. Perhaps a ping for @BrianOn99 or @osdamv ??
One concern being that from the comments it appears to remove the red debug boxes to show the results and without that i'm unable to continue troubleshooting this issue properly.
tbh I have no idea. I'm not going to have a chance to look at this now. I think that the fix doesn't apply to the detector app which is the one causing the issue. I've seen a similar issue on here somewhere but I can't remember where. Unless something has changed then I don't think it fixed the issue. To replicate, use a Pixel C and rotate the app to landscape and try to use.
I took a closer look and my initial interpretation was a bit off; I was thinking that sensorOrientation referred to camera orientation only when in fact it's a computed variable of both sensor and display rotation relative to device.
The "invalid" 3 value was actually coming from the getWindowManager().getDefaultDisplay().getRotation() call which oddly enough returns an integer constant 1-3 rather than the rotation as one might expect. In this case the actual rotation is encoded in the variable name: e.g. android.view.Surface.ROTATION_180 = 2.
Accounting for that and doing a bit of variable swapping for height/width coordinate scaling fixed the issue and now the detector demo works in both landscape and portrait mode (as soon as #14236 goes in).
Activity
andrewharp commentedon Jun 1, 2017
@jubjamie Some screenshots would be very helpful as I don't have a device on hand to verify this with. It's possible this is a bug in how those devices report the camera or display orientation and the code mixes up width and height, or something of that nature.
When you turn on debug visualizations (using the volume keys), what do you see in the thumbnail view? It should be rendering static detections there.
jubjamie commentedon Jun 1, 2017
@andrewharp Curiously i'm not getting the same behaviour from my 6P today. However the Pixel C is giving me trouble. It looks like it's to do with how the camera feed is displayed as it is being cropped and squished but the overlay goes on as if it hasn't it.
Using the debug view is fine and shows that the camera preview feed is being cropped as I can see much more in the debug view than the main view.
I also have a feeling that this cropping may happen because I have to force the rotation on the Pixel C as it reports the rotation to be 3 deg. I have to manually set sensorOrientation to 90 for it to capture images the correct way up.
Screenshots:
I believe that there is a problem with how the camera view is created and that it's partly to do with the screenOrientation. For some reason the Pixel C will report a rotation of 3 (in the debug view) and have the image rotated by 90 (or 87) degrees when using the default app. The only solution I have found to get the app to "see" pictures in the correct orientation is to change sensorOrientation to this:
sensorOrientation = 90;Instead of the default found here.
While this appears to be partly caused by the hardware (we have tried on two different Pixel C's) there is also some kind of bug with how the camera feed is drawn. I'm really struggling to understand how it's done in the code so hopefully you can help.
Thanks
jart commentedon Jun 3, 2017
Assigning to @andrewharp, to remove from triage queue.
andrewharp commentedon Jun 8, 2017
@jubjamie Thanks for the details. Sounds like a bug in the device's camera implementation. 3 is obviously an invalid value for SENSOR_ORIENTATION, so maybe it makes sense to default to the most common setting of 90 when the value % 90 != 0?
However given the undesired squashing and stretching of the image it might be best just to force the pixel C to use the camera 1 API. See #8736 for a partially implemented PR -- if you patch that in, does it resolve the issue?
jubjamie commentedon Jun 9, 2017
@andrewharp Not sure i'll get a chance to look at using camera 1 today but reading through that PR it looks like it is incomplete? Do you have any idea if it's at a usable point yet? I'm not a big java person so after going through the commit I couldn't work out if it was suitable yet. Perhaps a ping for @BrianOn99 or @osdamv ??
One concern being that from the comments it appears to remove the red debug boxes to show the results and without that i'm unable to continue troubleshooting this issue properly.
osdamv commentedon Jun 9, 2017
At the moment the stylized demo and classifier demo are working with the api 1, I am working with the detector right now
andrewharp commentedon Aug 15, 2017
@jubjamie: Is this issue still occurring after #8736?
jubjamie commentedon Aug 15, 2017
tbh I have no idea. I'm not going to have a chance to look at this now. I think that the fix doesn't apply to the detector app which is the one causing the issue. I've seen a similar issue on here somewhere but I can't remember where. Unless something has changed then I don't think it fixed the issue. To replicate, use a Pixel C and rotate the app to landscape and try to use.
andrewharp commentedon Nov 4, 2017
I took a closer look and my initial interpretation was a bit off; I was thinking that
sensorOrientationreferred to camera orientation only when in fact it's a computed variable of both sensor and display rotation relative to device.The "invalid" 3 value was actually coming from the
getWindowManager().getDefaultDisplay().getRotation()call which oddly enough returns an integer constant 1-3 rather than the rotation as one might expect. In this case the actual rotation is encoded in the variable name: e.g. android.view.Surface.ROTATION_180 = 2.Accounting for that and doing a bit of variable swapping for height/width coordinate scaling fixed the issue and now the detector demo works in both landscape and portrait mode (as soon as #14236 goes in).
Android demo: fix handling of landscape rotation mode in classifier a…