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

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    324
    Awesome! Any idea how long this usually takes?
     
  2. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    I think about 10 days, probably a little over that.
     
  3. FyreDogStudios

    FyreDogStudios

    Joined:
    Aug 23, 2015
    Posts:
    97
    How much will this be?
     
  4. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Fifty dollars.
     
  5. 2Elemental

    2Elemental

    Joined:
    Jul 17, 2013
    Posts:
    12
    So it will be released somewhere next week? I currently have a full implementation of barcode recognition using OpenCV and WebCamTexture, but it's indeed not as performant as I'd like it to be (have only tested with Samsung Galaxy S6), and I'm only using 1280x720 as resolution. Looking forward to this package!
     
  6. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    @2Elemental It should. NatCam's barcode reading functionality is based off native implementations so there's no added layer (which means more time-consuming processing). In fact, scanning EAN_13 barcodes (ISBN codes on books) was the entire reason why we started developing NatCam.
     
  7. 2Elemental

    2Elemental

    Joined:
    Jul 17, 2013
    Posts:
    12
    That's nice to hear. In fact, it's not actually the barcode scanning that is not performant, as we can currently encode and decode pretty much every barcode, but it's the WebCamTexture that is laggy. Our barcode recognition using OpenCV only happens every 250ms, so a high FPS is not required. Does NatCam also support encoding of barcodes, or only decoding?
     
  8. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    NatCam supports decoding barcodes only. Encoding barcodes is not a part of the native camera API's
     
  9. 2Elemental

    2Elemental

    Joined:
    Jul 17, 2013
    Posts:
    12
    OK, and which barcodes and/or QR does it support for decoding?
     
  10. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    • QR
    • EAN_13 (and ISBN)
    • EAN_8
    • Data Matrix
    • PDF 417
    • Code 129
    • Code 93
    • Code 39
     
  11. 2Elemental

    2Elemental

    Joined:
    Jul 17, 2013
    Posts:
    12
    Great, I'll have to see which one is the most performant then, but this is looking good :)
     
  12. Cromfeli

    Cromfeli

    Joined:
    Oct 30, 2014
    Posts:
    202
    Any news on the release?
     
  13. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Still waiting for Unity
     
  14. sstadelman

    sstadelman

    Joined:
    Dec 17, 2013
    Posts:
    12
    Hi Lanre, very excited to give this a spin on my Samsung S6 (SM-G920V)/Android 5.1.1 !!

    I tried the Natcamagram apk linked in the thread above, and found that the Preview mode doesn't appear to be fully functioning--the screen is color sensitive, but does not display a high-resolution preview. It does display the high resolution bmp after holding the button for a few seconds.

    Image 702: static image
    Image 701: color sensitive Preview; no resolution

    Is this the expected behavior, and do you have a sample with the Preview mode enabled?
     

    Attached Files:

  15. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Hi @sstadelman We might have fixed the issue (but didn't update Natcamagram). I'll PM you for further investigation. Thank you!
     
  16. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    NatCam is currently on hold because we want to make a comprehensive scripting reference (documentation) for ease of use. Thus, there'll be a delay of about 6 days.
     
  17. tolstenko

    tolstenko

    Joined:
    May 31, 2012
    Posts:
    14
    I need this so bad! I swear I will buy it as soon as it appears on asset store. Are you accepting donations allowing me to try your code?
     
    Cromfeli likes this.
  18. aaronw

    aaronw

    Joined:
    May 13, 2013
    Posts:
    1
    @Lanre Do you have performance times for different resolutions on different devices?
    We have an application where we need the fastest possible camera frame rate at a lower resolution
    either 720p or even 480p which we want to apply a blob detection pipeline using the NEON processor.
    Will this be possible using NatCam? We dont even need the texture available in Unity although the scene rendering (which is done in Unity) is dependent on the result of our pipeline which is why we need a Unity plugin. What is the fastest frame rate at lower resolutions on an iPhone 6 and a Note 4 or Galaxy S6?
     
  19. grahamwell

    grahamwell

    Joined:
    Oct 5, 2013
    Posts:
    6
    Hi there, I got the same result as sstadelman on a Galaxy Note 5 with NatCamagram. Static resolution was fine, by default though things were just a blur. It reminded me of my efforts with Webcamtexture when I tried to read the resolution of the texture before the capture had started, ending up with 16 * 16 whatever I did.
     
  20. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Hi @aaronw NatCam will default to the highest frame rate on Android.

    On iOS however, the construct is different. The frame rate is dependent on the session preset (AVFoundation's AVCaptureSession doesn't allow you specify resolution or frame rate) and is usually (in our tests) 30FPS or 60FPS (depending on the device).

    On both platforms, you are ensured a smooth preview always. I should note that if you wish to do further processing on the preview texture (on the CPU), you should use the readable preview (this supplies the preview data instead of you trying to perform a readback from the GPU which is notoriously slow).

    Supplying a desired frame rate is on the roadmap (for version 2.0)

    EDIT: Corrected "highest resolution" to "highest frame rate".
     
    Last edited: Mar 1, 2016
  21. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Hi @grahamwell care to be a tester? We believe we fixed the issue after I posted Natcamagram but we would have to test to find out.
     
  22. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Also, I will be posting a link to NatCam's documentation in a few days. To create it, we are developing a package called Calligraphy that easily creates API documentation for your C# API's.
     
  23. sstadelman

    sstadelman

    Joined:
    Dec 17, 2013
    Posts:
    12
    @Lanre from your response to @aaronw, it looks like there are two options for accessing the preview texture:
    (1): 'view'-only (GPU-only), does not permit processing or OpenCV access, etc.
    (2): 'read'-access (CPU), permits processing, OpenCV access, etc.

    If so, this is very good--it definitely seems that we'll be in the (1) camp.
     
  24. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Hi Stan @sstadelman. This is 100% correct. A brief history lesson:

    Originally, NatCam got the preview frame from the device camera and uploaded it directly to the GPU (this was especially crucial on Android where we needed fluid frame rates, and to perform a transformation on the textures--processes that proved all too slow on the CPU). But due to the persistence of the OpenCV community, we had to make the textures accessible to the CPU (we needed a way to perform a readback from the GPU to the CPU). On iOS, this was relatively easy whereas on Android, it was hell--literally. Anyone familiar with OpenGL programming is aware of the notorious glReadPixels. After several days of nerve-racking research and coding, we finally implemented a very performant way of doing performing a readback at little-to-no cost (available on GLES2, GLES3, and GLES3.1AEP, which account for ALL Android devices that run Unity).

    NatCam's Initialize method has a parameter that specifies whether the preview should be readable or not. Although the cost is very little, it is there. That's why we didn't just create NatCam will readable previews all the time.

    As a prominent graphics programming expert and stackoverflow-ist said (paraphrased):
     
  25. sstadelman

    sstadelman

    Joined:
    Dec 17, 2013
    Posts:
    12
    Makes perfect sense. We're doing an AR app on Android that is *not* reliant on bar code or image processing for camera positioning. (In fact, we're replacing the Vuforia AR camera, since we no longer need their feature-set). So, we'll probably be opting for the non-readable parameter value.
     
  26. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    @sstadelman Interesting. I'm curious as to how that works. Did you receive my email?
     
  27. sstadelman

    sstadelman

    Joined:
    Dec 17, 2013
    Posts:
    12
    Yes, installed and it is working as expected. Looks quite sharp! There is a slight motion lag as you pan very quickly, but I benchmarked that behavior against the native Android device Camera app, (and the native iOS Camera) and it's comparable in Unity to the Native apps.
    One thing which will be interesting is how to manage the autofocus behavior for a GearVR headset app. It hasn't been a massive issue for us thus far with the WebCamTexture (since everything is pretty fuzzy) but with the higher resolution, you might notice it a little more. Will share some research on what we see when we put it in the Gear.
     
  28. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    @sstadelman That's great.

    When you quick-pan the camera, I'm sure that the sensor (or its driver) skips frames. I'm almost 100% sure that that's why.
     
  29. pStar

    pStar

    Joined:
    Jun 26, 2013
    Posts:
    7
    Hi @Lanre, I've been following this thread since I've started looking for a solution for the ever slow Webcamtexture. I have a conceptual app running with Vuforia on the GearVR. I'd like to substitute Vuforia with Natcam as I'm currently only using the passthrough camera feature. Vuforia has been clocking reasonable good speed on the Note4, but I'd like to see faster frame updates, and less jitter.

    I looked for the .apk to test, but I can't seem to find it. Please advise?

    Thank you for the awesome work.
     
  30. shoveltoolsinc

    shoveltoolsinc

    Joined:
    Aug 16, 2015
    Posts:
    12
    I have a note4 and s6 with GearVR. I would love to implement NatCam and use the preview camera feature. Let me know when its up or if I can test out implementation!
     
  31. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    NatCam is almost submitted. The wait has been on a new package we have been developing called Calligraphy, which helps us quickly generate a scripting reference right from the editor. Calligraphy is almost done, and when it is, I'll generate NatCam's documentation and upload it, then submit it for review.
     
  32. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    NatCam support for Android IL2CPP is no more marked experimental as all the APK's we've built and sent out were built with the IL2CPP backend, and we have not seen any issues with it.
     
  33. shoveltoolsinc

    shoveltoolsinc

    Joined:
    Aug 16, 2015
    Posts:
    12
    Any update on the release? Can't wait to play with this.
     
  34. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    NatCam will be released next week. I am performing some last minute changes and developing the scripting reference generator.
     
    tolstenko likes this.
  35. pStar

    pStar

    Joined:
    Jun 26, 2013
    Posts:
    7
    @Lanre That's great news!
     
  36. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Check out NatCam's scripting reference here!.

    EDIT: Google Drive's hosting is pretty neat.
     
  37. Vern_Shurtz

    Vern_Shurtz

    Joined:
    Mar 6, 2009
    Posts:
    264
    Very cool!! Any news on release in the Asset Store?
     
  38. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    @Vern_Shurtz Thank you! The plan is to wrap up in the next 5 hours and send it back to Unity. I'll keep this thread updated.
     
    xfer, Cromfeli and jcarpay like this.
  39. xfer

    xfer

    Joined:
    Mar 30, 2015
    Posts:
    3
    Any news about on release in the Asset Store? Or a way to get the plugin outside the store? Or a beta? :D

    (I have a deadline and from what I read, NatCam will help me a lot, heh)
     
  40. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Finally finished! Waiting on Unity.
     
    pStar and SioHio like this.
  41. Vern_Shurtz

    Vern_Shurtz

    Joined:
    Mar 6, 2009
    Posts:
    264
    Excellent. :)
     
  42. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    bariscigal and ikazrima like this.
  43. Cromfeli

    Cromfeli

    Joined:
    Oct 30, 2014
    Posts:
    202
    Please make sure to add the source code other ways it is impossible to use it for any production system :(
     
    SioHio likes this.
  44. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Hi @Cromfeli. We plan to do so in the next minor release. We did not include native sources because we need to make some changes and improvements. We will be finished with these late next week. Stay tuned!
     
    SioHio and Cromfeli like this.
  45. SioHio

    SioHio

    Joined:
    Oct 3, 2015
    Posts:
    6
    Can you post an update when the sources are included? :)
     
  46. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    @SioHio I sure will. We will be including all native sources except Android C++ (the native native layer). We have to perform an optimization for OpenGLES3 devices that won't make NatCam v1.1.

    We will also be adding a new delegate to provide access to the native pixel data, and access to the preview's pixel data in memory. This way, you can send the IntPtr to your own native plugins for operations (don't forget to memcpy).

    Also, we are working to provide much tighter and stable OpenCV support with EnoxSoftware, the great people responsible for OpenCVForUnity. AR is also a new and upcoming focus.
     
    Cromfeli and Dotby like this.
  47. Cromfeli

    Cromfeli

    Joined:
    Oct 30, 2014
    Posts:
    202
    I hope you maintain clean separation between different modules. Rather on the level of disabling/enabling those modules that one needs. I would not like your plugin to become hairy monster :)
     
  48. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    @Cromfeli We sure will! The source files and instructions will be in a zip folder, not interfering with anything. Overall, we aren't making any changes where we enable something one person needs.
     
  49. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Hi, putting this on my list of things to watch :)

    Few questions:
    What does it mean "except Android C++", are you referring to the original android source code from Google, or some code you wrote yourself in c++?

    All the images in the asset store are fullscreen, the texture access isn't implemented yet?
    If it has, you may want to add some different preview.

    Is there still a lot of difference when you use the texture compared to webcamtexture or a lot of the gain is lost?
     
  50. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Hi @00christian00

    -By Android C++, I'm referring to the C++ code we wrote ourselves. It is very extensive, and will require special instructions for handling once we include it. We aren't including it in v1.1 because we have to investigate whether we can squeeze out more performance on OpenGLES3 devices when performing a readback by using Pixel Buffer Objects.

    -Oh I didn't think of that. It seems those images are misleading. The preview is returned as a Texture2D (you can check the documentation under Classes>NatCam>Preview. To ensure compatibility across unsupported platforms (non-iOS and non-Android platforms), there is also PreviewTexture which is a Texture (either a Texture2D on supported platforms, or a WebCamTexture on unsupported platforms, downcast to a Texture). I have noted this, and I will add better images. Thank you.

    -The first difference you see is the crisp resolution (if you specify one, like FullHD or HighestReoslution). The next is the speed. It. Is. Fast. Much faster than WebCamTexture on a significant number of devices. And of course, all the other features are icing on the cake.
     
    00christian00 likes this.