Search Unity

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. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    Thx Lanre,
    I can't use NatCam.SavePhoto() as I aiming a custom dir.

    So I tried :
    Code (CSharp):
    1.             NatCamU.Core.Utilities.Utilities.RotateImage(photo, NatCamU.Core.Orientation.Rotation_90, new Color32[photo.width * photo.height], null, null, (rotated, orientation) => {
    2.                  var bytes = rotated.EncodeToJPG(100);
    3.                  File.WriteAllBytes (cheminCompletImage, byt);
    But I have an "Object reference not set to an instance of an object" error.
    I don't really understand the call back thing, I think I made it wrong?
     
  2. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Where exactly does the NullRef come from? What line? And you are calling File.WriteAllBytes with 'byt', not 'bytes'.
     
  3. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    Oups you are right !
    I am a bit tired, it was 'bytes' instead of 'byt ' :)
     
  4. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Great!
     
  5. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    Yes :)
    One last thing Lanre, I just realized when I save a photo manually with something like:
    Code (CSharp):
    1. byte[] bytes = photo.EncodeToJPG(100);
    2. File.WriteAllBytes (myFilePath, bytes);
    => The photo is reversed like this :
     
  6. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    I am not sure what causes this. Look into File.WriteAllBytes and/or texture importing. RotateImage() does not cause this issue.
     
  7. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    First indeed I tought it was because of RotateImage(), but then I realized it happened even with just a simple File.WriteAllBytes.
    The photo was saved correctly before with NatCam 1.3.
    To be precise, now I'm using NatCam 1.5b3 on android.

    I will try to search what's going on !
     
  8. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Sounds good!
     
  9. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    I finally ended up with this but it's really expensive (for anybody having the same issue):
    • Flip the photo with this function :
      • Code (CSharp):
        1.         Texture2D FlipTexture(Texture2D original){
        2.             Texture2D flipped = new Texture2D(original.width,original.height);
        3.        
        4.             int xN = original.width;
        5.             int yN = original.height;
        6.        
        7.        
        8.            for(int i=0;i<xN;i++){
        9.               for(int j=0;j<yN;j++){
        10.                   flipped.SetPixel(xN-i-1, j, original.GetPixel(i,j));
        11.               }
        12.            }
        13.             flipped.Apply();
        14.        
        15.             return flipped;
        16.         }
    • Modify the rotation with RotateImage()
     
  10. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Thank you!
     
  11. DemonIg15

    DemonIg15

    Joined:
    Nov 6, 2015
    Posts:
    2

    Attached Files:

    • 9879.png
      9879.png
      File size:
      335.2 KB
      Views:
      832
  12. DemonIg15

    DemonIg15

    Joined:
    Nov 6, 2015
    Posts:
    2
    It's unity issue. Works fine on unity 5.3.4f1 or down.
     
  13. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Yes it is. Consider updating your version of Unity and check that you are using the most recent version of Google Cardboard SDK. It also seems like you are using NatCam 1.3.
     
  14. darix989

    darix989

    Joined:
    Feb 18, 2014
    Posts:
    1
    Hi,
    I've the NatCam Professional 1.5f3, I'm trying to use the Scanner example scene but it doesn't detect anything.
    I'm using a Samsung Galaxy J3.
    I'm not able to use this example scene on a Nexus 4 and an Asus Zenfone 2 551 because the app crashes at the moment I invoke NatCam.

    Can someone help me?

    Thanks
     
  15. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    I presume you mean 1.5f2, the current Asset Store version.
    Can you email me the full logs from logcat.
     
  16. GodModeTech

    GodModeTech

    Joined:
    Jun 21, 2010
    Posts:
    66
    Can video be recorded from a modified preview (webcam texture)?
     
  17. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    How do you mean a modified preview? Video is recorded directly from the camera (even before the preview frames are sent to Unity) so it cannot be modified in any way.
     
  18. GodModeTech

    GodModeTech

    Joined:
    Jun 21, 2010
    Posts:
    66
    Ok, thanks.
     
  19. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    Hi Lanre !
    Just a little question : I'm trying to pause MiniCam at launch by doing the following :

    Code (CSharp):
    1. // Use this for initialization
    2. public override void Start () {
    3.     //Start base
    4.     base.Start();
    5.     //Set the flash icon
    6.     SetFlashIcon();
    7.  
    8.     StartCoroutine(pauseNatCamAtLaunch());
    9. }
    10.  
    11. public IEnumerator pauseNatCamAtLaunch()
    12. {
    13.     yield return null;
    14.     NatCam.Pause();
    15. }
    It works but I'm losing 10 FPS, so I maybe it's not the better way to do it ?
     
    Last edited: Feb 18, 2017
  20. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    I'm trying to track down memory issues on iOS using my iPhone 6+ and found this post from last year. What's strange is I can't find the above mentioned macro (ALLOCATE_NEW_PHOTO_TEXTURES) or file (NatCamNativeInterface.cs) in my natcam core/extended/pro asset files. When I search for the macro the changelog comes up with the only mention of the search text. Where is this found? I don't see this file on my mac HD. What am I doing wrong?

    I too only need one texture in memory, so I'd like to have NatCam reuse the already allocated texture2d. Can you tell me how to do this?
     
    Last edited: Feb 22, 2017
  21. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    I am not sure why there is a framerate drop. Why are you trying to pause NatCam immediately? If you don't want to start the preview, simply do not call NatCam.Play() (in this case, don't call base.Start()).
     
  22. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    That macro has been deprecated. NatCam will always allocate a new texture and provide it to the you. You must release it by calling Texture2D.Destroy() once you are done with the texture. This is better for memory (because it is not holding on to a Texture2D that might never be used for the remainder of runtime).
     
  23. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    I will do that ! Thanks :)
     
  24. Calvin2274

    Calvin2274

    Joined:
    Sep 11, 2014
    Posts:
    17
    Hi, I just purchased NatCam Core, the preview is keep flashing for some reason
    What i did wrong ?
    Code (CSharp):
    1. void InitWebCam() {
    2. NatCam.OnPreviewStart += OnPreviewStart;
    3. NatCam.Camera = DeviceCamera.RearCamera;
    4. NatCam.Camera.FocusMode = FocusMode.AutoFocus;
    5. NatCam.Camera.SetPhotoResolution(ResolutionPreset.FullHD);
    6. NatCam.Camera.SetPreviewResolution(ResolutionPreset.FullHD);
    7. NatCam.Play();
    8. }
    9.  
    10. void OnPreviewStart() {
    11. rawImage.texture = NatCam.Preview;
    12. }
     
  25. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    This is a bug in 1.5f2. I emailed you the 1.5b3 beta.
     
  26. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Hi Lanre,

    I use NatCam as my AR camera. I have a Quad in my scene with the material assigned to my subclass of NatCamBehaviour like this:

    Code (CSharp):
    1.  
    2. public class PipNatCamBehavior : NatCamBehaviour
    3. {
    4.     public Renderer objectRenderer;
    5.  
    6.     public override void OnPreviewStart () {
    7.         // Set the preview texture onto the material
    8.         objectRenderer.material.mainTexture = NatCam.Preview;
    9.     }
    10.  
    11. }
    This works great, but I now need to implement the MiniCam photo capture and I'm trying to get the done in the most optimized way. My first attempt completely ignored the main AR camera, and instead had the MiniCam canvas prefab (created from the example app) as well as the MiniCam.cs script attached to the canvas prefab. Now in my mind I've got two NatCams going at this point, though it does work.

    Should I remove the MiniCam.cs and use my main camera's subclass of NatCamBehavior to get the minicam implementation working? Is this possible? The photo capture panel slides up into view, user snaps photo and then the photo panel slides out of view. The problem I'm having is the photo capture panel slides into view but doesn't display anything in the preview and I can't figure out what needs to be done.
     
  27. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    This will work. NatCam is a library, not an instance, so you won't have 'multiple NatCams'.
    Ideally, yes. This way, you will be using functionality that is specific to your use case.
    I'm not sure what you mean here. Do you want your photo panel to display the camera preview before you capture a photo? If so, make sure you set the panel's texture to NatCam.Preview.
     
  28. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Thanks for the help on getting the preview working. I'm actually now trying to set this up to test better in Unity editor, so from code found here I'm trying to do this:


    Code (CSharp):
    1.  
    2.     public void SetupPhotoControls() {
    3.  
    4.         #if UNITY_EDITOR
    5.             NatCam.ActiveCamera = DeviceCamera.FrontCamera;
    6.         #else
    7.             NatCam.ActiveCamera = DeviceCamera.RearCamera;
    8.         #endif
    9.  
    10.         // Set the rawImage to the camera preview
    11.         preview.texture = NatCam.Preview;
    12.  
    13.     }
    I must be doing something wrong because I get this error: `NatCamU.Core.NatCam' does not contain a definition for `ActiveCamera'. This code is in my NatCamBehavior subclass :)
     
  29. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    In NatCam 1.5, NatCam.ActiveCamera was refactored to NatCam.Camera. See NatCamBehaviour and the documentation.
     
  30. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Thanks again for that last bit of help.

    I found the following post which I wanted to ask you a question about...

    In my case I need to:

    - Display the photo captured to the user
    - Save the photo captured to the photo gallery
    - Upload the bytes ( byte[] bytes = photo.EncodeToJPG()) to a server

    Questions:
    1. For Displaying the photo captured I'm using the MiniCam example. Can you tell me if the mini-cam example implementation uses a GPU shader to manipulate the display element's UV's (as you suggested in the quote)? Just curious.

    2. For uploading the bytes to the server, is photo.EncodeToJPG the optimal way to go, or has NatCam got some fast/GPU type functionality that I should be looking into?

    Thanks again Lanre
     
  31. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Been doing some testing of 1.5.3 using new Unity project for iOS and only NatCam asset installed. Using the rear camera on my iPhone 6+, capturing a photo in each orientation always logged the following:

    2017-02-27 11:39:48.880 ProductName[3537:816228] NatCam: Captured photo

    -------------------------------------------------> OnCapturedPhoto orientation: Rotation_270, Mirror



    I modified minicam.cs to log the orientation as follows:

    Code (CSharp):
    1.        
    2. void OnCapturedPhoto (Texture2D photo, Orientation orientation) {
    3.  
    4.             Debug.Log ("-------------------------------------------------> OnCapturedPhoto orientation: " + orientation);
    5.  
    6.             // Cache the photo
    7.             this.photo = photo;
    8.             //Set the rawImage
    9.             preview.texture = photo;
    10.             // Orient the view
    11.             view.Orientation = orientation;
    12.             //Enable the check icon
    13.             checkIco.gameObject.SetActive(true);
    14.             //Disable the switch camera button
    15.             switchCamButton.gameObject.SetActive(false);
    16.             //Disable the flash button
    17.             flashButton.gameObject.SetActive(false);
    18.  
    19.             // testing orientation...
    20.             #if UNITY_EDITOR
    21.             NatCam.SavePhoto (photo, NatCamU.Extended.SaveMode.SaveToAppDocuments);
    22.             #else
    23.  
    24.             Debug.Log ("-------------------------------------------------> SaveToPhotoAlbum");
    25.  
    26.             NatCam.SavePhoto (photo, NatCamU.Extended.SaveMode.SaveToPhotoAlbum);
    27.             #endif
    28.  
    29.         }
    30.  
     
  32. FaberVi

    FaberVi

    Joined:
    Nov 11, 2014
    Posts:
    146
    I use:

    private void OnPhotoCapture(Texture2D photo)
    {
    NatCam.SavePhoto(photo, NatCamU.Extended.SaveMode.SaveToPhotoGallery, NatCamU.Extended.SaveOrientation.Rotation_90);
    }

    But the picture is not rotated correctly ... Even using all other settings related to the rotation always get a picture oriented to the left. How can I resolve to rotate a photo correctly?
     
  33. Xenc

    Xenc

    Joined:
    Feb 2, 2016
    Posts:
    13
    Is it possible to obtain the captured live input of this plugin and use the pixels to apply on a texture of a mesh?
    We need the camera input to be shown behind a 3D object (as we're using AR), so we would like to render the camera input on a plane behind the 3D object.
    Is this possible with this plugin? If so, which version supports this feature?
     
  34. akusep

    akusep

    Joined:
    Jul 31, 2012
    Posts:
    3
    Has anyone else on Android been able to save the video files created with Natcam Professional to device? We’ve been testing with Nexus 3 and Galaxy Note 3, and neither of those worked. They just generated a black, broken video clip and NatCam crashes on StartRecording/StopRecording. Is the video recording on android working at all? We are using the 1.5.3 beta version.
     
  35. Dotby

    Dotby

    Joined:
    Nov 12, 2013
    Posts:
    32
    Yes, you can do it easy.
    =====================================
    NatCamBehaviour.preview
    public RawImage preview;
    Description
    The RawImage that will display the camera preview.

    https://www.assetstore.unity3d.com/en/#!/content/52154

    - Preview Data. The Professional Spec gives you access to the native preview data buffer for performing software operations.

    - Preview Frame. The Pro Spec allows you to get the current preview frame on-demand.

    - Preview Matrix. The Pro Spec gives you access to an OpenCVForUnity Mat containing the current preview frame.

    =====================================

    Just edit some code and cast out texture to your mesh material.
     
    Last edited: Feb 28, 2017
    Lanre likes this.
  36. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    Hi, I've updated Unity and had to update Natcam as well and I was getting these same weird errors again. I removed the Gyrodroid asset from my project as I had come up with my own Gyrocam script and these Natcam errors went away. Really not sure how or why Gyrodroid would block these UNITY API calls but deleting it got rid of the problem. Figured I'd share in case anyone else had these problems...
     
    Lanre likes this.
  37. kongbt

    kongbt

    Joined:
    Feb 17, 2017
    Posts:
    1
    Hi Lanre
    I'm checking on ios webcam feature but I found the performance too low compared to AVfounderation. When I use the ipad natcam 1.5 pro for opencv is very high cpu. How do I solve it?
     
  38. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Any thoughts Lanre?

     
  39. juuuuun

    juuuuun

    Joined:
    Feb 17, 2014
    Posts:
    23
    Hi all,

    I seem to get a memory leak problem (checked using Xcode Instrument) when I build the app for iOS using NatCam 1.5f2 with Unity 5.5.2 even with the sample scene came with the asset called Minigram. I'm not sure if this is the reason but when I tried to use NatCam with OpenCV for realtime image processing for camera image the app freezes in few mins and I have to reboot the device itself in order to use the phone again.

     
  40. chachi_app

    chachi_app

    Joined:
    Feb 9, 2017
    Posts:
    12
    Hello! I´ve just bought NatCam Professional to solve the problems of rotations, scale and flipped photos, but after trying the Minigram example and taking a photo, the bug still remains. the photo is rotated 90 degrees. Any help please?
     
  41. lindenbaum256

    lindenbaum256

    Joined:
    Sep 24, 2014
    Posts:
    1
    I just bought NatCam Pro 1.5 and found 2 major problems,

    1. The preview doesn't handle orientation correctly, both on iOS and Android. The minigram example exhibits this problem. Turn the device from portrait to landscape, upside down... or whatever, only portrait is shown correctly. Doesn't NatCam handle orientation? or do I have to handle them myself?

    2. The startingoff example doesn't work by default. The preview shows garbled capture, both on iOS and Android. I had to change the Canvas rendering mode from "Screen Space - Overlay" to "Screen Space - Camera" for it to work.
    But that won't work for my project. I have several canvases in my project, and some of the canvas need to be rendered as "Screen Space - Overlay", however NatCam will show garbled capture unless I set all my canvases to "Screen Space - Camera".

    Any hints?
     
    Mikael-H likes this.
  42. Mikael-H

    Mikael-H

    Joined:
    Apr 26, 2013
    Posts:
    309
    Just got this as I need live video for an AR app. Two problems:

    1. When I switch to landscape mode (which I will mostly use) everything gets stretched
    2. On a Samsung Galaxy S7 the screen seems to constantly flicker between fullscreen and a smaller screen in the bottom left quarter of the screen.

    Using latest android sdk and jdk and NatCam Extended

    Does anyone else have this issue or is this some odd issue that only happens to me :p
    Otherwise I'll keep trawling the asset store I guess...
     
  43. Mikael-H

    Mikael-H

    Joined:
    Apr 26, 2013
    Posts:
    309
    So as I couldn't get this asset to work properly I just went ahead and made my own implementation using basic webcamtexture and must say the FPS was really problem. So maybe unity upgraded it under the hood the last few versions.
     
  44. boothy1

    boothy1

    Joined:
    Feb 13, 2014
    Posts:
    6
    I bought Natcam Professional yesterday and after playing around wit Minigram I can't get the preview to stop flashing. It worked initially (until I added a new panel to the canvas) but now I can't get it to stop flashing. This morning I removed Natcam and re-downloaded it but the preview is still flashing using the stock Minigram app. What am I doing wrong? I'm using Windows 10 (current patch releases) and the current Unity 5.5.1f1 personal). Test phone is a Samsung Galaxy S6.
     
  45. boothy1

    boothy1

    Joined:
    Feb 13, 2014
    Posts:
    6
    I
    I'm having exactly the same problems on a Samsung Galaxy S6 with Natcam Pro.
     
  46. chachi_app

    chachi_app

    Joined:
    Feb 9, 2017
    Posts:
    12
    To major problems:

    1. The problem of the incorrect orientation for photos persist. I thought this feature was included in a plugin of 99€
    2. Firebase integration : Did anyone integrate natcam with Firebase? I have a "Fail to repackage resources" during the building process, after setting the Android SDK to a minimum of 18.

    Very dissapointed with the help of this plugin. It was really expensive and no-one is answering to my emails.
     
  47. boothy1

    boothy1

    Joined:
    Feb 13, 2014
    Posts:
    6
    I emailed the developer today about this and had a reply within 10 minutes. This is a known issue with the current version of NatCam and has been fixed in the next release. Although I was offered early access to the beta version I was also given a work around that solved my problem (in the player settings change the rendering to multithreaded).
     
    Lanre and Mikael-H like this.
  48. Mikael-H

    Mikael-H

    Joined:
    Apr 26, 2013
    Posts:
    309
    Awesome! As my current solution works for now I can wait for the update. Thanks for letting me know, now I don't have to trawl through every video capturing asset there is in the store but can just wait for the next version of this one :)
     
  49. xdbx

    xdbx

    Joined:
    Jun 29, 2016
    Posts:
    3
    Using the latest NatCam i noticed that NatCam.PreviewBuffer(out buffer, out width, out height, out size);
    returns a 640x480 image on tablets, but a 480x640 image on phones. Is there a way force PreviewBuffer to always return 640x480 regardless of the device?
     
  50. violetforest

    violetforest

    Joined:
    May 26, 2015
    Posts:
    10
    Hi, when I try to build and run on iOS thru Xcode i get
    libc++abi.dylib: terminating with uncaught exception of type Il2CppExceptionWrapper
    I am trying to build a version with the NatCamCV custom script for opencv

    heres the log:
    -> applicationDidFinishLaunching()

    2017-03-07 22:40:40.116940 ar[1522:520091] Metal GPU Frame Capture Enabled

    2017-03-07 22:40:40.117272 ar[1522:520091] Metal API Validation Disabled

    -> applicationDidBecomeActive()

    GfxDevice: creating device client; threaded=1

    Init: screen size 750x1334

    Initializing Metal device caps: Apple A9 GPU

    Initialize engine version: 5.5.1f1 (88d00a7498cd)

    UnloadTime: 1.061083 ms

    2017-03-07 22:40:40.849392 ar[1522:520091] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles

    2017-03-07 22:40:40.851308 ar[1522:520091] [MC] Reading from public effective user settings.

    2017-03-07 22:40:40.861900 ar[1522:520091] NatCam Logging: Changed camera format for resolution 1280x720

    2017-03-07 22:40:40.862352 ar[1522:520091] NatCam Logging: Changed camera format for photo resolution 9999x9999

    2017-03-07 22:40:40.862786 ar[1522:520091] NatCam Logging: Changed camera framerate to 30.000000

    NatCam Logging: Initialized Main Dispatcher

    2017-03-07 22:40:41.103931 ar[1522:520091] NatCam Logging: Started session

    Setting up 1 worker threads for Enlighten.

    Thread -> id: 16f5b3000 -> priority: 1

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

    (lldb)


    Can you email me 1.53 beta please? info@violetforest.com
     
    Last edited: Mar 8, 2017