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

OpenCVSharp for Unity

Discussion in 'Assets and Asset Store' started by NWHCoding, Oct 8, 2017.

  1. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    LogoDark.png

    Fast and easy to use asset that brings OpenCV functionality to Unity.
    Features:
    • Supports following platforms: Windows, Linux, Mac OS X, Android and iOS.
    • Works both in editor and as a standalone.
    • Includes fast functions for easy conversion between common Unity and OpenCV structures (WebCamTexture to Mat, Mat to Color32[], etc.). No conversion is done iteratively.
    • Uses vanilla C++ OpenCV 3.3.1 with C# wrapper and syntax.
    • Due to the direct calls from C# to the C++ native OpenCV plugins 60+ FPS is easily achievable on mobile, and 200+ FPS on desktop devices.
    • IDisposable is implemented along with exception redirection to standard Unity errors.

    Conversion functions:
    • MatToTexture2D
    • MatToColor32Array
    • Texture2DToMat
    • Texture2DToColor32
    • Texture2DToRenderTexture
    • Color32ArrayToMat
    • Color32ArrayToTexture2D
    • Color32ArrayToByteArray
    • ByteArrayToColor32Array
    • RenderTextureToTexture2D
    • WebCamTextureToMat
    • WebCamTextureToTexture2D
    • WebCamTextureToRenderTexture
    Conversions are mostly made through memory copy or similar methods and work on all supported devices - no iterative conversions. RenderTextureToTexture2D conversion also allows use of OpenCV on in-game cameras - such as the line following robot example.


    Included modules:
    • core
    • calib3d
    • imgproc
    • shape
    • superres
    • stitching
    • video
    • aurco
    • bgsegm
    • dnn
    • face
    • img_hash
    • optflow
    • tracking
    • xfeatures2d
    • imgproc
    • xphoto
    • text

    Included helper functions:
    • GetWebCamTexture2D - returns image from webcam as Texture2D.
    • GetWebCamMat - return image from webcam as OpenCV mat.
    • GetIntPtr - returns pointer to the structure.
    • GetStreamingAssetsPath - returns path to the file in the Streaming Assets folder. Platform independent. Useful for ImRead and similar functions that require path to the file.

    More info:
    Website
    Youtube Channel



    Demos:
    Windows (64-bit)
    Windows (32-bit)
    MacOS
    Android
    iOS


    For more info and screenshots check out OpenCVSharp for Unity website.

    Asset is now available on the Unity Asset Store. Click here to visit.
     

    Attached Files:

    Last edited: Jul 4, 2018
  2. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
  3. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,302
    According to README:
    this is not true - except StreamingAssets folder - since Unity 5.something - Plugins folder can be placed anywhere below root Plugins folder and Unity will consolidate all of them.
    I like to keep things organized so I just moved the whole OpenCVSharpForUnity folder into Plugins - works okay.
    But the main caveat after importing is to set manually each respective native dll to correct architecture:

    upload_2017-12-5_15-3-52.png

    otherwise the Editor will complain it can't distinguish between same named libraries and example scenes won't work. ( this is 2017.2 )

    This should be mentioned in the documentation, or enforced on import ( don't know if asset store package upload preserves meta file import setting tbh )

    On Android with some landscape orientation I had camera image upside down and Hough lines sample reliably crashed the app. :) Haven't tested on iOS yet.

    But other than the above I'm really glad you chose to all native opencv libraries, and include sources for iOS - performance is great !

    Cheers
     
  4. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Hello,
    sorry for the confusion. I believe that the switch happened when going from 5.x to 2017.x. I initially made it for 2017.1 and then ported it back to 5.6 to ensure backwards compatibility. I will need to fix this on both this asset and Grapher. I will indeed have to mention this in the manual so people with newer versions of Unity do not get confused.
    I am also glad you like the rest, development and building for each platform was hell and took me a lot of time.
     
    r618 likes this.
  5. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,302
    @NWHCoding unfortunately link step on iOS fails for me:

    (with practically everything getting unresolved afterwards)

    strangely, my attempt to specify just armv7 in target build settings fails too:

    I don't know what exactly this means for the format of frameworks to be compiled as ( I've mistakenly thought that iOS frameworks are distributed as sources - all the hpp's mislead me o), but it seems that something is missing in them currently for Xcode to be satisfied
    this is latest Xcode 9.2 compiling for 11.2
     
  6. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Uh, oh. I have built for iOS just two days ago on High Sierra with XCode 9.2 and the build went without a problem. Granted, I do not have an actual iOS device to test it on, but I sure did not get the message. iOS frameworks (unfortunately) are not distributed as source (which would be nice). They need a lot of building actually, the headers are there for Unity. I have a feeling this might be something related to build settings and/or iOS version.

    Here is a screenshot from two days ago:
    2017-12-05_20-13-14.png

    And here are the settings:
    upload_2017-12-5_20-15-11.png

    Also, in the folder Plugins/iOS there are 3 files and each should have iOS ticked. I doubt this is the problem since Unity seems to find correct plugins.

    Could you please try and build with those settings? I am on a virtual machine and my build will take some time. If you want you could send me your settings and I will try to build with those. iOS is very picky about everything.

    EDIT: Also tried setting 11.2 as target and it passed.
     
  7. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,302
    I've been building iOS stuff since unity 1.6, of course I have all basics set and am providing support for my own iOS integration, occasionally ]

    Have you ever built for and run on an actual iOS device ?

    build for Generic iOS device in Xcode fails with the same linker errors

    Everything it would take to reproduce this is getting current version of the package from the store, import into new project, build for iOS, and build Xcode project.
    Let me know if you are able to repro this.
     
  8. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,302
    Ah, according to file OpenCvSharpExtern is indeed missing arm architectures:

    opencv2 itself:

    so that would probably explain it - now to actually build the extern fat library is all that is left
    Good luck and don't stress about this - just let me know once update is ready.
    Cheers!
     
    Last edited: Dec 5, 2017
  9. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Thank you for the spot, since I do not own the actual device I managed to oversee this - simulator only supports i386 and x86_64 which is a bit lame. Will fix it tomorrow as it is getting a bit late now and send you the fixed package. Asset Store update will follow as soon as admins approve it.
    Once again thank you for the bug report and sorry for the problems.
     
  10. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Missing architecture problem for iOS (device) has been fixed and will be released as an update 1.1.
    It will be pushed to the store tomorrow which means it will be available for download from the store in a few days, after it has been approved.
    If you need it sooner send me a PM or email and I will send it to you.
     
    r618 and lukesUbuntu like this.
  11. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Price has been reduced to $28 for the time being.
     
    r618 likes this.
  12. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    New update coming during the next week. Asset will be updated to OpenCV 3.3.1 and newest OpenCvSharp wrapper.
     
  13. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Update has been finalized and beta is available. Asset Store release will be beginning of the next week.
    If anybody wants to try it out sooner send me a PM or an email with your invoice.
     
  14. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Hi,

    Do you have any examples with ArUCo marker detection?
     
  15. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    No, only the examples from the Menu scene are included. Still, this asset uses OpenCvSharp wrapper so any code written for it will work here too, and porting from C++ is not hard since syntax is quite similar (not same tho).
     
  16. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Thanks for the reply.
     
  17. mrmoonshield

    mrmoonshield

    Joined:
    Feb 27, 2018
    Posts:
    2
    Hi, in opencv TermCriteria for optical flow is written as follows:
    TermCriteria termcrit(TermCriteria::COUNT | TermCriteria::EPS, 20, 0.03);
    how does it declare in OpenCVSharp?
     
  18. Deleted User

    Deleted User

    Guest

    Gaussian and Median blur is crashing.
     
  19. Omini

    Omini

    Joined:
    Jul 16, 2013
    Posts:
    9
    Unity crashes when I try to draw markers. Any idea why? Here is my code:

    Code (CSharp):
    1.        
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Runtime.InteropServices;
    5. using UnityEngine;
    6. using OpenCvSharp;
    7. using NWH;
    8. using UnityEngine.UI;
    9. using OpenCvSharp.Aruco;
    10. public class Marker : MonoBehaviour {
    11.     private RawImage rawImage;
    12.     private WebCamTexture webCamTexture;
    13.     private Texture2D tex;
    14.     private Mat mat, gray;
    15.     Dictionary dictionary;  
    16.     void Start()
    17.     {
    18.         dictionary = CvAruco.GetPredefinedDictionary(PredefinedDictionaryName.Dict5X5_50);
    19.         rawImage = GameObject.Find("Canvas/RawImage").GetComponent<RawImage>();
    20.        
    21.         webCamTexture = new WebCamTexture(WebCamTexture.devices[0].name);
    22.         webCamTexture.Play();
    23.         mat = new Mat(webCamTexture.height, webCamTexture.width, MatType.CV_8UC3);
    24.         gray = new Mat(webCamTexture.height, webCamTexture.width, MatType.CV_8UC1);
    25.         tex = new Texture2D(webCamTexture.width, webCamTexture.height, TextureFormat.RGBA32, false);
    26.     }
    27.     void Update()
    28.     {              
    29.         if (webCamTexture.didUpdateThisFrame && webCamTexture.isPlaying)
    30.         {
    31.         CamUpdate();
    32.         }
    33.     }
    34.     void CamUpdate()
    35.     {
    36.         CvUtil.GetWebCamMat(webCamTexture, ref mat);
    37.         int[] ids;
    38.         Point2f[][] corners;
    39.         Point2f[][] rejects;
    40.         InputArray markers;
    41.         DetectorParameters parameters = DetectorParameters.Create();
    42.         markers = InputArray.Create(gray);      
    43.         CvAruco.DetectMarkers(markers, dictionary, out corners, out ids, parameters, out rejects);
    44.         CvAruco.DrawDetectedMarkers(mat, corners, ids);      
    45.         CvConvert.MatToTexture2D(mat, ref tex);
    46.         rawImage.texture = tex;
    47.     }
    48.     private void OnDestroy()
    49.     {
    50.         webCamTexture.Stop();
    51.     }
    52. }
    53.  
     
  20. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Could you paste your code?
     
  21. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    I am looking at this and possibly the reason for the crash in the post above.
     
  22. Omini

    Omini

    Joined:
    Jul 16, 2013
    Posts:
    9
    Thanks, I got it working. I was not converting the image color formats, so it was crashing Unity. Maybe you should catch the exceptions so at least unity doesn`t crash? Or maybe pass the exception to unity so we can handle it. Here is the final code:
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Runtime.InteropServices;
    5. using UnityEngine;
    6. using OpenCvSharp;
    7. using NWH;
    8. using UnityEngine.UI;
    9. using OpenCvSharp.Aruco;
    10.  
    11. public class Marker : MonoBehaviour
    12. {
    13.     private RawImage rawImage;  
    14.     private WebCamTexture webCamTexture;
    15.     private Texture2D tex;
    16.     private Mat mat, gray;
    17.     Dictionary dictionary;
    18.  
    19.     void Start()
    20.     {
    21.         dictionary = CvAruco.GetPredefinedDictionary(PredefinedDictionaryName.DictArucoOriginal);
    22.         rawImage = GameObject.Find("Canvas/RawImage").GetComponent<RawImage>();      
    23.         webCamTexture = new WebCamTexture(WebCamTexture.devices[0].name);
    24.         webCamTexture.Play();
    25.         mat = new Mat(webCamTexture.height, webCamTexture.width, MatType.CV_8UC4);      
    26.         gray = new Mat(webCamTexture.height, webCamTexture.width, MatType.CV_8UC1);
    27.         tex = new Texture2D(webCamTexture.width, webCamTexture.height, TextureFormat.RGBA32, false);      
    28.     }
    29.  
    30.     void Update()
    31.     {
    32.         if (webCamTexture.didUpdateThisFrame && webCamTexture.isPlaying)
    33.         {
    34.             CamUpdate();
    35.         }
    36.     }
    37.  
    38.     void CamUpdate()
    39.     {
    40.         CvUtil.GetWebCamMat(webCamTexture, ref mat);
    41.         int[] ids;
    42.         Point2f[][] corners;
    43.         Point2f[][] rejects;
    44.  
    45.         DetectorParameters parameters = DetectorParameters.Create();
    46.         Cv2.CvtColor(mat, gray, ColorConversionCodes.RGBA2GRAY);
    47.         CvAruco.DetectMarkers(gray, dictionary, out corners, out ids, parameters, out rejects);
    48.         Cv2.CvtColor(mat, mat, ColorConversionCodes.RGBA2RGB);
    49.         CvAruco.DrawDetectedMarkers(mat, corners, ids);      
    50.         CvConvert.MatToTexture2D(mat, ref tex);
    51.         rawImage.texture = tex;
    52.     }
    53.  
    54.     private void OnDestroy()
    55.     {
    56.         webCamTexture.Stop();
    57.     }
    58. }
    59.  
     
    Last edited: May 5, 2018
  23. Omini

    Omini

    Joined:
    Jul 16, 2013
    Posts:
    9
    Check out my code above! Works like a charm! I`m using the original markers, but you can change the dictionary.
     
  24. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Great. I will still be rolling an update since as you mentioned crashes should not happen.
     
    Last edited: May 5, 2018
  25. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Version 1.3 has been submitted for approval - expect it in about 2 working days since it needs to be approved by Asset Store team first.
    Most of the problems above should now be solved and error reporting improved.
     
  26. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,302
    Did you wrap all calls in native parts in try {} catch {} statements ? -
    Since exception thrown from native code usually ends up crashing in unity
     
  27. Omini

    Omini

    Joined:
    Jul 16, 2013
    Posts:
    9
    Thanks!
     
  28. Omini

    Omini

    Joined:
    Jul 16, 2013
    Posts:
    9
    How can I call cv::aruco::estimatePoseSingleMarkers? If it's not possible, do you plan to support in the future?
     
  29. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    The feature was added in OpenCvSharp 3.4.1 (while the one used here is 3.3.1). I tend to keep one version behind because there are usually hundred or more fixes between the release (which was just a few weeks ago) and the next one. So in short, not supported in this version but will be supported in 1.4.
     
    Last edited: Jun 28, 2018
  30. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Update 1.3 is out but there has been a small mistake when uploading the version, StreamingAssets folder was left out. '
    If you just updated from 1.2 it will not be a problem as you already have it, but for those that are new to the asset the Thresholds and Face Detection scenes will not work. Other than those two demo scenes everything else will work fine.
    Fixed package has been uploaded just now and will be available in one or two days, if anybody needs StreamingAssets directory immediately I can send it via email.

    Sorry for the complication.
     
  31. Vander-Does

    Vander-Does

    Joined:
    Dec 22, 2015
    Posts:
    19
    @NWHCoding I just purchased this asset to perform aruco detection and pose estimation. It looked like pose estimation was supported based on your auto-gen docs http://46.101.247.190:9994/group__aruco.html#ga98806f0a781224132febfad0b2c71b3a, but seems it isn't based on the above comment.

    I'm also a bit confused because you say that function was added in 3.4, but based on the opencv docs its been there from at least 3.1 https://docs.opencv.org/3.1.0/d9/d6a/group__aruco.html.

    Anywho, any thoughts on a timeline for getting this function added?
     
  32. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Update to OpenCV 3.4.1 will be out somewhere around the middle of the next week, along with some changes to conversion functions to improve performance and reduce memory footprint.

    EDIT: EstimateSinglePoseMarkers will be avilable with the update.
     
    Last edited: Jun 28, 2018
  33. Vander-Does

    Vander-Does

    Joined:
    Dec 22, 2015
    Posts:
    19
    @NWHCoding it doesn't show up in the editor. You sure its there?
     
  34. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Correct. I have just checked. I was on mobile, out of office yesterday and was using git search which apparently does not search the selected commit/tag but the latest commit.
    Commit "add aruco EstimatePoseSingleMarkers" was for tag 3.4.1 and so while OpenCV does have it (which you saw in the auto-generated docs) it has only been implemented in OpenCvSharp 3 months ago. I hope waiting a few days is not a problem, or if it is you can send me an email with your invoice and I will send you the newest version. Currently only Mac OS and iOS have not been built.
     
    Vander-Does likes this.
  35. Vander-Does

    Vander-Does

    Joined:
    Dec 22, 2015
    Posts:
    19
    @NWHCoding thank you for the update. A few days is no problem for me.
     
  36. Vander-Does

    Vander-Does

    Joined:
    Dec 22, 2015
    Posts:
    19
  37. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Yep. Building done, testing has only iOS left and currently reworking CvConvert. I will be most likely pushing today evening and allow it 2-3 days to get approved.
     
    Vander-Does likes this.
  38. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Version 1.4 has been pushed to the store and will be available after it is approved by Asset Store team.

    Changes:
    • Upgraded to OpenCV 3.4.1.
    • Upgraded to latest OpenCvSharp commit.
    • Improved preformance of conversion functions.
    • Introduced support for 1, 2, 3 and 4 channel Texture2D/Mat conversions (8UC1 to R8, 8UC2 to RG16, 8UC3 to RGB24 and 8UC4 to RGBA32 and vice versa).
    • Moved to Unity 2017.4.6f1 (LTS).
    • Reduced native iOS plugin size by ~70%.
    • All native plugins are now single file per platform.
    • Fixed Android issue with transparent lines / rectangles (check README_ANDROID.txt).
    • Fixed Android crashing when drawing lines.
    • Fixed possible memory leak with some conversion functions.
    • Other minor improvements.
     
    Last edited: Jul 4, 2018
    Vander-Does likes this.
  39. Vander-Does

    Vander-Does

    Joined:
    Dec 22, 2015
    Posts:
    19
    Thanks @NWHCoding, looking forward to trying it out.
     
  40. mrnobody93

    mrnobody93

    Joined:
    Oct 27, 2015
    Posts:
    1
    Demo scenes don't work in Unity 2018.2.0f2 on Win10:
    • Thresholds
      FileNotFoundException
      OpenCvSharp.Mat..ctor (System.String fileName, ImreadModes flags)
      OpenCvSharp.Cv2.ImRead (System.String fileName, ImreadModes flags)
      Thresholds.Start () (at Assets/OpenCVSharpForUnity/Examples/DemoScenes/Thresholds/Thresholds.cs:20)
    • SimpleBlobDetection
      Texture2D and Mat must have same dimensions and number of channels. Tex: 640x480, RGBA32 | Mat: 640x480, CV_8UC3.
      UnityEngine.Debug:LogError(Object)
      NWH.CvConvert:MatToTexture2D(Mat, Texture2D&) (at Assets/OpenCVSharpForUnity/Scripts/CvConvert.cs:59)
      SimpleBlobDetection:CamUpdate() (at Assets/OpenCVSharpForUnity/Examples/DemoScenes/SimpleBlobDetection/SimpleBlobDetection.cs:82)
      SimpleBlobDetection:Update() (at Assets/OpenCVSharpForUnity/Examples/DemoScenes/SimpleBlobDetection/SimpleBlobDetection.cs:31)
    • FAST
      FileNotFoundException
      OpenCvSharp.Mat..ctor (System.String fileName, ImreadModes flags)
      OpenCvSharp.Cv2.ImRead (System.String fileName, ImreadModes flags)
      FAST.Start () (at Assets/OpenCVSharpForUnity/Examples/DemoScenes/FAST/FAST.cs:25)
    • FaceDetection
      FileNotFoundException: "D:/Škola/DP/DP3/Assets/StreamingAssets\haarcascade_frontalface_alt2.xml"not found
      OpenCvSharp.CascadeClassifier..ctor (System.String fileName)
      FaceDetection.Start () (at Assets/OpenCVSharpForUnity/Examples/DemoScenes/FaceDetection/FaceDetection.cs:28)

      NullReferenceException: Object reference not set to an instance of an object
      FaceDetection.DetectFace (OpenCvSharp.CascadeClassifier cascade, OpenCvSharp.Mat src) (at Assets/OpenCVSharpForUnity/Examples/DemoScenes/FaceDetection/FaceDetection.cs:98)
      FaceDetection.CamUpdate () (at Assets/OpenCVSharpForUnity/Examples/DemoScenes/FaceDetection/FaceDetection.cs:47)
      FaceDetection.Update () (at Assets/OpenCVSharpForUnity/Examples/DemoScenes/FaceDetection/FaceDetection.cs:37)

    I have fresh installation of Unity, first project in this version, and this is always the first thing I try, when I buy package, demo scenes. I could fix that errors, but why if I paid for that. And for me if basic demoscenes are not ok, how can I trust this package. And also first error from Menu scene will be forever for everyone if you won't make changes in structure. Scenes are missing in build settings. That is also not very good first impression. But it's easy to fix.
     
  41. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    Have you read the README.txt and moved the StreamingAssets folder into parent folder? It should be Assets/StreamingAssets and you probably have Assets/OpenCvSharp/StreamingAssets.
     
  42. Vander-Does

    Vander-Does

    Joined:
    Dec 22, 2015
    Posts:
    19
    @NWHCoding does the library provide mapping between unity and opencv's coordinate system?
     
  43. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    I am assuming we are talking about Vec2f, Point and similar? Then no, since the conversion is simple enough that I did not bother including conversions for each and every type. But in general something like this will work fine:

    Code (CSharp):
    1. public static Vector3 PointToVector3(Point point)
    2. {
    3.        return new Vector3(point.X, point.Y, point.Z);
    4. }
    Pretty much the same for Vec3f, Vec2f, Vec3i, etc.
    Of course of you are doing it a lot you might want to avoid creating the new vector each frame and use out or ref instead.
     
  44. StaffanEk

    StaffanEk

    Joined:
    Jul 13, 2012
    Posts:
    380
    Just purchased the asst and I'm interested in doing some perspective transformation like here. I'm probably being stupid, but how do I construct a new InputArray? Is there another way to create a PerspectiveTransform?

    EDIT:
    Ok so you create the transformation arrays by simple creating a multidimensional float array like so:
    Code (CSharp):
    1.         float[,] pts2 = { { 0, 0 }, { 300, 0 }, { 0, 300 }, { 300, 300 } };
    Then the resulting Mat that you get from GetPerspectiveTransform is the conversion matrix
     
    Last edited: Aug 16, 2018
  45. EdgarSantos

    EdgarSantos

    Joined:
    Nov 11, 2013
    Posts:
    27
    @NWHCoding quick question.

    Do you plan on adding UWP support (e.g. to use with Hololens)?
     
  46. bsawyer

    bsawyer

    Joined:
    May 6, 2014
    Posts:
    37
    @NWHCoding Hi, does this plugin implement the SURF feature from the xfeatures2D module?
     
  47. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    I will look into it with next update of the OpenCvSharp. You might want to check out OpenCvSharp-UWP by Firifire on github.
     
  48. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,685
    SURF is implemented, but note that some of the C++ functionality might not be available.
    Included are following functions / properties:
    • Create
    • HessianThreshold
    • NOctaves
    • NOctaveLayers
    • Extended
    • Upright
     
  49. weareinteractive

    weareinteractive

    Joined:
    Apr 14, 2017
    Posts:
    12
    I have the same problem with SimpleBlobDetection Demo... "Texture2D and Mat must have same dimensions and number of channels. Tex: 640x480, RGBA32 | Mat: 640x480, CV_8UC3 RGB24 RGBA32."

    The problem is the tex.format is different from textureFormat. After some time looking for a solution I realized that mat is supposed to be in the format CV_8UC4 and not in CV_8UC3. With some debugging I realized that after the Cv2.DrawKeypoints () method the format is changed ... Does anyone have a solution?
     
  50. weareinteractive

    weareinteractive

    Joined:
    Apr 14, 2017
    Posts:
    12
    One solution is change in SimpleBlobDetection.cs the line 22 to
    tex = new Texture2D(webCamTexture.width, webCamTexture.height, TextureFormat.RGB24, false);