Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    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. XXFS

    XXFS

    Joined:
    Dec 13, 2015
    Posts:
    3
    Hi, I add natcam plugin to my project that integrated vuforia SDK,the arscene was crashed when run at ipad2018(6th):)
     
  2. xteamsoftware

    xteamsoftware

    Joined:
    Jan 7, 2016
    Posts:
    5
    don't worry, it's more important to me if you solve the preview issue
     
    Lanre likes this.
  3. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    NatCam can't run at the same time as Vuforia because only one service can gain exclusive access to use the hardware camera.
     
  4. XXFS

    XXFS

    Joined:
    Dec 13, 2015
    Posts:
    3
    I don't know these until you tell me translation,thank you
     
  5. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    NatCam and Vuforia can't run at the same time because only one service can use the camera at any point in time. The same restriction goes for WebCamTexture and Vuforia, or WebCamTexture and NatCam.
     
  6. Leocrsp

    Leocrsp

    Joined:
    Mar 7, 2019
    Posts:
    1
    Hi, did you solve it? Because i have a very similar problem and I am struggling to solve it
     
  7. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    Make sure you are running with the latest version of NatCam (2.2).
     
  8. daleKaio

    daleKaio

    Joined:
    Jan 28, 2019
    Posts:
    3
    We are experiencing a problem with zoomRatio when running our application on an iPhone XR. The max zoomRatio for an iPhone XR reads as 189 which is a lot larger than most other devices we have tested on. It seems like the zoomRatio isn't using the entire range of 1-189. Is this intended behavior for the iPhone XR?

    Thanks
     
  9. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    This is weird. Usually, the zoom ratio is anywhere from 4 to 8. I'm not sure what you mean by the zoom ratio not using the entire range; NatCam sets the value passed in verbatim on the AVCaptureDevice.
     
  10. daleKaio

    daleKaio

    Joined:
    Jan 28, 2019
    Posts:
    3
    I don't currently have the iPhone XR at the office to test it, but it seemed like it would get to full zoom before reaching the maxRatio of 189. Do you have any ideas on how we could bandaid the issue before the next NatCam update? The last update fixed the other issues we were having. We're using the zoomRatio to do distance calculations in OpenCV and need a workable scale from 4 to 8
     
  11. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    Unfortunately there isn't anything we can do to resolve this. I guess a safe option is to consider the max zoom ratio as `minimum(DeviceCamera.MaxZoomRatio, 8)` (you can switch out 8 for any number that works for you. This looks like a bug in the XR.
     
  12. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,282
    Thank you for releasing the latest version of NatCam (2.2.1).
    The known Android platform bug seems to be revised definitely as far as I tried it.

    However, I have encountered another problem.
    The latest version of NatCam (2.2.1) seems to have the same problem as Unity's WebCamTexture API.
    This is a problem of the low illumination of a front camera occurring only with some Android devices.
    https://forum.unity.com/threads/android-webcamtexture-in-low-light-only-some-models.520656/
    https://forum.unity.com/threads/released-opencv-for-unity.277080/page-33#post-3445178
    https://answers.unity.com/questions/1425938/android-native-camera-low-lightlow-iso.html
    This problem was not present in previous versions.

    I am in trouble as I have been using NatCam as an alternative to this problem.

    NatCam2.2.1_front_camera_low_light_issue_fps30.jpg NatCam2.2.1_front_camera_low_light_issue_fps15.jpg
     
  13. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    I think I know why this is happening. Email me tomorrow for an updated build.
     
  14. azjata

    azjata

    Joined:
    Sep 27, 2012
    Posts:
    7
    the feed is very slow and tearing on brand new phone samsung s10+
    while using webcamtexture from unity works very smooth.
    I tried to reduce the preview texture alot, but that doesn't make much difference. is there any way I can optimise this so i get a smooth preview?

    deviceCamera.PreviewResolution = new Vector2Int(1520, 720);

    I have also tried half of that resolution still not very smooth considering very good processor in a brand new phone, so I can rule out performance issues

    deviceCamera.PhotoResolution = new Vector2Int(4608, 3456);

    thanks
     
  15. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    Can you email me with the full logs from logcat? Thanks.
     
  16. henriqueranj

    henriqueranj

    Joined:
    Feb 18, 2016
    Posts:
    151
    Hello @Lanre , with the latest Unity support for Android 64-bit architecture and the Google Play Store requirement for such architecture from August 2019, is the NatCam native Android libraries supporting 64-bit? And what about NatCorder?
     
    TriggerAndrew likes this.
  17. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    With the latest versions of our API's, everything is written in Java. So no native (C/C++) libs, and no need for 32- or 64-bit compilation.
     
    henriqueranj likes this.
  18. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    709
    So latest NatCam cannot run in the same project as Vuforia? In 2017 you said you can release the NatCam before initiating Vuforia. This no longer the case?
     
  19. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    You can have them in the same project, but they can't run at the same time. The equivalent of 'releasing' NatCam now is to simply make sure that all DeviceCamera.Cameras are not running.
     
    thylaxene likes this.
  20. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    228
    I'm still struggling a little on iOS regarding the best NatCam setup for augmented reality. Basically the focus and exposure are constantly adjusting such that you lose the AR feel of the app. Do you have a suggestion regarding a good implementation for focus and exposure?

    For example, I thought about implementing a custom "tap to expose/focus" method where by the ExposureMode and FocusMode will be set to AutoFocus and AutoExpose for a brief second or two, just enough to allow the focus and exposure to take place, and then back to off/locked. Either that or a coroutine that sleeps for 10 seconds, then sets focus/exposure on then off again. Does this seem like it would work? Any idea how long would I need to wait for the focus/exposer to take place?

    Thanks!

    Edit: The problem with leaving Exposure locked is that the AR screen is sometimes too dark or overexposed depending on how the environment is when the user starts the app.

    Thanks Lanre, any ideas would be appreciated.
     
  21. okgostudio

    okgostudio

    Joined:
    Sep 16, 2016
    Posts:
    2
    Hi Lanre, i have the same issue with EnoxSoftware about low light on Oppo F3S, please help me about it
     
  22. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    If you want to maintain parity with the Human Visual System, then you should technically allow autoexposure. The eyes perform continuous AE. Focus is more of an issue, because NatCam doesn't support setting infinite focus.
    This is a more reliable way to do it. NatCam doesn't provide callbacks for when AF or AE routines complete, so you shouldn't assume a specific time. A coroutine sounds more ideal.
     
  23. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    The next update will fix this.
     
  24. atul109

    atul109

    Joined:
    May 11, 2018
    Posts:
    2
    We purchased the asset with great expectation, it works great in Redmi4 where as the camera preview is lagging in Samsung S9+ and Note5. Tried building in unity by changing different settings like OpenGLES2, OpenGLES3, AutoGraphics enabled, Mono & IL2CPP etc. but results are same.

    Screen recording : https://drive.google.com/open?id=1BKvPKgjDu1UN7xbKtexKOqPOcEHjkU3r
     

    Attached Files:

  25. gciapponirealmore

    gciapponirealmore

    Joined:
    Sep 13, 2018
    Posts:
    5
    As the user above, we just purchased NatCam but the performance is very poor on both Samsung S6 and Samsung S7, works fine on iPhone 7.
    Issues are exactly the same as in the screen recording shown by atul109.
     
  26. xteamsoftware

    xteamsoftware

    Joined:
    Jan 7, 2016
    Posts:
    5
    Hi Lanre,
    thanks for the great work in the latest update of NatCam.
    we have also noticed that the framerate has dropped considerably, even by setting low preview resolutions.

    Can you provide suggestions on how to improve NatCam performance?

    Have a nice day
     
  27. Otto_Oliveira

    Otto_Oliveira

    Joined:
    Jul 24, 2014
    Posts:
    33
    Hi Lanre,
    on my device (Nexus 6P) flash doesn't work on latest version 2.2.1. When the camera is requested flash turns on for a half second then turn off and when taking a photo it doesn't turn on.

    Also, the front face camera is taking rotated photos, but on the preview is fine. On previous versions, I handled that using callback's orientation parameter and then rotating the texture.
     
  28. visionvr-app

    visionvr-app

    Joined:
    May 20, 2019
    Posts:
    1
    Hi Lanre,

    Appreciate all the great work you've done with this app. We're developing an application with NatCam that utilizes the front camera on a Samsung GS7. Everything seems to work swimmingly, with the exception of autofocus. Autofocus technically *works* but it's a PDAF sensor, and it doesn't seem like phase focus works (it's a contrast-based sweep mode). However, replacing the camera2 API with Samsung's soon to be deprecated Camera SDK in a native Android app yields extremely fast focus performance by enabling PHASE_AF_MODE when building the capture request.

    I'm wondering if there's a way to add Samsung's API support in place of camera2 API within NatCam to get the performance of PDAF in NatCam?

    In addition to this, there is a lot of advanced camera customization available to Samsung phones with their SDK, including noise reduction, black level, lens correction, turning off OIS, etc. It would certainly be a dream to have control of these options!
     
  29. karthik372

    karthik372

    Joined:
    Jun 13, 2019
    Posts:
    1
    How to set ( Android mobile camera focal length ) using natcam. How to fix same pixel value for different mobile and capture same person.
     
  30. BrodeyPison

    BrodeyPison

    Joined:
    Jun 12, 2018
    Posts:
    4
    Hello!
    I've noticed with the new updates that switching device cameras too often will cause a black screen or the app to crash. Even when called using a coroutine and timers in between. Any idea why this is happening? Thanks!
     
  31. nhic

    nhic

    Joined:
    Dec 25, 2018
    Posts:
    3
    Hi, I bought NatCam a few days ago because I needed to get the HFOV of my front web camera.
    I tested debugging the HFOV every frame in the Unity editor on my Mac laptop but always got a value of 0.

    Here is how I get the HFOV.
    Debug.Log("HFOV is: " + deviceCamera.HorizontalFOV);

    Could you tell me why it's returning 0 instead of the actual HFOV?
     
  32. xdbx

    xdbx

    Joined:
    Jun 29, 2016
    Posts:
    3
    Hi, tried the latest version of NatCam (2.2.1) in Unity 2019 (both 1.7 and 1.5). On some devices (tried a P8 lite, a P9 lite a P20 lite and a Samsung Galaxy A5) its super slow (like 4 FPS on average) on others (Galaxy S8, P30 Pro) it runs fine. Reverting back to and older version (2.1f2) it runs fine on all devices tested.
     
    Lanre likes this.
  33. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    I responded to your email. Sorry for the delay.
    We have an update, 2.3.0, that should improve performance on these devices. Shoot me an email with your invoice number and I'll share the build.
     
  34. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    I'm aware of the flash issue. The camera2 API seems to have totally changed flash functionality. I'll look into it sometime soon.
    I'll try to reproduce this and get back to you.
     
  35. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    Not at all unfortunately. We have to build with the official API's and nothing else.
     
  36. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    NatCam doesn't support setting the focus distance.
     
  37. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    We've fixed state management issues like this in the next update, 2.3.0. Email me with your invoice number and I'll share the build with you.
     
  38. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    On all platforms other than Android and iOS, NatCam will fall back to WebCamTexture (which does not provide this functionality). You should have gotten a warning in the console when trying to do this.
     
  39. markalles21

    markalles21

    Joined:
    Apr 2, 2019
    Posts:
    5
    Hi, I have a problem with the camera being inverted. On Android, the front facing camera (in horizontal mode) is horizontally inverted. On IOS the camera is vertically inverted (basically up side down). Is there an option where I can make sure that it is always correct?
     
  40. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    Email me with your invoice number and I'll share the 2.3.0 update that should implicitly fix these issues.
     
    markalles21 likes this.
  41. medinnoscan

    medinnoscan

    Joined:
    Apr 30, 2019
    Posts:
    1
    Hi, we have a problem setting the resolution on iOS. In contrast, on Android, the
    CapturePhoto()
    function works fine, and returns the photo with the specified resolution. But on iOS, regardless of what we set as PhotoResolution, even when set to the camera's native resolution, we always get an image of 1920x1080 pixels. This CS code in Unity:
    Code (CSharp):
    1. deviceCamera.PhotoResolution = new Vector2Int(3264, 2448);
    works fine when compiled to Android but is simply disregarded on iOS and the resolution is always 1920x1080.

    We specifically bought NatCam because it promised "NatCam allows you to set the camera's resolution." It's such a basic thing, I imagine we might be missing something. Is there something else we need to set beforehand or some other trick?
     
  42. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,378
    On iOS, you can't set the photo resolution independently of the preview resolution. Both are 'tied together' in what Apple calls 'formats'. Typically you can get the highest photo resolution by either setting the preview resolution to 1280x720 (set preview res before photo res), or by not setting a preview resolution at all.
     
  43. tonidurans

    tonidurans

    Joined:
    Jan 30, 2015
    Posts:
    6
    Hi Lanre,

    First of all thanks for your hard work. I've been using Natcam for a long time without issues, but I've started a new project using the latest Natcam on Asset Store, and the first time the camera is opened on Android, it asks for permissions and then when permissions are granted the screen remains black. Then I close the app, and open it again and it works fine. I attach an extract of the log.

    Other thing is I should provide compatibility with Android 5.0 devices in my app, and as I can see now the minimum for NatCam is 6.0. Should I work with an older version? or is there anything else I can do?

    Best regards
     

    Attached Files:

  44. WorkinBrian

    WorkinBrian

    Joined:
    Dec 5, 2016
    Posts:
    2
    Hi Lanre!

    I've got a question when you get a sec.

    I'm trying to make a QR scanner using ZXing and NatCam, but can't seem to get the
    BarcodeReader to ever return not null when trying to decode with the byte array I'm passing in from the deviceCamera's CaptureFrame function.

    The code I'm using is fairly simple I think; here's the camera setup where I am starting the camera:

    private byte[] previewData;
    private int blockWidth;

    _deviceCamera.PreviewResolution = new Vector2Int(720, 720);
    _deviceCamera.StartPreview(OnStart);

    public void OnStart(Texture preview) {
    previewData = new byte[preview.width * preview.height * 4];
    blockWidth = preview.width; // 720

    rawImage.texture = preview;
    rawImage.material.mainTexture = preview;
    fitter.aspectRatio = preview.width / (float)preview.height;
    }

    And then here's where I'm attempting to decode the previewData, in Update:

    if (_deviceCamera.IsRunning && !decoding) {
    _deviceCamera.CaptureFrame(previewData);

    Result data = barReader.Decode(previewData, blockWidth, blockWidth, RGBLuminanceSource.BitmapFormat.RGBA32
    );
    if (data != null)
    {
    Debug.Log("Data NOT NULL.");
    decoding = true;
    dataText = data.Text;
    } else {
    Debug.Log("Data NULL.");
    }

    I was able to get this working with the WebCamTexture but for whatever reason this always shows Data NULL when trying to scan our QR code. Not entirely sure what I'm doing wrong here or where to start debugging as there appears to be no errors thrown

    If you happen to have any thoughts, I'd greatly appreciate it!
     
    Last edited: Jul 19, 2019
  45. nbarber20

    nbarber20

    Joined:
    May 25, 2015
    Posts:
    1
    Hey, Im using the newest version of natcam and running it on an galaxy s8. It takes photos fine but the preview is black. It seems like some other people have this issue but i cant seem to find an answer to it anywhere on this forum.
     
  46. tonidurans

    tonidurans

    Joined:
    Jan 30, 2015
    Posts:
    6
    Hi WorkingBrian,
    I think it may be RGBLuminanceSource.BitmapFormat parameter in Decode function. Try with RGBLuminanceSource.BitmapFormat.Unknown, It will try to figure out in which format is the data.
    I have something similar working like that.
    Code (CSharp):
    1. _camera.CaptureFrame(buffer);
    2.        
    3.  
    4.         if (buffer != null)
    5.         {
    6.             BarcodeReader barcodeReader = new BarcodeReader { AutoRotate = false };
    7.             barcodeReader.Options.TryHarder = true;
    8.  
    9.             Result res = barcodeReader.Decode(buffer, imgCamera.texture.width, imgCamera.texture.height, RGBLuminanceSource.BitmapFormat.Unknown);
    10.  
    11.             if (res != null )
    12.             {
    13.                 Debug.Log("QR Found -> " + res.Text);
    14.                 OnQrRecognized(res.Text);
    15.             }
    16.         }
    I hope it may help you, best regards.
     
  47. WorkinBrian

    WorkinBrian

    Joined:
    Dec 5, 2016
    Posts:
    2
    Thanks so much, tonidurans! The problem seemed to be that my width and height were set to be equal, when I guess they need to be the exact width / height from the image. Either way, your example saved the day!!
     
    Lanre likes this.
  48. markalles21

    markalles21

    Joined:
    Apr 2, 2019
    Posts:
    5
    Having some issues with ios. I tried version 2.3.0. My project is horizontal. The one horizontal rotation works, the other one shows a 90 degree wrong rotation. Is there an easy fix for that?
    Also on IPad it seems to crash when using the rearcamera.
     
    Last edited: Jul 23, 2019
  49. neshius108

    neshius108

    Joined:
    Nov 19, 2015
    Posts:
    109
    Hey there!

    Pretty new at NatCam but I noticed that every few seconds, I get some duplicated frames. How can I fix that?
    I am using the GrayCam example and not much else.
    Since I using the camera to analyze the pixels, it is quite important for me that no duplicate frames are found. Is it a problem with the settings?
     
  50. ddkim21

    ddkim21

    Joined:
    Sep 8, 2017
    Posts:
    1
    Thanks for the awesome package!

    It does exactly what I need, with the big exception that I need to support android API level 22 (for Amazon 2017 edition Fire devices). I'm aware that the minimum API level is listed as 23. I'm wondering if there's any possible way to get NatCam working on level 22, either getting sent a legacy version, or disabling bits of functionality.
     
    Lanre likes this.
unityunity