Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NatDevice - Media Device 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:
    3,969
    This is a very broad question. You must be more specific with your performance requirements (versus what performance you currently see). Firstly, you might try setting your app's Vsync to every Vblank. This might improve the framerate because NatCam's preview framerate is capped to Unity's. Secondly, increase the framerate of the DeviceCamera that you are running from. It would be very helpful if you have profiled NatCam and can reference specific behaviors in its performance that you are looking to address.
     
  2. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    48
    Hi,
    I wrote an app which uses natcam and which takes a photo. All seemed fine but sometimes I managed (so far only on Windows platform) that the NatCam.CapturePhoto(OnPhotoCapture); callback doesn't get called.
    I have a button in my app which should makes the above call, but seldomly the callback slips and then I can press the button as often as I want the callback never gets called. The camera got switched on and is indicated by the red light of the webcam it seems to work. Any idea how that can happen. I use Pause and Play and don't do a full reinitialisation which by the way seems to crash when done in the callback where the photo gets saved and it is finished saving the photo (however there is no callback to check if the photo got saved successfully). I just tried the full reinitialisation to get rid of the first bug.
    best,Robert
     
  3. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Can you share your code (preferably on on GitHub Gist)? Also, it seems like you are using an older version of NatCam. Please make sure you are updated to 1.5f3.
     
  4. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    48
    we are on the newest plugin version, however it might have been a problem on our gui side, I need to check a bit more
     
    Lanre likes this.
  5. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    Hello Lanre,
    In the previous versions there were a working utility script in order to pinch and zoom (and crop ?).
    Would it be possible to provide the same for this new version ? It will be great for designer like me ;)

    Regards,
    Seb
     
  6. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    The NatCamZoomer class has been deprecated because we added much wider support for zooming on mobile platforms; It has been made obsolete by the newer zoom API. I recommend building your own pinch-to-zoom gesture logic tailored for your application.
     
  7. TobiasW

    TobiasW

    Joined:
    Jun 18, 2011
    Posts:
    91
    Hi Lanre!

    We're currently using the WebCamTexture to do two things:
    • Render the contents into a background image via UnityEngine.UI.RawImage
    • Extract the contents via WebCamTexture.GetPixesl32 into a Colors32[] array.
    This works reasonably well on iOS, but on Android the profiler shows 15-30ms for Webcam.UploadTexture even with 1280x720.

    Can I do the same with NatCam, and would NatCam speed this up? At the beginning of the thread, you write that it got a speed up by a factor of 10 - is that still true for the current Unity implementation, or did they improve it?

    All the best,
    Tobias
     
  8. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Yes you can, and yes NatCam will provide a significant speedup. More below:
    This is very easy:
    Code (CSharp):
    1. RawImage panel;
    2. panel.texture = NatCam.Preview;
    NatCam Professional does not provide an API to do this directly. Instead, NatCam Pro provides this API:
    Code (CSharp):
    1. IntPtr buffer;
    2. int width, height, size;
    3. NatCam.PreviewBuffer(out buffer, out width, out height, out size);
    This provides a handle to the native buffer (not in managed memory) containing the preview data for the current frame. If you require a Color32[], then you can simply pin your Color32[] and perform a `memcpy` from the native buffer NatCam gives you into it.
     
  9. james14123

    james14123

    Joined:
    Jan 22, 2017
    Posts:
    20
    Hi Lanre !
    I have a question about the minicam example.
    I just added a button to change scenes and back to the minicam scene.
    But when i back to minicam, there is an error happened.
    ------
    MissingReferenceException: The object of type 'RawImage' has been destroyed but you are still trying to access it.
    ------
    How could this happened ?
    The script didn't destroy any rawimage.
    Is this a bug of NatCam?
     
  10. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    This means that the UI panel was destroyed when switching scenes. It is not a problem with NatCam. Make sure the RawImage is present in the scene (that it has been reloaded and referenced properly) before using it.
     
  11. gilead

    gilead

    Joined:
    Oct 14, 2014
    Posts:
    13
    I just today installed and tested NatCam on Android. It seemed to otherwise work fine, but there was a problem with tap to focus.

    I created a new project in Unity 5.5.2f1 and imported NatCam. Changed platform to Android, set the bundle identifier and min api level 16, enabled multithreaded rendering. Built with using MiniCam example scene.

    When running on device, the auto focus mode seems to work okay. Then I change to mode on NetCamFocuser to Tap To Focus. Running on Galaxy S7 touching on the device doesn't seem to do anything for the focus. Running with Galaxy Tab S2 brings the following error message to console whenever touching the screen:

    E Unity : NatCam Error: Camera 0 does not support focus
    I Unity : NatCam Logging: Camera 0 focus was unsuccessful
     
  12. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    That means that the camera does not support tap to focus exclusively. Try this instead:
    Code (CSharp):
    1. var focusMode = FocusMode.AutoFocus | FocusMode.TapToFocus;
     
  13. gilead

    gilead

    Joined:
    Oct 14, 2014
    Posts:
    13
    Thanks for the swift reply :) Sadly it didn't help. With that code change, also the S7 starts giving out that same error message.
     
  14. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Can you post your code in a GitHub gist and send me the link? Or simply post it here.
     
  15. TobiasW

    TobiasW

    Joined:
    Jun 18, 2011
    Posts:
    91
    Well, coincidentally, I don't actually need the Color32[] data. That was only a step before we
    1. send the Color32[] encapsulated in a pinned buffer to a native plugin (read access only) in the main thread every frame and
    2. keep the Color32[] to be copied later into another pinned buffer to be sent to a native plugin in another thread (also read access only).
    How long is the buffer that PreviewBuffer spits out "good for"? Does it update on the main thread? Should I call PreviewBuffer every frame or is the native buffer updated and stays good? Do I need to make a copy for read access in the main thread?

    As mentioned above, I also need access to the camera in another thread which has this basic loop:
    1. Gets a camera image
    2. Sents the camera image for read access it to a native plugin, which will take a while
    3. Repeat as soon as it's done
    At the moment, I just copy the last Color32[] I got from WebCamTexture.GetPixels32 (with a synchronization lock around GetPixels32 and the copy operation) in the thread. What do you think would be the best way to do this is NatCam Pro?
     
  16. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Ah this means that PreviewBuffer would be more memory efficient for your application.
    The buffer is static. NatCam only maintains one buffer (pixel data can occupy a lot of memory, so we only keep one).
    We can only guarantee thread-safe read only accesses. This is because on different platforms, different threads may be used (and of course the buffer is meant to be read only). On Android, it is currently updated on the render thread. On iOS, it is currently updated on the 'main' (Unity) thread.
    Yes, you should. Although the same buffer is preserved, certain events can cause a reallocation of the buffer. These include calls to NatCam.Release, switching cameras (with different preview resolutions), and on orientation changes (I'll have to check on this one, but I think so).
    It depends. First off, if you need to write to the buffer, then yes. If you need to access the buffer for a long time (if your processing pipeline's frame time is more than NatCam's), then you should make a copy and only update your copy when your pipeline is ready for more data. This guarantees quasi-atomic buffer reads. If you are using a separate thread for processing, then what I have stated would apply.
    Definite yes. Copy the buffer into your processing pipeline instead of using it directly.
    You can take advantage of the fact that the preview buffer handle is (mostly) static. Thus, you can do this:
    Code (CSharp):
    1. // C#
    2. void OnFrame () { // NatCam callback
    3.     // Get the preview buffer
    4.     IntPtr handle; int width, height, size;
    5.     if (!NatCam.PreviewBuffer(out handle, out width, out height, out size)) return;
    6.     // Send it to your native processing pipeline's worker thread
    7.     DispatchWorkloadNatively(handle, width, height, size);
    8. }
    9.  
    10. // C++
    11. // This is assuming the pthread model where the worker thread has a separate event loop
    12.  
    13. intptr_t handle, frame; // Globals for easily retrieving the buffer properties
    14. int width, height, size;
    15.  
    16. extern "C" void DispatchWorkloadNatively(intptr_t _handle, int _width, int _height, int _size) {
    17.     // Update the handle et. al
    18.     handle = _handle;
    19.     ...
    20. }
    21.  
    22. void WorkerUpdate () {
    23.     while (someCondition) {
    24.         // Update the worker's copy of the frame
    25.         memcpy(frame = frame ? frame : new unsigned char[size], handle, size);
    26.         ...
    27.     }
    28. }
     
    Last edited: May 28, 2017
  17. eagleeyez

    eagleeyez

    Joined:
    Mar 21, 2013
    Posts:
    406
    Hi everyone,

    If I take a picture to save and have this displayed, how can I zoom in on the picture? For example using a bluetooth keyboard and pressing up arrow would zoom in on the photo and down would zoom out.
     
  18. gilead

    gilead

    Joined:
    Oct 14, 2014
    Posts:
    13
    I am using your example scene MiniCam.unity. I replaced NatCamFocuser.StartTracking with the following:

    Code (CSharp):
    1. public void StartTracking () {
    2.             var f = FocusMode.AutoFocus | FocusMode.TapToFocus;
    3.             StartTracking(f);
    4.         }
    Guessing this won't help you much, I also emailed you a link to a zip file that contains the whole project.
     
    Lanre likes this.
  19. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    You have to develop a way to scale your display panel up and down. This is out of the scope of NatCam.
     
  20. eagleeyez

    eagleeyez

    Joined:
    Mar 21, 2013
    Posts:
    406
    Thanks, I thought it would be something like that. No Probs, I'll do just that.
     
    Lanre likes this.
  21. riccardo-braga

    riccardo-braga

    Joined:
    Dec 30, 2015
    Posts:
    1
    Good morning everyone,

    i'm having a couple of issues with the latest version (1.5f3):
    1. if take a photo using NatCam.CapturePhoto (the phone is in portrait mode) and try to display the taken Texture2D, the photo appear flipped, just like the photo was took in landscape mode. This happens in both Android and iOS.
    2. After i capture the photo, i also wanto to save it with NatCam.SavePhoto but the photo doesn't get saved both in Android and iOS.
    Here is the code i'm using:
    Code (CSharp):
    1. private IEnumerator CaptureEnemy(float time){
    2.  
    3. yield return new WaitForSeconds(time);
    4. NatCam.CapturePhoto(OnCapturePhoto);
    5. }
    6.  
    7. void OnCapturePhoto(Texture2D photo, Orientation or){
    8.  
    9.         //ENABLE THE PANEL TO SHOW THE PHOTO TOOK AND DISPLAY IT
    10.         menuContainer.SetActive(true);
    11.         menuContainer.transform.GetChild(0).GetComponent<RawImage>().texture = photo;
    12.  
    13.         //SAVE THE PHOTO
    14.         NatCam.SavePhoto(photo, NatCamU.Extended.SaveMode.SaveToPhotoGallery | NatCamU.Extended.SaveMode.SaveToAppDocuments | NatCamU.Extended.SaveMode.SaveToPhotoAlbum, Orientation.Rotation_90,
    15.             (mode, path) => Debug.Log("Photo saved with "+mode+" to path: "+path));
    16.     }
    I saw in the previous posts that the beta version could solve my problem (i think is 1.5b4). If that is so, could you please send it to me? And does it solves both problems or only one of these?

    Thank you in advance!
     
  22. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    This is why the PhotoCallback has an Orientation argument passed. The captured photo will always be returned in landscape left orientation (the natural orientation of the camera). You must display it based on the orientation that NatCam provides. There is a helper component to do this: NatCamPreview. See the documentation and the MiniCam example for how it is used.
    This might be a bug that was mentioned here.
     
  23. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Hi guys. Here's a little update on the API:

    We are working on a revision to the 1.5f3 release, featuring stability improvements and minor bug fixes. An exciting addition coming in the Professional spec release is the NatCam.PreviewBuffer overload which supports a Color32[]. This will be especially useful for performing pixel operations in the managed layer (not needing to write native C/C++ code).

    We are deprecating the Extended Specification.

    We intend to begin work on NatCam 2.0 in the next few months. We will be bringing native support for the Windows and macOS platforms in this release.
     
  24. simo90ita

    simo90ita

    Joined:
    May 8, 2017
    Posts:
    3
    Hi, i have the same issue, if you find the resolution of the problem, please tell me
    thanks
     
  25. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Hi. Please email me with logs from logcat. I'd also like to have you test a fix that might resolve the issue.
     
  26. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    Hey for those who whant to use the zoom function, I found a great free plugin which allows to pinch easily :
    https://www.assetstore.unity3d.com/en/#!/content/30111
    • Import the plugin
    • Unity horizontal menu/GameObject/Lean/Touch (to add the listenner).
    • Select the natCam preview gameObject and disable the "rayCast Target" component within the rawImage Component (because it will block the rays).
    • Add the following script to the preview gameObject :

    Code (CSharp):
    1. /*
    2. *   NatCam Test Suite
    3. *   Copyright (c) 2016 Yusuf Olokoba
    4. */
    5. namespace NatCamU.Examples {
    6.     using UnityEngine;
    7.     using Core;
    8.  
    9.     using Lean.Touch;
    10.  
    11.     //public class ZoomCam : NatCamTest
    12.     public class ZoomCam : NatCamBehaviour
    13.     {
    14.  
    15.         public override void OnStart () {
    16.             // Base
    17.             base.OnStart();
    18.         }
    19.      
    20.         //Ignore fingers with StartedOverGui?
    21.         [HideInInspector]
    22.         public bool IgnoreGuiFingers = true;
    23.  
    24.         //Allows you to force rotation with a specific amount of fingers (0 = any)
    25.         [HideInInspector]
    26.         public int RequiredFingerCount;
    27.  
    28.         //If you want the mouse wheel to simulate pinching then set the strength of it here
    29.         [Range(-1.0f, 1.0f)]
    30.         public float WheelSensitivity;
    31.  
    32.         //Limitation du zoom ?
    33.         [HideInInspector]
    34.         public bool ZoomClamp =true;
    35.      
    36.         //Le zoom de démarrage :
    37.         [HideInInspector]
    38.         public float Zoom= 1.0f;
    39.  
    40.         //Zoom Min
    41.         [HideInInspector]
    42.         public float ZoomMin = 1.0f;
    43.  
    44.         //Zoom Max
    45.         [HideInInspector]
    46.         public float ZoomMax = 2.0f;
    47.  
    48.         protected virtual void LateUpdate()
    49.         {
    50.             // Get the fingers we want to use
    51.             var fingers = Lean.Touch.LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount);
    52.  
    53.             // Get the pinch ratio of these fingers
    54.             var pinchRatio = Lean.Touch.LeanGesture.GetPinchRatio(fingers, WheelSensitivity);
    55.  
    56.             // Modify the zoom value
    57.             //Zoom *= pinchRatio; //En espacant les doigts, on diminue
    58.             Zoom /= pinchRatio; //En espacant les doigts, on agrandit
    59.  
    60.             //On limite le zoom
    61.             if (ZoomClamp == true)
    62.             {
    63.                 Zoom = Mathf.Clamp(Zoom, ZoomMin, ZoomMax);
    64.             }
    65.  
    66.             // Set the new zoom
    67.             SetZoom(Zoom);
    68.         }
    69.      
    70.         protected void  SetZoom(float current)
    71.         {
    72.             //Si on est pas sur Windows, on applique l'HybridFocusMode:
    73.             #if    UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
    74.             #else
    75.                 NatCam.Camera.ZoomRatio = current;
    76.             #endif
    77.          
    78.         }
    79.     }
    80. }
    I also changed the NatCamFocuser script to be able to catch the hybrid focus (auto and manual) :
    Code (CSharp):
    1. /*
    2. *   NatCam Core
    3. *   Copyright (c) 2016 Yusuf Olokoba
    4. */
    5.  
    6. namespace NatCamU.Core.UI {
    7.  
    8.     using UnityEngine;
    9.     using UnityEngine.UI;
    10.     using UnityEngine.EventSystems;
    11.    
    12.     using Lean.Touch;
    13.  
    14.     [RequireComponent(typeof(EventTrigger), typeof(Graphic))]
    15.     //public sealed class NatCamFocuser : MonoBehaviour, IPointerUpHandler { // NCDOC // Excuse the typo ;)
    16.     public class NatCamFocuser : MonoBehaviour { // NCDOC // Excuse the typo ;)
    17.  
    18.         ///////////
    19.         //Rajout//
    20.         /////////
    21.         public FocusMode focusMode = FocusMode.AutoFocus | FocusMode.TapToFocus;
    22.        
    23.         public bool IsTracking {get; private set;}
    24.  
    25.  
    26.         #region --Client API--
    27.  
    28.         /// <summary>
    29.         /// Start tracking focus gestures on the UI panel that this is attached to
    30.         /// </summary>
    31.         public void StartTracking () {
    32.             ///////////
    33.             //Rajout//
    34.             /////////
    35.             //On initialise l'hybrid focus ici
    36.             var f = FocusMode.AutoFocus | FocusMode.TapToFocus;
    37.             StartTracking(f);
    38.         }
    39.  
    40.         /// <summary>
    41.         /// Start tracking focus gestures on the UI panel that this is attached to
    42.         /// </summary>
    43.         /// <param name="focusMode">Focus mode to apply to the camera. Note that this must have
    44.         /// the FocusMode.TapToFocus bit set for tap to focus to work</param>
    45.         public void StartTracking (FocusMode focusMode) {
    46.             if (!NatCam.Camera) return;
    47.             this.focusMode = (NatCam.Camera.FocusMode = focusMode);
    48.             this.IsTracking = true;
    49.         }
    50.  
    51.         /// <summary>
    52.         /// Stop tracking focus gestures
    53.         /// </summary>
    54.         public void StopTracking () {
    55.             IsTracking = false;
    56.         }
    57.         #endregion
    58.  
    59.         protected virtual void OnEnable()
    60.         {
    61.             // Hook into the events we need
    62.             LeanTouch.OnFingerDown   += OnFingerDown;
    63.         }
    64.        
    65.         protected virtual void OnDisable()
    66.         {
    67.             // Unhook the events
    68.             LeanTouch.OnFingerDown   -= OnFingerDown;
    69.         }
    70.        
    71.         private void OnFingerDown(LeanFinger finger)
    72.         {
    73.             if (IsTracking && NatCam.Camera)
    74.             {
    75.                 NatCam.Camera.SetFocus(Camera.main.ScreenToViewportPoint(finger.ScreenPosition));
    76.             }
    77.         }
    78.     }
    79. }
    I'm not a dev so maybe the code is not perfect, just tell me if you can improve it ;)
    Have a nice day !
     
  27. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Thank you so much! I created a gist with some modifications (I made them into separate classes because I don't advise modifying NatCam's sources).
     
  28. deanmarcussen

    deanmarcussen

    Joined:
    Nov 2, 2016
    Posts:
    1
    I see on this forum that in order to get NatCam running on a Samsung S7 and avoid the error message "Failed to load legacy FastRead context" you need to use OpenGl3 support.

    The app I'm working on has another Android plugin which only supports OpenGl2, and crashes when opengl3 is included in the list.

    Is this issue Nougat related or Samsung related? As OpenGl2 works fine on a Moto G4 which updated to Nougat recently.

    Is there any workaround to get the S7 running with NatCam and OpenGL 2?

    The other plugin is old now, so I expect updating that to fix the OpenGl3 crash would be challenging.

    Thanks
     
    Gustavo-Quiroz likes this.
  29. poshaughnessey

    poshaughnessey

    Joined:
    Jul 12, 2012
    Posts:
    45
    I don't see a NatCamLinker.cs class in the 1.5f3 version. What's the preferred way to disable Extended and/or Professional in 1.5f3?

    Thanks,
    Patrick
     
  30. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    The reason why NatCam Pro cannot run on OpenGL ES2 on Android N is because with Android N, Google decided to restrict access to system libraries by third party applications. When NatCam runs on OpenGL ES2, it needs system libraries to perform readbacks from the GPU (this is what NatCamFastRead is responsible for). On Android N+, trying to dynamically link against these libraries results in a hard crash. I advise that you contact your other plugin's developer for an update or find a more recent plugin that does the same thing.

    Newer devices should not be restricted to OpenGL ES2.
     
  31. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    You can use the SpecificationEnabled flag in NatCamEditor.cs in the Extended and Professional directories.
     
  32. poshaughnessey

    poshaughnessey

    Joined:
    Jul 12, 2012
    Posts:
    45
    Has this been implemented yet? If not, is there a workaround?
     
  33. Deleted User

    Deleted User

    Guest

    Hi @Lanre. Do you have an example of querying a specific camera by name? Specifically, I need to guarantee that I can always discover a specific USB camera that's connected to my Windows machine.

    In Unity, I can pass the name into the WebCamTexture constructor.

    Do you have a similar hook for this?

    Thanks very much.
     
  34. unitycodergp

    unitycodergp

    Joined:
    Feb 1, 2017
    Posts:
    47
    Hi,

    Thx for this plugin.

    When I change scene and I come back on the minicam scene the application crash (iOS).

    In Editor :
    MissingReferenceException: The object of type 'RawImage' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.

    Natcampreview.cs
    void Apply
    image.SetAllDirty(); => crash

    Thx in advance :)
     
    Last edited: Jun 10, 2017
  35. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Yes. In NatCamAndroid.cs and NatCamiOS.cs (in the Professional directory), there is the `AudioRecording` flag.
     
  36. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    NatCam does not expose camera names because there is no such concept on Android and iOS (where NatCam has native implementations). But since NatCam falls back to WebCamTexture on all other platforms (NatCamLegacy backend), you can request a specific camera by its name by supplying the index of that camera (within the WebCamTexture.devices array) to NatCam:
    Code (CSharp):
    1. const string cameraName = "[WEBCAM_NAME_HERE]";
    2. // Find its index in the WebCamTexture.devices array
    3. int cameraIndex = -1; // Equivalent of null for DeviceCamera
    4. for (int i = 0, len = WebCamTexture.devices.Length; i < len; i++) if (WebCamTexture.devices[i].name == cameraName) cameraIndex = i;
    5. // Set the NatCam camera
    6. NatCam.Camera = cameraIndex; // int is implicitly cast to a DeviceCamera
     
  37. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    When you reload the scene, the reference to the Preview RawImage is missing because the RawImage was destroyed when you opened your other scene. You must get a new reference to the Preview RawImage in the scene. GameObject.Find will be helpful for this.
     
  38. unitycodergp

    unitycodergp

    Joined:
    Feb 1, 2017
    Posts:
    47
    Thx!

    Is it possible to crop image after or before Apply() method ?
     
    Last edited: Jun 13, 2017
  39. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    NatCam does not have cropping functionality. You must crop the image then send it to NatCamPreview for display.
     
  40. Tagglar

    Tagglar

    Joined:
    Jul 14, 2015
    Posts:
    9
    I have a project that involves switching in and out of a scene that uses NatCam, and on iOS, when the scene is loaded the second time, the app crashes. I've tried using SceneManager.LoadScene and SceneManager.LoadSceneAsync, and it happens with both. The error log in Xcode doesn't show anything helpful. The last output is:
    UnloadTime: 319.854095 ms

    libc++abi.dylib: terminating with uncaught exception of type Il2CppExceptionWrapper

    (lldb)
     
  41. TobiasW

    TobiasW

    Joined:
    Jun 18, 2011
    Posts:
    91
    Hello Lanre,

    I've successfully integrated NatCam into our Android version and first tests suggest a pretty good speed up regarding everything camera-releated.

    I have a question regarding the data returned by PreviewBuffer. In the code for NatCam.PreviewFrame, I found the following lines:

    Code (CSharp):
    1. const TextureFormat format =
    2.             #if UNITY_IOS && !UNITY_EDITOR
    3.             TextureFormat.BGRA32;
    4.             #else
    5.             TextureFormat.RGBA32;
    6.             #endif
    Does that mean that the data returned by PreviewBuffer is in the BGRA order instead of RGBA on iOS devices?
     
    Lanre likes this.
  42. ThomasVandenberghe

    ThomasVandenberghe

    Joined:
    Feb 28, 2014
    Posts:
    22
    Hello,

    Since recently google analytics has forced us to move to Firebase to track mobile app analytics. This plugin uses "play-services-base-11.0.0.aar" and "play-services-basement-11.0.0.aar". NatCam however uses the 9.2.1 version, these files do not work together.

    If I disable the 9.2.1 version the app builds and can be started, until I start the NatCam instance, then the app crashes.
    By disabling the 11.0.0 version, the app cannot be build anymore.

    Would you have any solution to this problem?
     
    cybergaston007 likes this.
  43. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Yes. iOS uses BGRA32 for uncompressed pixel data. Its hardware is more optimized for this byte ordering. Instead of trying to swizzle it to RGBA32 (or ARGB32), you can simply keep your iOS pipeline in BGRA32.
     
    TobiasW likes this.
  44. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Open NatCamEditor.cs in the Extended directory and change the GooglePlayVersion string to 11.0.0.
     
    Otto_Oliveira likes this.
  45. ThomasVandenberghe

    ThomasVandenberghe

    Joined:
    Feb 28, 2014
    Posts:
    22
    This still doesn't work, I've removed Firebase for testing and edited the GooglePlayVersion string to 11.0.0, made sure that the new .aar files were the 11.0.0 ones.
    When opening my scene were NatCam is based it shows 1 frame and then I get the message "Unfortunately, your app has stopped"
     
    cybergaston007 likes this.
  46. dsurka

    dsurka

    Joined:
    Sep 30, 2012
    Posts:
    7
    Hello, I've been using NatCam core on a pretty straight forward way with great success. Now i'm starting to do some more complex stuff and I have 2 questions.
    1. are there any short term plans to have natcam working on editor or is this outside of the scope. At least having it access webcam texture in the background so we don't have to keep 2 codign paths allowing for faster iteration.

    2. when getting Orientation from the PhotoCallback, i can get any one rotation, mirror, or a rotation and mirror. I have no trouble accessing the first 2, but in the case of rotated and mirrored how should i access that case? I'm not very well versed in byte ops, but is it possible the enums should be 0,1,2,4,8 instead of 0,1,2,3,8? would changing this break anything else internally?

    Thanks!
     
  47. jdessart_current

    jdessart_current

    Joined:
    Jun 23, 2017
    Posts:
    18
    I'm developing an app with NatCam Pro 1.5f3, and got it working nicely on iOS. However, when I run it on Android it exits, with OnApplicationQuit called on DispatchUtility. Here's the verbose debug output from the app:

    06-26 13:25:59.493 8403 8419 I Unity : NatCam Logging: Inspected device: Found 2 cameras
    06-26 13:25:59.542 8403 8419 I Unity : NatCam Logging: Changed camera 1 resolution to 1280x720
    06-26 13:25:59.544 8403 8419 I Unity : NatCam Logging: Changed camera 1 photo resolution to 3264x2448
    06-26 13:25:59.546 8403 8419 I Unity : NatCam Logging: Changed camera 1 framerate to 30000
    06-26 13:25:59.560 8403 8419 I Unity : NatCam Logging: Initialized main dispatcher
    06-26 13:25:59.565 8403 8419 I Unity : NatCam Logging: Changed camera 1 resolution to 1280x720
    06-26 13:25:59.566 8403 8419 I Unity : NatCam Logging: Changed camera 1 photo resolution to 3264x2448
    06-26 13:25:59.567 8403 8419 I Unity : NatCam Logging: Changed camera 1 framerate to 30000
    06-26 13:25:59.914 8403 8419 I Unity : NatCam Logging: Released dispatcher

    Is this a known issue? Is there something I might be doing wrong to get this behaviour?

    Any help would be appreciated. Thanks!

    ETA: It works on a Note 5, and an S7 Edge, but not on a Google Pixel.
     
    Last edited: Jun 26, 2017
  48. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    NatCam already has a backend for WebCamTexture. It is the NatCamLegacy backend. The same code works (although most functions are not supported), so no need for platform-specific code. NatCam does this for you.
    I do not advise changing it. It is meant to be 0, 1, 2, 3. To check if the mirror bit is set, do this:
    Code (CSharp):
    1. bool mirrored = (orientation & Orientation.Mirror) == Orientation.Mirror;
     
  49. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    The reason for the crash is not in this log. Email me the full logs (not filtered for Unity log tags).
     
  50. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    ow3n likes this.