Search Unity

NatCam - WebCam API

Discussion in 'Assets and Asset Store' started by Lanre, Dec 17, 2015.

?

Should we add exposure controls in v1.3? This means dropping support for iOS 7

Poll closed Jun 10, 2016.
  1. Yes

    9 vote(s)
    75.0%
  2. No

    3 vote(s)
    25.0%
  1. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    Check that you have granted camera permissions to your app.
     
  2. Rapskalian

    Rapskalian

    Joined:
    Jan 4, 2011
    Posts:
    45
    Hi @Lanre,

    I'm noticing an issue while testing out the MiniCam example scene in a completely blank Unity project. I'm building to my Samsung Galaxy S6 for testing. When I attempt to switch the camera, the preview freezes. I'm still able to interact with the UI and capture photos correctly from the proper camera (while viewing the frozen preview), but when I touch the checkmark button to dismiss the captured photo, it displays the previously frozen preview again. I can see that the camera is switching properly in adb:


    D/Unity (24434): NatCam: Camera 0 started session
    D/Unity (24434): NatCam: Camera 0 stopped session
    D/Unity (24434): NatCam: Camera 1 started session
    D/Unity (24434): NatCam: Camera 1 stopped session
    D/Unity (24434): NatCam: Camera 0 started session
    D/Unity (24434): NatCam: Camera 0 stopped session
    D/Unity (24434): NatCam: Camera 1 started session


    The only workaround I've found is to open the application switcher on Android (which pauses the app), and then re-enter the MiniCam application. That seems to re-initialize the preview. What other info would be helpful to you?
     
  3. Rapskalian

    Rapskalian

    Joined:
    Jan 4, 2011
    Posts:
    45
    @Lanre I'm also observing the exact same issue on the Samsung Galaxy S9 that I borrowed.
     
  4. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    This is a known issue, and we've fixed it in the upcoming version. If you need the fix ASAP, then email me your invoice number and I'll send you my current build of 2.1.
     
  5. caglarenes

    caglarenes

    Joined:
    Jul 9, 2015
    Posts:
    31
    Is it possible to control seperatelly ISO, shutter speed or aperture (I know aperture not changeable for most phones) with NatCam?
     
  6. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    NatCam currently doesn't expose any of these controls. We do plan to do so very soon (we're implementing a newer Android backend).
     
  7. caglarenes

    caglarenes

    Joined:
    Jul 9, 2015
    Posts:
    31
    Oh good news. Especially shutter speed control would be a game changer for our projects :)
     
    Lanre likes this.
  8. Edsart

    Edsart

    Joined:
    Mar 1, 2017
    Posts:
    2
    Hi
    I'm getting some problems with setting the exposure bias and focusmode on android. Both of these functions work on ios devices. It seems to be stuck in autofocus mode and i cant change the exposurebias.
    Could you help me solve this issue?

    I experience this issue on a galaxy S8 on Android 8.0.0 and galaxy Note 5 on Android 5.1.1.

    I initialise the camera in the startmethod with the following parameters.
    Code (CSharp):
    1.          
    2.   NatCam.Camera = DeviceCamera.RearCamera;
    3.             NatCam.Camera.PreviewResolution = CameraResolution._1920x1080;
    4.             NatCam.Camera.PhotoResolution = CameraResolution.Highest;
    5.             NatCam.Camera.Framerate = 30;
    6.             NatCam.Camera.ExposureMode = ExposureMode.Locked;
    7.             NatCam.Camera.FocusMode = FocusMode.TapToFocus;
    8.             NatCam.OnStart += OnCameraStart;
    9.             NatCam.Play();
    I change the exposuremode with:
    Code (CSharp):
    1.             NatCam.Camera.ExposureBias = Mathf.Clamp(bias, NatCam.Camera.MinExposureBias, NatCam.Camera.MaxExposureBias);
    2.  
    When running the application on android, i receive the following messages in logcat

    D/Unity (28050): NatCam: Inspected device: Found 2 cameras
    I/Unity (28050): NatCam: Initialized NatCam 2.0 Android backend
    I/Unity (28050): UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
    I/Unity (28050): UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    I/Unity (28050): UnityEngine.Logger:Log(LogType, Object)
    I/Unity (28050): UnityEngine.Debug:Log(Object)
    I/Unity (28050): NatCamU.Core.Platforms.NatCamAndroid:.ctor() (at /Users/e.boelens/Projects/Lexis/Assets/NatCam/Plugins/Managed/Platforms/NatCamAndroid.cs:71)
    I/Unity (28050): NatCamU.Core.NatCam:.cctor() (at /Users/e.boelens/Projects/Lexis/Assets/NatCam/Plugins/Managed/NatCam.cs:175)
    I/Unity (28050): System.Object:__icall_wrapper_mono_generic_class_init(IntPtr)
    I/Unity (28050): NatCamU.Core.DeviceCamera:get_Device() (at /Users/e.boelens/Projects/Lexis/Assets/NatCam/Plugins/Managed/DeviceCamera.cs:147)
    I/Unity (28050): NatCamU.Core.DeviceCamera:get_IsFrontFacing() (at /Users/e.boelens/Projects/Lexis/Assets/NatCam/Plugins/Managed/DeviceCamera.cs:22)
    I/Unity (28050): NatCamU.Core.DeviceCamera:<DeviceCamera>m__0(DeviceCamera) (at /Users/e.boelens/Projects/Lexis/Assets/NatCam/Plugin
    D/Unity (28050): NatCam: Changed camera 0 resolution to 1920x1080
    D/Unity (28050): NatCam: Changed camera 0 photo resolution to 5312x2988
    D/Unity (28050): NatCam: Changed camera 0 framerate to 30000
    E/Unity (28050): NatCam Error: Failed to set camera 0 focus mode to 1
    D/Unity (28050): NatCam: Camera 0 started session
    D/Unity (28050): SendMessage: object Body not found!
    D/Unity (28050): NatCam Rendering: Created ES3 GLRenderContext
    D/Unity (28050): NatCam: Detected first frame flag with preview size: 1920x1080 orientation: Portrait
    D/Unity (28050): NatCam: Exposing camera 0 to 0EV clamped from 0EV requested
     
  9. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    There's a really weird thing on Android where you can't set `TapToFocus` solely because most cameras don't support it. You have to set both `TapToFocus` and `AutoFocus` like so:
    Code (CSharp):
    1. NatCam.Camera.FocusMode = FocusMode.TapToFocus | FocusMode.AutoFocus;
    Since you are clamping the bias before setting, chances are that the camera is reporting its min or max or both biases as 0. Try Debug.Logging both of them and seeing what the values are.
     
  10. Edsart

    Edsart

    Joined:
    Mar 1, 2017
    Posts:
    2
    Thanks for the help, setting the exposure now works on android. Setting the bias once before accessing the min/max values seems to do the trick.

    TapToFocus also works when combined with autofocus, but the autofocus makes the tap redundant. When i manually focus on a specific part on the screen, it sets the focus automatically back to the center after about half a second. Is there a way to use TapToFocus without using autofocus on android?
     
  11. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    As I mentioned in my last post, most devices cameras don't support setting TapToFocus as the only focus mode. TapToFocus and AutoFocus together is the most widely supported mode.
     
  12. Timboc

    Timboc

    Joined:
    Jun 22, 2015
    Posts:
    34
    Hi there, after doing some searching through forums I found that NatCam "WebCamAPI" does indeed support pc/windows which I was very pleased about. I purchased this for the sole reason of being able to lock the exposure of my web camera - however after importing and setting DeviceCamera.ExposureMode / Bias I received the error 'Exposure is not supported on legacy'. After further googling it sounds like 'Legacy' is the platform used on non-ios/android?
    Is there any way to lock the exposure of a web camera on Windows? I'm really hoping there's something I've missed as locking the exposure is fundamental to what I'm trying to achieve.
     
  13. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    Hi there. NatCam does not natively support Windows, so functions like focus and exposure don't work. If you don't have any use for NatCam because of this, email me your invoice and I'll request a refund from Unity.
     
  14. taejinha

    taejinha

    Joined:
    Jul 20, 2015
    Posts:
    4
    Hi, I need to decode barcode.
    And I found the video "NatCam Snippets - E5 - Barcodes"
    So I bought the NatCam Asset.
    However the asset was different with the video. (different class name, function name...)
    How Can I use barcode decoder?
     
  15. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    We removed barcode detection a long time ago. On the Asset Store page, there is no mention of barcode detection. You can use the free ZXing.NET library with NatCam for barcode detection.
     
  16. E-Matching

    E-Matching

    Joined:
    Aug 23, 2018
    Posts:
    4
    Hello,
    I've just purchased NatCam, but i can't build my project anymore. Here is what i have when trying to build:

    Exception: Unknown CPU architecture for library Assets/NatCam/Plugins/iOS/libNatCamRenderPipeline.a
    UnityEditor.Android.PostProcessor.Tasks.NativePlugins.ProcessPlugin (UnityEditor.Android.PostProcessor.PostProcessorContext context, System.String pluginPath, System.String pluginTargetCPU)
    UnityEditor.Android.PostProcessor.Tasks.NativePlugins.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report)
    UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties)
    UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTargetGroup targetGroup, BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:287)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    I'e just imported the asset and nothing else.

    Thank you
     
  17. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    Hi there. Navigate to the library in the Editor and select it. In the inspector, make sure that the library only applies to iOS and not any other platforms.
     
  18. MultivariousDev01

    MultivariousDev01

    Joined:
    May 22, 2014
    Posts:
    17
    EDIT: Figured I should mention, this is happening on NatCam 2.0f4 from the Asset Store.

    Hello! Just want to start out by saying how much I appreciate what NatCam is doing.

    I've been chasing a weird Android freeze bug for almost two weeks now every time I go to start up NatCam on Android.

    I finally managed to logcat some of what I'm seeing.

    I'm really not sure what I'm doing wrong here. I'm trying to use NatCam as the camera background for an otherwise very simple Google Cardboard (GoogleVR, really) app that simply puts overlays over the AR stereo image.

    Everything I'm doing seems to work perfectly fine on iOS. I have disabled ES 2, and am really burning short on the list of possibilities. I hope you can help shine some insight!


    09-06 21:12:30.387 16884 16903 E Unity : NatCam Error: Failed to open camera 0 with error: Fail to connect to camera service
    09-06 21:12:30.388 16884 16903 E Unity : NatCam Error: Failed to open camera 1 with error: Fail to connect to camera service
    09-06 21:12:30.389 16884 16903 D Unity : NatCam: Inspected device: Found 2 cameras
    09-06 21:12:30.394 16884 16903 I Unity : NatCam: Initialized NatCam 2.0 Android backend


    09-06 21:12:37.493 16884 16903 E Unity : AndroidJavaException: java.lang.NullPointerException: Attempt to read from field 'int android.hardware.Camera$Size.width' on a null object reference
    09-06 21:12:37.493 16884 16903 E Unity : java.lang.NullPointerException: Attempt to read from field 'int android.hardware.Camera$Size.width' on a null object reference
    09-06 21:12:37.493 16884 16903 E Unity : at com.yusufolokoba.natcam.NatCamDevice.getPreviewWidth(NatCamDevice.java:283)
    09-06 21:12:37.493 16884 16903 E Unity : at com.yusufolokoba.natcam.NatCam.play(NatCam.java:61)


    09-06 20:52:25.132 15028 15047 E Unity : AndroidJavaException: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List android.hardware.Camera$Parameters.getSupportedPreviewFpsRange()' on a null object reference
    09-06 20:52:25.132 15028 15047 E Unity : java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List android.hardware.Camera$Parameters.getSupportedPreviewFpsRange()' on a null object reference
    09-06 20:52:25.132 15028 15047 E Unity : at com.yusufolokoba.natcam.Utilities.ClosestFramerate(Utilities.java:40)
    09-06 20:52:25.132 15028 15047 E Unity : at com.yusufolokoba.natcam.NatCamDevice.setFramerate(NatCamDevice.java:136)


    Here's a "cleaner" log from a different (worse) device, of the same issue. At this point, I'm really only trying to start NatCam... If I try to change the FPS or the exposure/focus modes, then the error messages will relate to those functions instead, so I've commented it all out for now.

    D/Unity (18967): NatCam: Inspected device: Found 2 cameras
    I/Unity (18967): NatCam: Initialized NatCam 2.0 Android backend
    I/Unity (18967): (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    E/Unity (18967): AndroidJavaException: java.lang.NullPointerException: Attempt to invoke virtual method 'com.yusufolokoba.natcam.NatCamDevice com.yusufolokoba.natcam.NatCamDevice.open()' on a null object reference
    E/Unity (18967): java.lang.NullPointerException: Attempt to invoke virtual method 'com.yusufolokoba.natcam.NatCamDevice com.yusufolokoba.natcam.NatCamDevice.open()' on a null object reference
    E/Unity (18967): at com.yusufolokoba.natcam.NatCam.play(NatCam.java:60)
    E/Unity (18967): at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    E/Unity (18967): at com.unity3d.player.UnityPlayer.c(Unknown Source)
    E/Unity (18967): at com.unity3d.player.UnityPlayer$e$2.queueIdle(Unknown Source)
    E/Unity (18967): at android.os.MessageQueue.next(MessageQueue.java:221)
    E/Unity (18967): at android.os.Looper.loop(Looper.java:131)
    E/Unity (18967): at com.unity3d.player.UnityPlayer$e.run(Unknown Source)
    E/Unity (18967): at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0
    E/Unity (18967): at UnityEngine.AndroidJNISafe.CallVoidMethod (IntPtr obj, IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <filename unknown>:0
    E/Unity (18967): at UnityEngine.AndroidJavaObjec
    D/Unity (18967): NatCam Rendering: Created ES3 GLRenderContext
     
    Last edited: Sep 7, 2018
  19. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    Can you attach the full logs from logcat (not filtering for Unity tags) in a .txt file? The full logs will mention exactly why NatCam can't access any of the cameras.
     
  20. DynastyV

    DynastyV

    Joined:
    Mar 16, 2015
    Posts:
    14
    Are the FOV properties measuring the FOV of the preview or of the actual photo captured by the camera? If the aspect ratio of the preview differs from what the camera captured, does NatCam do any cropping?
     
  21. MultivariousDev01

    MultivariousDev01

    Joined:
    May 22, 2014
    Posts:
    17
    Hey, no prob, here!

    Just to make sure there's no other differences, I included one log from our GoogleVR stereoscopic screen scene, and one from the non-VR full-screen camera scene.

    I'm also using mono right now for iteration-speed purposes, but the issue seems to happen on IL2CPP and 64-bit android as well.
     

    Attached Files:

  22. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    On iOS, the horizontal FOV is gotten directly from the camera whereas the vertical FOV is calculated from the hFOV and aspect ratio. On Android, both horizontal and vertical FOV's are gotten directly from the camera. In both cases, the FOV applies only to the preview; we don't have a way to get the FOV of the photo. NatCam doesn't do any cropping.
     
  23. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    I need the full logs. You are starting logcat like this:
    Code (CSharp):
    1. .\adb logcat -s Unity ActivityManager PackageManager dalvikvm DEBUG
    You need to start it like this:
    Code (CSharp):
    1. .\adb logcat
     
  24. MultivariousDev01

    MultivariousDev01

    Joined:
    May 22, 2014
    Posts:
    17
    Oh, super sorry! Yeah I just blindly used my typical debugging command that I found in a Unity forum somewhere.

    Attached the full log... Well, I had to pipe it straight to a file because it was too much for my shell, but hope this is what you need!
     

    Attached Files:

  25. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    It seems like you didn't set a camera before calling NatCam.Play. Can you check your code, or share it so I can look over it?
     
  26. MultivariousDev01

    MultivariousDev01

    Joined:
    May 22, 2014
    Posts:
    17
    OK, you have a point there. I got so desperate to track this bug down that I had taken out the m_CurrentDeviceCamera reference that I set earlier from the call to Play(DeviceCamera). I saw that that function had a default parameter of "null" so I figured that was a way to tell NatCam to just use an arbitrary camera.

    I just forgot to reset before I ran this test!

    I have my script set up so that it won't even call Play if the m_CurrentDeviceCamera reference is null.

    Here's the two functions in question that get called for setup. I have registered for the NatCam OnStart event and use it to do aspect ratio work and the like.

    I have also attached another log, where the code being run matches this code, instead of being my flawed debugging attempt.

    This code doesn't seem to freeze/crash on Play on every device... just most of them. When I ran it just now, it didn't freeze, but maybe the logs might show some relative funny-business?

    Thanks so much for looking into this!!
    (SetUpForDeviceCamera gets called by a life-cycle script, and based on its response, it calls the other function afterwards)
    Code (CSharp):
    1.     public string SetUpForDeviceCamera(bool allowFrontFacingCam)
    2.     {
    3.         if (!Application.HasUserAuthorization(UserAuthorization.WebCam))
    4.         {
    5.             return "Failed to get webcam authorization!\nYou may need to manually provide permission in your device settings.\n\nReturning to Main Menu in 5 seconds...";
    6.         }
    7.         if (DeviceCamera.RearCamera == null && (allowFrontFacingCam && DeviceCamera.FrontCamera == null))
    8.         {
    9.             return "Could not find suitable DeviceCamera to use!\n\nReturning to Main Menu in 5 seconds...";
    10.         }
    11.         if(DeviceCamera.RearCamera != null)
    12.         {
    13.             m_CurrentDeviceCamera = DeviceCamera.RearCamera;
    14.             LastSetDeviceCamera = DeviceCamera.RearCamera;
    15.         }
    16.         else if(allowFrontFacingCam && DeviceCamera.FrontCamera != null)
    17.         {
    18.             m_CurrentDeviceCamera = DeviceCamera.FrontCamera;
    19.             LastSetDeviceCamera = DeviceCamera.FrontCamera;
    20.         }
    21.         /* TODO: if want to use this logic, need to capture tap events and call focusing logic
    22.         if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.Equals(AppUtilities.SINGLE_SCREEN_SCENE_NAME))
    23.         {
    24.             m_CurrentDeviceCamera.FocusMode = FocusMode.TapToFocus;
    25.         }
    26.         */
    27.         if (VSPAppToolbox.RegisterComponent<UserDataManager>().UsingHighQuality)
    28.         {
    29.             m_CurrentDeviceCamera.Framerate = 60f;
    30.         }
    31.         else
    32.         {
    33.             m_CurrentDeviceCamera.Framerate = 30f;
    34.         }
    35.         m_CurrentDeviceCamera.FocusMode = FocusMode.AutoFocus;
    36.         // Autoexposure seems to cause especially-noticeable issues in low-quality mode
    37.         m_CurrentDeviceCamera.ExposureMode = ExposureMode.AutoExpose;
    38.         return "";
    39.     }
    40.  
    41.     public bool StartDeviceCameraFeed ()
    42.     {
    43.         if(m_CurrentDeviceCamera == null)
    44.         {
    45.             Debug.LogError("NatCamRawImage: Must call SetUpForDeviceCamera before calling StartDeviceCameraFeed!");
    46.             return false;
    47.         }
    48.         if(!NatCam.IsPlaying || m_ShouldBePaused)
    49.         {
    50.             NatCam.Play(m_CurrentDeviceCamera);
    51.         }
    52.         return true;
    53.     }
    Just to be clear, I can't get this freeze on Play to occur on my current device... It's an HTC One, and actually it sounds like the clients report all of the HTC devices seem OK. Our client reports that the Google Pixels and most other device types are freezing. However, this device seems to crash consistently at some point after Play, or when trying to leave the NatCam scene... I will try to send you a log of a freezing Pixel tomorrow.

    In this post, logcat-2 is a log of "normal execution" and logcat-3 should contain crash data, which may be purely resource-based and have nothing to do with NatCam.
     

    Attached Files:

    Last edited: Sep 10, 2018
  27. MultivariousDev01

    MultivariousDev01

    Joined:
    May 22, 2014
    Posts:
    17
    Heyyy Lanre, I got a real crash log, and it looks to my eyes to be entirely a camera permissions issue.

    This is a bit confusing to me, as previous iterations of this app were appearing to come in with camera permissions already enabled. Also the app would have to get through a block like this:
    Code (CSharp):
    1.          
    2. if (Application.HasUserAuthorization(UserAuthorization.WebCam) == false)
    3.             {
    4.                 yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
    5.  
    6.                 if (Application.HasUserAuthorization(UserAuthorization.WebCam) == false)
    7.                 {
    8.                     CameraDeviceInitState = SubserviceState.ERROR;
    9.                     ReportErrorAndReturnToMenu("Failed to get webcam authorization!\nYou may need to manually provide permission in your device settings.");
    10.                     yield break;
    11.                 }
    12.             }
    13.  
    ... before it ever got to the point of actually running NatCam.Play.

    So presumably, Application.HasUserAuthorization(WebCam) is returning true. But voila, when I checked the device settings, I absolutely did need to manually provide camera permissions. The app never warns me and it doesn't seem to have a problem skipping right over the UserAuthorization bit to call NatCam.Play.

    I know there are issues with using RequestUserAuthorization and that it doesn't seem to work these days... Do you have any idea what might be causing this? I have some Google VR-related Android Manifests in my project that came in through the current official GoogleVR for Unity plugin. Would that be causing trouble? What would you recommend?

    Attached a copy of this crash log for your perusal as well.

    Many many thanks!

    EDIT: went ahead and attached the AndroidManifest.xml that appears post-compilation.
     

    Attached Files:

    Last edited: Sep 11, 2018
  28. MultivariousDev01

    MultivariousDev01

    Joined:
    May 22, 2014
    Posts:
    17
    Sorry for the triple-post!

    [EDIT x3: Deleted this part because it's inconsequential]

    EDIT: looks like your examples, and NatCam as a whole, rely on Unity Android asking for camera permissions on app start... Which is totally not happening at all for my builds... Android devices less than 6 never ask and just give permissions implicitly, and 6 and up also seem to never ask, but also never give permissions.

    EDIT x2: I think I found it! I believe that the GoogleVR plugin is adding unityplayer.SkipPermissionsDialogue = "true" to the built APK's Android Manifest. (I stumbled upon that possibility here: https://github.com/googlevr/gvr-unity-sdk/issues/683 )

    I've updated my custom manifest to explicitly set that to "false"... gonna see how it goes.

    EDIT x3: That seemed to work!!! So yeah, watch out for GoogleVR suppressing the permissions dialogue in the manifest.
     
    Last edited: Sep 11, 2018
  29. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    I'm so sorry for the late response. It looks like you've figured it out though. Be sure to let me know if you face any other issues.
     
  30. DynastyV

    DynastyV

    Joined:
    Mar 16, 2015
    Posts:
    14
    So I should be using the FOV measurements in conjunction with NatCam.Preview.height and NatCam.Preview.width? This doesn't make much sense if the FOV is obtained directly from the camera API. Do I have to adjust the FOV measurement if I want to know the FOV of the preview? I'm currently only working on an Android app, but I'm planning on supporting iPhone as well.
     
  31. DynastyV

    DynastyV

    Joined:
    Mar 16, 2015
    Posts:
    14
    I was under the impression that the preview size could be set to any arbitrary number of pixels, and that the camera image would be scaled and cropped appropriately. Is that how NatCam works?
     
  32. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    No. Cameras have a fixed set of preview resolutions. When you request a resolution, NatCam finds the closest supported resolution to what you've requested. The FOV reported by the camera updates based on the active preview resolution.
     
  33. MultivariousDev01

    MultivariousDev01

    Joined:
    May 22, 2014
    Posts:
    17
    Does it save on power to lower the NatCam device camera frame rate directly? I lower the overall Application.targetFrameRate during periods of inactivity, and was wondering if that automatically throttled NatCam, or if NatCam is still trying to get 60 frames per second from the camera through means independent of the application frame rate.
     
  34. SniperED007

    SniperED007

    Joined:
    Sep 29, 2013
    Posts:
    139
    In Linear lighting the Camera Preview is a lot lighter than the actual photo that gets taken, is there a setting to change to get it to match like it does in Gamma Color Space?
     
  35. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    Yes, it is more energy efficient to use a 30FPS preview. If you reduce Application.targetFrameRate to say 30 while NatCam is running at 60FPS, NatCam will update the preview texture twice per application frame whereas the user can only see one update; the camera will be doing more work all for half of its work to be wasted.
     
  36. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    NatCam doesn't support linear lighting. You can inspect the managed sources under NatCam > Plugins > Managed > Platforms for how each platform's implementation creates the preview texture.
     
  37. SniperED007

    SniperED007

    Joined:
    Sep 29, 2013
    Posts:
    139
    Thanks, I updated this line in the OnStart function in NatCamAndroid.cs to support Linear:
    instance.preview = Texture2D.CreateExternalTexture(width, height, TextureFormat.RGBA32, false, true, texPtr);

    And I updated this line in the OnPhoto function in NatCamAndroid.cs:
    var photo = new Texture2D(width, height, TextureFormat.RGBA32, false, true);

    After doing that both the preview and the photo that was taken match but both are too white.
    If I update both lines above and set it to false then the preview still shows as white and the camera and nice and vivid.
    So not sure why the preview still shows up as too white.
     
  38. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    As I mentioned, NatCam doesn't support linear rendering. This is why the preview remains white even if you toggle the linear flag.
     
  39. DynastyV

    DynastyV

    Joined:
    Mar 16, 2015
    Posts:
    14
    I'm having a freezing issue as well. I've been pulling my hair out for days now trying to debug the crash, which seems to happen consistently about 5-10 seconds after launch. I've finally tracked the problem down to the CaptureFrame function in NatCamAndroid.cs, line 115
    NatCamBridge.InvertFrame(handle.AddrOfPinnedObject());
    . The invocation of InvertFrame never returns and ends up freezing Unity.

    Code (CSharp):
    1.         public void CaptureFrame (byte[] pixels, bool flip) {
    2.             // Handle flip specially
    3.             if (flip) {
    4.                 var handle = GCHandle.Alloc(pixels, GCHandleType.Pinned);
    5.                 NatCamBridge.InvertFrame(handle.AddrOfPinnedObject()); // CRASH HAPPENS HERE
    6.                 handle.Free();
    7.             } else {
    8.                 IntPtr ptr;
    9.                 NatCamBridge.CaptureFrame(out ptr);
    10.                 if (ptr == IntPtr.Zero) return; // Only happens in frame when app is suspended
    11.                 Marshal.Copy(ptr, pixels, 0, preview.width * preview.height * 4);
    12.             }
    13.         }
    The device I'm using is a Pixel 2 running Android P. If I flip the frame in OpenCV instead, the game does not crash.
     
  40. Soaryn

    Soaryn

    Joined:
    Apr 17, 2015
    Posts:
    232
    I started looking through the thread in hopes to find if NatCam would be a lower latency and more crisper capture of my capture card; however, I decided to stop at page around 10 when 'windows' started to be used like candy as a keyword :p

    EDIT: Having looked up a little bit (starting from end rather than beginning) I noticed it was mentioned that Windows is not natively supported :(

    So the questions wind up being:
    1. Is windows native created yet, or is it still defaulting to WebCamTexture?
    2. How does it render out? Does it capture to a Texture or? (More or less looking to apply a shader to the end result)
    Ideally, I need a crisper and smoother video source than what WebCamTexture is presenting with
     
    Last edited: Sep 17, 2018
  41. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    Can you upload the full logs from logcat? I'm curious to see why it is freezing. I have had reports of this issue in the past.
     
  42. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    On Windows, NatCam falls back to WebCamTexture.
    On iOS and Android, we upload the preview data to a native texture. On other platforms, we use a WebCamTexture.
     
  43. Soaryn

    Soaryn

    Joined:
    Apr 17, 2015
    Posts:
    232
    Drat, I can't seem to figure a good way to get 1080p60 from my capture card in unity. Constantly has a microstutter that isn't present in say programs such as OBS
     
  44. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    Hm. Try increasing your application's framerate to 60 and requesting 60FPS in the WebCamTexture constructor.
     
  45. Soaryn

    Soaryn

    Joined:
    Apr 17, 2015
    Posts:
    232
    Attempted, but to no avail.

    Every once and a while, WebCam.UploadTexture takes just enough time to throw off the smoothness of the render.
    I think the biggest issue is that all of this is on the same thread :\ and if at anypoint any of these things take just a tinge to long, it becomes very apparent.

    If I move my hand rather slowly, you can see it jump from one location to the next. I'm really hoping they don't have something in the back-end that is attempting to be "clever"
     
  46. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    I'm not too sure. It might be useful to create a new thread to ask Unity devs about this.
     
  47. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    831
    Hi Lanre, ReplayKit + Microphone recording... the microphone recording playback seems to have audio that sounds damaged/stilted (tiny breaks)? How do we record a smooth microphone sound?
     
  48. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    831
    Is this possible: Video Recording but omit recording the camera button?
     
  49. karmatha

    karmatha

    Joined:
    Aug 25, 2012
    Posts:
    32
    Hi @Lanre is there a way to get the pixel data of the preview on iOS and Android? A way without having create a temporary texture, blit the `NatCam.Preview` there, create a new Texture2D, ready the pixel data from the temporary texture into that, applying it and only THEN call `GetPixels32()` on that... it's kinda slow that.
     
  50. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,667
    This is an issue with Unity's Microphone API. File a bug report with Unity.
     
    ina likes this.