Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

WebcamTexture autofocus solution

Discussion in 'Android' started by JeremyLefevreLS, Apr 15, 2016.

  1. JeremyLefevreLS

    JeremyLefevreLS

    Joined:
    Apr 15, 2016
    Posts:
    1
    Hello,

    I work on a barcode reader for a few days.
    I made an algorithm that work well but I had a problem with WebcamTexture: the autofocus!
    I needed to wait loo long to have a sharp image...

    I know many people have the same problem so here is a solution!
    /!\ Warning: This is a hack level 9000, but it's the only solution that worked for me...

    First you need DexManager:
    http://forum.xda-developers.com/android/software/tool-dex-manager-v1-0-designed-to-play-t2988532

    This software can decompile .dex files, the equivalent of .jar files for Android.

    Decompile the file:
    "Unity install folder"\Editor\Data\PlaybackEngines\androidplayer\Variations\mono\Release\Classes\classes.dex

    In the sources, browse for "a.smali", it's the CameraManager class. If this is not the correct file search a file that contains "android/hardware/Camera", it's must be the only one.

    In this file, find the text "continuous-video". It's the autofocus mode that Unity uses by default. Replace all occurrences by "continuous-picture".

    Recompile the .dex file with DexManager and replace the one in Unity install folder with it.

    Now when you package your .apk, Unity will use the new .dex with a nice autofocus.

    Enjoy!
     
  2. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,957
    Neat trick! Also, you should consider using NatCam. It features 4 different focus modes and fast barcode detection.
     
  3. juliumpi

    juliumpi

    Joined:
    Mar 1, 2023
    Posts:
    1
    When will it be available again?