AR toolkit work in portrait mode???

Community support forum for the ARToolKit v5.x for Android SDK.
latigo_mc
Posts: 9
Joined: Mon Oct 17, 2016 1:10 am

AR toolkit work in portrait mode???

Postby latigo_mc » Sun Oct 30, 2016 7:42 pm

Hi bros,
I'm working with nftsimpleproj, how can i make it work properly in portrait mode?
-->
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // Force landscape-only.
-->
currently, if i set it to PORTRAIT the cubic has wrong position(90 degree rotation)
Thanks,

zia khan
Posts: 6
Joined: Sat Feb 20, 2016 11:20 pm

Re: AR toolkit work in portrait mode???

Postby zia khan » Tue Nov 08, 2016 8:19 am

you will have change aRBaseLib project's surfaceChange method in CaptureCameraPreview class.

Code: Select all

@SuppressWarnings("deprecation") // setPreviewFrameRate, getPreviewFrameRate
   @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
       
       if (camera == null) {          
          // Camera wasn't opened successfully?
          Log.e(TAG, "No camera in surfaceChanged");
          return;          
       }
       
       Log.i(TAG, "Surfaced changed, setting up camera and starting preview");
       
        String camResolution = PreferenceManager.getDefaultSharedPreferences(getContext()).getString("pref_cameraResolution",    getResources().getString(R.string.pref_defaultValue_cameraResolution));
        String[] dims = camResolution.split("x", 2);
        Camera.Parameters parameters = camera.getParameters();
        parameters.setPreviewSize(Integer.parseInt(dims[0]), Integer.parseInt(dims[1]));
        parameters.setPreviewFrameRate(30);

        //added by zia khan
        Display display = ((WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

        if(display.getRotation() == Surface.ROTATION_0)
        {
//            parameters.setPreviewSize(h, w);
            camera.setDisplayOrientation(90);
        }

        if(display.getRotation() == Surface.ROTATION_90)
        {
//            parameters.setPreviewSize(w, h);
        }

        if(display.getRotation() == Surface.ROTATION_180)
        {
//            parameters.setPreviewSize(h, w);
        }

        if(display.getRotation() == Surface.ROTATION_270)
        {
//            parameters.setPreviewSize(w, h);
            camera.setDisplayOrientation(180);
        }
        //zia khan
        String cameraOn = PreferenceManager.getDefaultSharedPreferences(getContext()).getString("pref_cameraIndex", "0");
        if (cameraOn.equals("0")) {
//            parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
        }
        camera.setParameters(parameters);
       
        parameters = camera.getParameters();
        captureWidth = parameters.getPreviewSize().width;
        captureHeight = parameters.getPreviewSize().height;
        captureRate = parameters.getPreviewFrameRate();
        int pixelformat = parameters.getPreviewFormat(); // android.graphics.imageformat
        PixelFormat pixelinfo = new PixelFormat();
        PixelFormat.getPixelFormatInfo(pixelformat, pixelinfo);
        int cameraIndex = 0;
        boolean cameraIsFrontFacing = false;
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
         Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
         cameraIndex = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getContext()).getString("pref_cameraIndex", "0"));
         Camera.getCameraInfo(cameraIndex, cameraInfo);
         if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) cameraIsFrontFacing = true;
      }
       
      int bufSize = captureWidth * captureHeight * pixelinfo.bitsPerPixel / 8; // For the default NV21 format, bitsPerPixel = 12.
      Log.i(TAG, "Camera buffers will be " + captureWidth + "x" + captureHeight + "@" + pixelinfo.bitsPerPixel + "bpp, " + bufSize + "bytes.");
      cameraWrapper = new CameraWrapper(camera);       
        cameraWrapper.configureCallback(this, true, 10, bufSize); // For the default NV21 format, bitsPerPixel = 12.

        camera.startPreview();

        if (listener != null) listener.cameraPreviewStarted(captureWidth, captureHeight, captureRate, cameraIndex, cameraIsFrontFacing);

    }

grire974
Posts: 9
Joined: Thu Dec 01, 2016 6:52 am

Re: AR toolkit work in portrait mode???

Postby grire974 » Thu Dec 01, 2016 7:02 am

@zia khan thanks for the info; any tricks for re-compiling it? As far as I can tell, I need to open the ARBaseLibProj folder in Android Studio; make the changes you mention above and then choose 'Build Module'; take the aRBaseLib-debug.aar file in the build/outputs folder of ARBaseLibProj, and then paste it into the arBaseLib sub folder of the project that I'm working in (in this case nftBookProj).

When I do this however I get a gradle build error that I can't get past from within the sample project that I'm working in (nftBookProj):

Error converting from bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'

Of course - the target & source compatibility configs are already there; so that doesn't help; looked at other forums on the topic of the error and tried things like changing the project jdk path and ndk path; downgrading to AS 2.1 etc. etc. none work. But wanted to make sure I had the procedure correct in the first place - would love to hear your thoughts!

grire974
Posts: 9
Joined: Thu Dec 01, 2016 6:52 am

Re: AR toolkit work in portrait mode???

Postby grire974 » Thu Dec 01, 2016 7:51 am

Update:

I've been able to get around the dex error by actually changing the targetCompatibility and sourceCompatibility settings in build.gradle to 1.8; go figure... Also had to enable jackOptions in build.gradle and upgrade build tools to v 25.

However, I can't see @zia khan's code take any effect; still the same result; have tried using log statements to see if the various code blocks are being called; it would seem none of them are.

Senador
Posts: 57
Joined: Mon Oct 05, 2015 12:36 am

Re: AR toolkit work in portrait mode???

Postby Senador » Mon Dec 05, 2016 4:04 am


zia khan
Posts: 6
Joined: Sat Feb 20, 2016 11:20 pm

Re: AR toolkit work in portrait mode???

Postby zia khan » Mon Dec 05, 2016 7:44 am

i am not using aRBaseLib-debug.aar, i have the ARBaseLib as dependency module in my main project.

zia khan
Posts: 6
Joined: Sat Feb 20, 2016 11:20 pm

Re: AR toolkit work in portrait mode???

Postby zia khan » Mon Dec 05, 2016 11:01 pm

i can confirm that this method only works in Samsung devices, i have checked it on Note 3 and S5, but on Nexus 5x the preview is upside down.

grire974
Posts: 9
Joined: Thu Dec 01, 2016 6:52 am

Re: AR toolkit work in portrait mode???

Postby grire974 » Tue Dec 06, 2016 3:15 pm

Ah I see.. thanks for clarifying; I think you can add Galaxy s7 to the not working list for that approach; but good to know at least that I should research other options.

@Senador - thanks for the link; it eventually references some CSharp for a Unity fix; don't suppose you've seen a Java/AS fix floating around for this?

amalcao
Posts: 6
Joined: Thu Jan 05, 2017 2:52 am

Re: AR toolkit work in portrait mode???

Postby amalcao » Sun Feb 26, 2017 8:55 pm

See here https://github.com/artoolkit/artoolkit5/issues/259, maybe it could help you.


Return to “ARToolKit for Android”

Who is online

Users browsing this forum: No registered users and 2 guests