tensorflow: Android Demo DetectorActivity landscape orientation problem

I’m trying to change the orientation to landscape:

private static final Size DESIRED_PREVIEW_SIZE = new Size(1280, 720); private static final boolean USE_YOLO = true

        <activity android:name="org.tensorflow.demo.DetectorActivity"
                  android:screenOrientation="landscape"
                  android:label="@string/activity_name_detection">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

But it draws detected rects wrongly. How to fix it?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 27 (5 by maintainers)

Most upvoted comments

Just pulled the latest demo, still cannott change to landscape mode by simply changing the screenOrientation in manifest.xml, and change to auto rotate didn`t work for me @prasanna532

Here`s my work around:

In DetectorActivity: sensorOrientation = 0 - getScreenOrientation();//here change rotation to 0

In MultiBoxTracker:

final boolean rotated = sensorOrientation % 180 != 90;//here change == to !=

frameToCanvasMatrix =
ImageUtils.getTransformationMatrix(
        frameWidth,
        frameHeight,
        (int) (multiplier * (rotated ? frameHeight : frameWidth)),
        (int) (multiplier * (rotated ? frameWidth : frameHeight)),
        sensorOrientation+90,//here add 90 to degree
        false);


borderedText.drawText(canvas, trackedPos.left + cornerSize, trackedPos.top, labelString,90);//here draw from top, and modify the drawText function in env/BorderedText

In env/BorderedText:

//Add a new drawText function
public void drawText(final Canvas canvas, final float posX, final float posY, final String text, float angle) 
{
    if(angle != 0){
        canvas.rotate(angle, posX, posY);
    }
    canvas.drawText(text, posX, posY, exteriorPaint);
    canvas.drawText(text, posX, posY, interiorPaint);
    if(angle != 0){
        canvas.rotate(-angle, posX, posY);
    }
    
}

I am having some issue camera is opening only 70% to the screen Remaining 30% of the screen is black. Any suggestion or solution on how to fix that?

I’ve solved the landscape orientation problem thanks to @MICHAEL-ZENZ. However, the issue of 30% black rectangle @prasanna532 at the bottom stayed in both landscape and vertical orientations. Please, need help.

Screenshot_2020-12-29-13-13-37-219_org tensorflow lite examples detection

I solved this problem.

I have the same issue. Any luck till recently?

I’ve made a fix for this internally, should show up in the next push. You’ll still have to manually change the orientation of the Activity in AndroidManifest.xml, but everything else should just work afterwards.