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. tgouala-wellfiredLtd

    tgouala-wellfiredLtd

    Joined:
    Jun 8, 2013
    Posts:
    99
    On Samsung Note 10.1 GT-N8010 Android 4.1.1 and Samsung Note 8,0 GT-N5120 Android 4.1.2, the focus does not work, no matter it is tap or autofocus. I attached the log of Samsung Note 10.1 GT-N8010.

    Additionally, on Samsung Note 8.0 GT-N5120, the camera preview will be totally white the first time I call NatCam.Play(). If I leave the scene, come back and call again NatCam.Play() it will work. I attached the logs of Note 8.0 when starting NatCam the first time and the screen stay white. Edit : Actually it is an issue with the device itself, not related to NatCam.

    We finish doing a round testing of all our devices, and only 2 bugs seems to exist (the preview rotation not calculated correctly, the focus not working on Samsung Note 10.1 and Samsung Note 8.1).

    We have much better result that using Unity embedded WebcamTexture.
    Not bad at all ! We hope you can find something helpful in the posted logs.
     

    Attached Files:

    Last edited: Jul 18, 2017
  2. Mhanicos

    Mhanicos

    Joined:
    Jan 25, 2017
    Posts:
    11
    Hi, after i close the scene with NatCam, the object NatCam(whith script Dispatch Utility) still live in DontDestroyOnLoad, and application freezing, how could i avoid this
     
  3. Mhanicos

    Mhanicos

    Joined:
    Jan 25, 2017
    Posts:
    11
    A few days later i found that natcam normaly works on galaxy s7, but when i'm importing vuforia the app is totaly crushed after two seconds when i open scene with natcam. We turn on delayed initialization on vuforia, bit it doesn't help.
     
  4. tgouala-wellfiredLtd

    tgouala-wellfiredLtd

    Joined:
    Jun 8, 2013
    Posts:
    99
    Do you release natcam before using Vuforia ? NatCam.Release()
    Or do you release vuforia before using Natcam ?
     
    Lanre likes this.
  5. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    Good morning Lanre,
    I'm sure the issue is easy to fix, but I'm not a dev :/
    Could you point me to the right direction ?

    Here is a screenShot of the preview gameObject:


    And you can find enclosed my pinchCam script.
    Have a nice day
     

    Attached Files:

  6. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    I was not able to download the scene; I just checked and saw that it has been deleted. Make sure you are managing NatCam from one class; having MiniCam and PinchCam would result in the same calls being made to NatCam multiple times which could lead to unexpected behaviour. Use PinchCam if you need the pinch to zoom functionality.
     
  7. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    It is an RGBA32 (on Android) or BGRA32 (on iOS or macOS) pixel buffer. You can copy it into a Color32[] using the System.Runtime.InteropServices.Marshal and GCHandle API's (pin and copy). NatCam 1.6 will come with a function that does this.
     
  8. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    This is correct if the platform uses RGBA32 format. On iOS, it would be BGRA.
     
  9. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Email me your invoice number and I'll share the native source projects with you.
     
  10. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    The logs don't show anything going wrong. What is your app's orientation in Player Settings?
     
  11. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    On Android the most supported focus mode is this:
    Code (CSharp):
    1. var hybridFocus = FocusMode.AutoFocus | FocusMode.TapToFocus;
    Most cameras do not support TapToFocus alone.
     
  12. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    You can manually delete the gameobject, but I do not recommend it. Make sure you application is not freezing for some other reason.
     
  13. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    You have to make sure that NatCam is completely uninitialized when you use Vuforia, and that Vuforia is completely uninitialized when you use NatCam. You cannot use both of them at the same time. To uninitialize NatCam, use NatCam.Release(). Check the Vuforia docs for a corresponding function for Vuforia.
     
  14. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Remove MiniCam from your scene as PinchCam already uses NatCam.
     
  15. tgouala-wellfiredLtd

    tgouala-wellfiredLtd

    Joined:
    Jun 8, 2013
    Posts:
    99
    Landscape left, this is the only orientation we allows in the game
     
  16. tgouala-wellfiredLtd

    tgouala-wellfiredLtd

    Joined:
    Jun 8, 2013
    Posts:
    99
    Yes, I saw that in the forum. But unfortunately, it seems that on these devices the focus will simply not respond. It happens on both Samsung Note 10.1 GT-N8010 Android 4.1.1 and Samsung Note 8,0 GT-N5120 Android 4.1.2, did you get some similar feedbacks on these devices ? Or is there a way to check in the log what's going on ?
     
  17. Mhanicos

    Mhanicos

    Joined:
    Jan 25, 2017
    Posts:
    11
    • I unitialize vuforia, but it don't help, the app still crashed. Also i create new project and import there vuforia +natcam, and don't initialize vuforia at all, but app crushed
     
  18. tgouala-wellfiredLtd

    tgouala-wellfiredLtd

    Joined:
    Jun 8, 2013
    Posts:
    99
    Are you sure that Vuforia does not initialize by itself ? You can disable this in vuforia configuration.
    upload_2017-7-24_18-1-44.png
     
    Lanre likes this.
  19. Mhanicos

    Mhanicos

    Joined:
    Jan 25, 2017
    Posts:
    11
    Yes, i turn on delayed initialization
     
  20. Mhanicos

    Mhanicos

    Joined:
    Jan 25, 2017
    Posts:
    11
    it works on all devices except galaxy s7
     
  21. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    This is the default hardware orientation of the camera. The orientation should be untouched. I will see what I can find on this.
     
  22. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Turn on NatCam's verbose mode:
    Code (CSharp):
    1. NatCam.Verbose = Switch.On;
    This will allow NatCam log a lot of information as it operates, including information relating to focusing.
     
  23. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Can you send me the full logs from logcat? The stack trace should have good clues.
     
  24. tgouala-wellfiredLtd

    tgouala-wellfiredLtd

    Joined:
    Jun 8, 2013
    Posts:
    99
    After playing with the shader NatCamTransform2D used by Preview, I figured out that the parameters sent by Unity to the shader seems to be wrong on the Kindle Fire 8.5. It's probably a similar issue on Samsung 4. If I modify over the time the rotation parameters directly in the shader, then the preview texture rotation is right. Unfortunately, the camera signal is vertically mirrored for some reason I ignore.
     
  25. tgouala-wellfiredLtd

    tgouala-wellfiredLtd

    Joined:
    Jun 8, 2013
    Posts:
    99
    It is already activated in the logs I shared with you. Do you see anything wrong about the focus ?
     
  26. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    This should not be the case. The NatCam.Preview texture is already oriented natively, so when applying it with NatCamPreview, simply do this:
    Code (CSharp):
    1. NatCamPreview preview = ...
    2. preview.Apply(NatCam.Preview);
     
  27. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Just checked it out. Apparently the Note 10.1 doesn't support Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE (the native equivalent to `AutoFocus | HybridFocus` on Android). But I should mention that you never seem to be calling DeviceCamera.SetFocus. Consider using the NatCamFocuser component on your preview UI panel.
     
  28. tgouala-wellfiredLtd

    tgouala-wellfiredLtd

    Joined:
    Jun 8, 2013
    Posts:
    99
    Here the code from NatCam.Preview :

    Code (CSharp):
    1. public void Apply (Texture texture, Orientation orientation = Orientation.Rotation_0, ScaleMode scaleMode = ScaleMode.FillView) {
    2.             // Set
    3.             image.texture = texture;
    4.             // Scale
    5.             dimensions = texture ? OrientedDimensions(texture, orientation) : image.rectTransform.rect.size;;
    6.             this.scaleMode = scaleMode;
    7.             image.SetAllDirty();
    8.             // Orient
    9.             image.materialForRendering.SetFloat("_Rotation", ((int)orientation & 7) * 0.5f);
    10.             image.materialForRendering.SetFloat("_Mirror", (int)orientation >> 3);
    11.         }
    What I mean is that image.materialForRendering.SetFloat seems to not passed the expected value to the shader. This ends with a preview rotated by around 40 degrees on the Kindle Fire HD 8.9. The value passed is right, but somehow, the shader get a different value. Maybe it is a precision issue, or a bug in Unity ?

    By the way, I don't know if you heard of Amazon Farm. This allows you to test on a battery of devices from the cloud in real time (you see phone screen in your browser). Not sure if it allows to test camera, but you can have a look.
     
  29. tgouala-wellfiredLtd

    tgouala-wellfiredLtd

    Joined:
    Jun 8, 2013
    Posts:
    99
    I am pretty sure I call it since it works on a lot of other devices. But indeed I don't use directly the component NatCamFocuser because it does not support
    Code (CSharp):
    1. var hybridFocus = FocusMode.AutoFocus | FocusMode.TapToFocus;
    2 questions
    - Is there a way to detect that the focus requested did not work and requires another mode ?
    - Since we use Natcam to scan QR code (only the camera preview, since we saw on medium that the QR code scanning part will be removed soon), would Macro focus be more adequate ? And is it supported by many devices ?
     
  30. CarinaMclane

    CarinaMclane

    Joined:
    Mar 12, 2014
    Posts:
    23
    Hi,

    We've just bought the pro version of this asset, and trying to run either of the example scenes on the Galaxy S8 shows me Unity loading, a white screen, then results in a crash (see attached log). Help please? (Don't have any other devices to hand currently to test)

    Thanks!
     

    Attached Files:

  31. chihchanglin

    chihchanglin

    Joined:
    Jul 24, 2015
    Posts:
    28
    Hi,
    I have few quesions:
    1. Can photo save using JPG instead of PNG?
    2. Can photo save using custom filename?
    3. Can photo save using custom folder name instead of App Documents root folder?
    4. Can photo save add some EXIF info? ex: GPS coordinates.

    Thanks. :)
     
    Last edited: Jul 26, 2017
  32. huffy

    huffy

    Joined:
    Nov 11, 2014
    Posts:
    8
    Hi,

    var hybridFocus = FocusMode.AutoFocus | FocusMode.TapToFocus;

    I set FocusMode; but it has a error;

    NatCam Error: Failed to set camera 0 focus mode to 3

    so I modify it like this
    var hybridFocus = FocusMode.TapToFocus;

    but if you tap screen, it can focus just a second; then it does not have focus

    the phone is Samsung Note 10.1, can you help me ?

    and a suggestion, if setting camera focus mode failed, can you return a value ?
     
  33. Zazery

    Zazery

    Joined:
    Jul 9, 2013
    Posts:
    3
    Would it be possible to upload the Android demo you had before with QR code scanning? I'm currently using WebCamTexture and having issues with autofocus on certain devices (S6 and Galaxy Tab E). I would like to verify this solves the issue before purchasing. Is QR code scanning part of core or only pro? Thanks.
     
  34. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    You can set it from code.
    Yes. Simply check the value of DeviceCamera.FocusMode after setting DeviceCamera.FocusMode.
    Although MacroFocus has been deprecated in 1.6, but would still be able to set it (using the same value as in 1.5). In my experience, MacroFocus isn't widely supported (as is the case with a lot of the other focus modes on Android).
     
  35. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Hi there. You seem to be forcing your application to use OpenGL ES2 even though the S8 is capable of ES3+. Due to Android restrictions, NatCam cannot be run with OpenGL ES2 on devices that run Android N or newer.
     
  36. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    NatCam does not save photos that are captured. The photos are returned as Texture2D objects. You can then save them as you wish.
     
  37. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    It would seem that the camera does not support the focus mode mentioned here.
    See this:
     
  38. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    QR code scanning has been deprecated. There are several QR code scanning API's available; I strongly recommend ZXing.NET.
     
  39. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    tgouala-wellfiredLtd likes this.
  40. huffy

    huffy

    Joined:
    Nov 11, 2014
    Posts:
    8
    my camera can't display, in Galaxy S4, Android 4.2.2. Can you help me?
    and I don't use IL2CPP.

    and I have a error, I don't know it relates this.

    OPENGL NATIVE PLUG-IN ERROR: GL_INVALID_ENUM: enum argument out of range.

    Screenshot_2017-07-31-15-16-28.png
    Unnamed QQ Screenshot20170801113009.png
     

    Attached Files:

    Last edited: Aug 1, 2017
  41. H-Holon

    H-Holon

    Joined:
    Apr 13, 2017
    Posts:
    1
    I'm using NatCam Professional 1.5f3 on iPhone6s plus that camera has 4032x3024 pixels resolution.
    (please see https://developer.apple.com/library...e/iOSDeviceCompatibility/Cameras/Cameras.html)

    and I modified NatCam example code MiniCam.cs, like this
    public override void Start () {
    base.Start();
    NatCam.Camera.SetPhotoResolution( 4032, 3024 );
    Debug.Log( "PhotoSize.Start:" + NatCam.Camera.PhotoResolution.ToString() );
    }

    I expected it will show iPhone6s plus's maximum pixel size, 4032x3024 (12Mpixels). but it shows smaller size, 8M pixels.
    PhotoSize.Start:(4096.0, 2304.0) UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
    What should I do for iPhone's maximum pixel size capturing ? I want to get a largest photo.
     
  42. tgouala-wellfiredLtd

    tgouala-wellfiredLtd

    Joined:
    Jun 8, 2013
    Posts:
    99
    Unity has a nasty bug that makes vertices shader using vertices alpha not work correctly with OpenGLES 3 on android devices using mali GPU : https://issuetracker.unity3d.com/is...-incorrectly-on-android-devices-with-mali-gpu.

    This makes for example this list of devices fails when using SVG renderer tools (like SVG Importer) :
    Samsung Galaxy S6
    Samsung Galaxy S6 edge
    Samsung Galaxy Note 5
    Xiao Mi 4
    Samsung Galaxy Tab S2
    Hua Wei P8
    Hua Wei M2
    Sony Zperia Z5 Dual
    Samsung Galaxy S6 edge+

    Solving the problem requires to disable OpenGLES 3 and use Opend GLES 2 instead. As you mentionned : NatCam cannot be run with OpenGL ES2 on devices that run Android N or newer.

    Your solution to access camera feed to for example scan QR code with precision is the most stable and covering the most numerous devices we found. So we really want to stick to it.

    Have you heard of any work around that would allows us to not use Open GLES 3 but Open GLES 2 instead ?
     
  43. SunnyChow

    SunnyChow

    Joined:
    Jun 6, 2013
    Posts:
    360
    Currently, i get a problem about webcamtexture, which makes thinking about purchasing this plugin. for iOS, there is video mode and photo mode, in video mode the texture is cropped so the fov is smaller, and unity builtin WebCamTexture is using this. So i would like to ask which mode NatCam is using?
     
  44. developer2017

    developer2017

    Joined:
    May 9, 2017
    Posts:
    8
    Hi.
    Using 1.5f3 version on Android 6.0.1 and ReplayCam sample...
    Sometimes recording works like a clock sometimes it crashes constantly (please see NullPointerException).
    I am using: ./adb.exe logcat | grep -e Unity -e 'AndroidRuntime' (do you have another grep pattern?)
    Video files seems to be created in root of Internal Storage no matter if it crashes or not.

    Another question: Do you think that specifying the output path and SaveMode in NatCam.StartRecording() would give us a little bit of control and save you some trouble of trying some invalid paths on some devices?
    Ty.
     

    Attached Files:

    • adb.txt
      File size:
      38.9 KB
      Views:
      1,025
  45. huffy

    huffy

    Joined:
    Nov 11, 2014
    Posts:
    8
    Hi, I come back again. my phone is Kindle Fire HD 8.9. the camera preview being rotated 180 degrees in landscape mode
     
  46. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    I am looking into this. Is multithreaded rendering on in Player Settings?
     
  47. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    On iOS, it is not possible to set the preview resolution independently from the photo resolution--they are 'tied' together (see AVCaptureDeviceFormat). As a result, NatCam gives highest precedence to preview resolution then framerate then photo resolution. If you want to find the photo resolution you need, you must first set preview resolutions (that support the photo resolution you want), then set the photo resolution you want. The process of finding the preview resolution that supports your desired photo resolution is tiresome so I generally do not recommend it.
     
  48. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Unfortunately, there is no workaround. In Android N and newer, the app will crash if it uses OpenGL ES2 as a rendering API. This is due to a strict restriction on system libraries that Google placed in Android N.
     
  49. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    I am not sure what you are referring to. In the iOS camera API, AVFoundation, there is no such photo vs. video mode. Can you explain more what you mean?
     
  50. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    This bug has been fixed in the upcoming NatCam 1.6.
    Specifying SaveMode for videos will tend too much towards NatCam Extended's featureset, which we have deprecated. Regarding a path, NatCam always saves to a directory that is guaranteed by the platform API's to exist and be writeable. This is why we don't accept a path in StartRecording (we'd have to handle all the chaos that could ensue with unsuitable paths). When you receive the path to the video in the SaveCallback, you are free to move the file to a location of your choosing.