Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[RELEASED] OpenCV for Unity

Discussion in 'Assets and Asset Store' started by EnoxSoftware, Oct 30, 2014.

  1. JesseYang

    JesseYang

    Joined:
    Jan 10, 2016
    Posts:
    1
    Does this support loading a mat from yaml files with FileStorage or other methods? Like this:

    Code (CSharp):
    1.     cv::Mat data;
    2.     cv::FileStorage Data(fileName, cv::FileStorage::READ);
    3.     Data["data"] >> data;
    4.     Data.release();
     
  2. Leoxi

    Leoxi

    Joined:
    Apr 25, 2014
    Posts:
    5
    Hi,Please tell me what version 4.6.9f1 of unity corresponding to the opencv
     
  3. lsewata

    lsewata

    Joined:
    Mar 24, 2015
    Posts:
    8
  4. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    For now there is no such sample code.
     
  5. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    Unfortunately, FileStorage class is not implemented in "OpenCV for Untiy".
     
  6. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    "OpenCV for Unity" works in Unity 4.6.0 or higher.
     
  7. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
  8. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    OpenCV for Unity
    Released Version 1.2.7


    Version changes
    1.2.7
    [Common] Added Beta11 Version of “OpenCV for Untiy” based on “OpenCV3.0.0”(Added mjpeg format support in VideoCapture class).
     
  9. almaris

    almaris

    Joined:
    Jan 15, 2016
    Posts:
    4
    Hello EnoxSoftware,
    When purchasing OpenCV for Unity, we were under the impression it was a complete wrap of OpenCV3.0.0 for Java, which includes VideoWriter functionality (See http://docs.opencv.org/3.0.0/dd/d9e/classcv_1_1VideoWriter.html) - as our sole purpose of purchase.

    Since the VideoWriter class is so straightforward, when can you add DLL bindings to allow my team to proceed with this?

    Thank you for your time.
     
  10. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    Unfortunately, the VideoWriter function is not implemented now.
    In the future, when the "OpenCV for Unity" is updated to OpenCV3.1, I plan to implement the VideoWriter function.
     
  11. SunnyChow

    SunnyChow

    Joined:
    Jun 6, 2013
    Posts:
    360
    I know this looks like a newbie question. How to do blob detection with your plugin? I can't find any class for this feature. It seems in other developer platform, they need an external library to do that.
     
  12. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
  13. sunnysun

    sunnysun

    Joined:
    Jul 24, 2015
    Posts:
    13
    Hi! I'm having linking problem about undefined symbols for architecture arm64 while building my project in xcode. May i know what causes the problem? Thanks alot!

    20160122_181422.jpg
     
  14. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    Could you tell me the build environment? Unity Version, Xcode Version, OpenCV for Untiy Version.
    Also, Is Build of OpenCVForUnitySamples successful?
     
  15. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    OpenCV for Unity
    Released Version 1.2.8


    Version changes
    1.2.8
    [iOS]Fixed malloc_error that occurs in Unity5.3.1p2.
    [Common]Added Beta12 Version of “OpenCV for Untiy” based on “OpenCV3.0.0”.
     
  16. sunnysun

    sunnysun

    Joined:
    Jul 24, 2015
    Posts:
    13
    Hi sorry for the late reply. I have tried building OpenCVForUnitySamples in XCode and I still get the same error. Im currently using Unity version 5.2.2f1 (Pro Version) , XCode version 7.2 and OpenCV for Unity 1.2.0.
     
  17. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    Do opencv2.framework is correctly Setting? Please Select platform iOS in Inspector.
    Also,Unity5.2.2f1 does not correspond to Xcode7.2.
     
  18. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    OpenCV for Unity
    Released Version 1.2.9


    Version changes
    1.2.9
    [Common]Added fastTexture2DToMat() and fastMatToTexture2D().
    [Common] Renewed the samples using WebCamTextureToMatHelper.(Supports all screen orientation.)
    [Common] Added Beta13 Version of “OpenCV for Untiy” based on “OpenCV3.0.0”.
     
  19. SunnyChow

    SunnyChow

    Joined:
    Jun 6, 2013
    Posts:
    360
    is there an effective way to scan a Mat in a loop. Now I am using get(), which is very slow. I know that if C++ original version there is a way to loop it with the pointer. But I am not sure how to do in your plugin.


    Code (CSharp):
    1. for(int x = 0 ;x< cols;x++){
    2.  for(int y = 0 ;y< rows;y++){
    3.   mat.get(y,x,array);
    4.   //do things
    5.  }
    6. }
     
  20. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    Unfortunately, There is no way to use the pointer.
    It is possible to get a byte array of all of the pixel at a time.
    Code (CSharp):
    1.  
    2.                         Mat imgMat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC4);
    3.  
    4.                         byte[] data = new byte[imgMat.total () * imgMat.elemSize ()];
    5.                        
    6.                         //It is possible to get a byte array of all of the pixel at a time.
    7.                         imgMat.get (0, 0, data);
    8.  
    9.                         int cols = imgMat.cols ();
    10.                         int rows = imgMat.rows ();
    11.                         int channels = imgMat.channels ();
    12.                         for (int x = 0; x< cols; x++) {
    13.                                 for (int y = 0; y< rows; y++) {
    14.                                         for (int c = 0; c< channels; c++) {
    15.                                                 Debug.Log ("x:" + x + " y:" + y + " channel:" + c + " data:" + data [(y * cols + x) + c]);
    16.                  
    17.                                         }
    18.                                 }
    19.                         }
     
  21. MORKANE

    MORKANE

    Joined:
    Feb 13, 2015
    Posts:
    3
    Why show error in "namespace" ??:(:(
     
  22. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    Which script file does it happen?
     
  23. paprocjo

    paprocjo

    Joined:
    May 16, 2012
    Posts:
    12
    Trying to use HoughLines but it is always coming back empty



    Code (CSharp):
    1.  Mat originalToPlaywith = Room.OriginalRGB;
    2.             Mat dst = new Mat();
    3.             Mat cdst = new Mat();
    4.  
    5.             Imgproc.Canny(originalToPlaywith, dst, 50.0, 200);
    6.             Imgproc.cvtColor(dst, cdst, Imgproc.COLOR_GRAY2BGR);
    7.  
    8.             Mat lines = new Mat();
    9.             Imgproc.HoughLines(dst, lines, (double)Mathf.PI / 180, 100, 0);
    Anyone have any ideas? The Canny comes through nice and clean
     
  24. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    http://nobotta.dazoo.ne.jp/blog/?p=490
    Code (CSharp):
    1.  
    2.                         Texture2D imgTexture = Resources.Load ("line") as Texture2D;
    3.  
    4.                         Mat imgMat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC4);
    5.  
    6.                         Utils.texture2DToMat (imgTexture, imgMat);
    7.                         Debug.Log ("imgMat dst ToString " + imgMat.ToString ());
    8.  
    9.                         Mat edge = new Mat ();
    10.                         Mat lines = new Mat ();
    11.                         Imgproc.cvtColor (imgMat, edge, Imgproc.COLOR_RGBA2GRAY);
    12.                         Imgproc.Canny (edge, edge, 80, 100);
    13.                         Imgproc.HoughLines (edge, lines, 1, System.Math.PI / 180.0, 100);
    14.                         Debug.Log ("lines " + lines.dump ());
    15.  
    16.                         double[] data;
    17.                         double rho, theta;
    18.                         Point pt1 = new Point ();
    19.                         Point pt2 = new Point ();
    20.                         double x0, y0;
    21.                         for (int i = 0; i < lines.cols(); i++) {
    22.                                 data = lines.get (0, i);
    23.                                 rho = data [0];
    24.                                 theta = data [1];
    25.                                 double cosTheta = System.Math.Cos (theta);
    26.                                 double sinTheta = System.Math.Sin (theta);
    27.                                 pt1.x = rho / cosTheta;
    28.                                 pt1.y = 0;
    29.                                 pt2.x = 0;
    30.                                 pt2.y = rho / sinTheta;
    31.                
    32.                                 Core.line (imgMat, pt1, pt2, new Scalar (255, 0, 0, 255), 1);
    33.                         }
    34.  
    35.                         Texture2D texture = new Texture2D (imgMat.cols (), imgMat.rows (), TextureFormat.RGBA32, false);
    36.                         Utils.matToTexture2D (imgMat, texture);
    37.  
    38.                         gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
    line.png
    line.png

    output
    output.PNG
     
  25. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    OpenCV for Unity
    Released Version 1.3.0


    Version changes
    1.3.0
    [Common]Fixed WebCamTextureToMatHelper.cs.( Bug of rotation convertion from WebCamTexture to Mat in Win,Mac StandAlone Build)
    [Common] Added Beta14 Version of “OpenCV for Untiy” based on “OpenCV3.0.0”.
     
  26. mister nobody

    mister nobody

    Joined:
    Dec 12, 2015
    Posts:
    5
    Has anyone gotten any of these OpenCV sample projects working with Google Cardboard on a phone?

    I've tried and while they work just fine in the editor, they DO NOT work well with Google Cardboard.

    Looks like these ARCameras rely on setting the camera.worldToCameraMatrix property with the transform of the detected object, but that doesn't work in Cardboard on an actual iPhone.
     
  27. rforgeon

    rforgeon

    Joined:
    Jul 3, 2015
    Posts:
    6
    EnoxSoftware thank you very much for the great product and support!

    I'm hung up on an archiving error in Xcode:

    To submit my archive to iTunes, I must use Standard Architecture
    After setting Standard Architecture, I get the following bitcode error when attempting to create a new archive:



    I'm using the Scripting Backend IL2CPP in Unity and have tried Architectures: Universal, ARM64, and ARMv7
    https://cloudup.com/cUQgqSzeQZm

    My Unity version is 5.3.2f1 Personal
     
  28. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    Unfortunately, Bitcode setting of libopencvforunity.a seems imperfect.
    Until it is fixed, please set ENABLE_BITCODE = NO in Xcode Setting.
     
  29. cobra_games

    cobra_games

    Joined:
    Feb 6, 2016
    Posts:
    1
    I've been thinking about buying this opencv just to build a cardboard app -- so I'm concerned by this. What do you mean doesn't work well with it? What does it do?
     
  30. rforgeon

    rforgeon

    Joined:
    Jul 3, 2015
    Posts:
    6
    Thank you! ENABLE_BITCODE = NO in Xcode Setting did the trick. With Xcode's Standard Arch. and Unity's IL2CPP. I was able to Archive my app and submit to iTunes. Cheers, ya'll rock!
     
  31. ram0m

    ram0m

    Joined:
    Apr 26, 2013
    Posts:
    3
    Hi, I have one problem with openCV when I build an Xcode proyect from iOS, when I try to run on my iPad the console show me the next error:



    folder/compilado Xcode/glasses/Libraries/OpenCVObjectDetector/Plugins/iOS/libopencvobjectdetector.a(opencvobjectdetector.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture armv7

    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    and if I try to disable bitcode I have the next error.

    Undefined symbols for architecture armv7:

    "__MNP_ShowRateUsPopUp", referenced from:

    RegisterMonoModules() in RegisterMonoModules.o

    "__MNP_ShowDialog", referenced from:

    RegisterMonoModules() in RegisterMonoModules.o

    "__MNP_ShowPreloader", referenced from:

    RegisterMonoModules() in RegisterMonoModules.o

    "__MNP_RedirectToAppStoreRatingPage", referenced from:

    RegisterMonoModules() in RegisterMonoModules.o

    "__MNP_HidePreloader", referenced from:

    RegisterMonoModules() in RegisterMonoModules.o

    "__MNP_ShowMessage", referenced from:

    RegisterMonoModules() in RegisterMonoModules.o

    "__MNP_DismissCurrentAlert", referenced from:

    RegisterMonoModules() in RegisterMonoModules.o

    ld: symbol(s) not found for architecture armv7

    clang: error: linker command failed with exit code 1 (use -v to see invocation)



    can anyone help me? Thank you
     
  32. rforgeon

    rforgeon

    Joined:
    Jul 3, 2015
    Posts:
    6
    For the second error:

    Did you set Unity Build - Player settings (debug) Scripting Backend = IL2CPP? http://docs.unity3d.com/Manual/iphone-64bit.html
     
  33. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    Is "OpenCVObjectDetector" version 1.1.8 ?

    1.1.8
    [iOS]Enabled Bitcode.
     
  34. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    OpenCV for Unity
    Released Version 1.3.1


    Version changes
    1.3.1
    [Common]Fixed WebCamTextureToMatHelper.cs.(Add didUpdateThisFrame () method)
    [Common]Added Beta15 Version of “OpenCV for Untiy” based on “OpenCV3.0.0”.


    bitcode of opencvforunity.a and opencvobjectdetector.a will be fixed in the next update.
     
  35. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    571
    Do you include a Unity example of blob tracking with your asset? Also, is background subtraction implemented and a way of adjusting the size of blob detected? I'm looking for an asset that can track people from a web cam on OS X and before I purchase would like to know some details of how this has been implemented within Unity.
     
  36. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    MultiObjectTrackingBasedOnColorSample has been included in ”OpenCV for Unity”.
    https://github.com/EnoxSoftware/Ope...Samples/MultiObjectTrackingBasedOnColorSample

    Since this package is a clone of OpenCV Java, you are able to use the same API as OpenCV Java.
    http://enoxsoftware.github.io/OpenCVForUnity/doc/html/index.html
    http://enoxsoftware.github.io/OpenCVForUnity/3.0.0/doc/html/index.html

    If there is implementation example using "OpenCV Java", I think that it can be implemented even using "OpenCV for Unity".
     
  37. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    OpenCV for Unity
    Released Version 1.3.2


    Version changes
    1.3.2
    [iOS]Fixed libopencvforunity.a Bitcode Setting.
    [Common]Added Beta16 Version of “OpenCV for Untiy” based on “OpenCV3.0.0”.
     
  38. Narlix

    Narlix

    Joined:
    Jul 3, 2009
    Posts:
    111
    Does this plugin work with Unity Cloud Build? I've noticed that many plugins dont work with Cloud Build.
     
  39. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    "OpenCV for Unity" work with UnityCloudBuild without problems.
    I am using UnityCloudBuild for test build before release to AssetStore.
     
  40. SunnyChow

    SunnyChow

    Joined:
    Jun 6, 2013
    Posts:
    360
    Is that a way to use surf/sift in your plugin? I know there is licensing problem for those equations, but i would like to ask, to make sure
     
  41. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    Unfortunately, SURF/SIFT does not plan to be implemented.
     
  42. ngng2306

    ngng2306

    Joined:
    Mar 2, 2016
    Posts:
    3
    I found "OpticalFlowSample" no response from my ASUS Zenfone 2 Deluxe, The OS is Andriod 5.0, is that OS issues or the hardware issues?
    **P.S. I download the Unity Sample From Google App Store.
     
  43. wave330

    wave330

    Joined:
    Feb 10, 2016
    Posts:
    2
    Hi Enox,
    Currently working on a student project to make a simple game demo using OpenCV/OpenCVSharp eye tracking and a webcam. For example, detect where the player is looking and shoot in that same direction. Currently, I have managed to get the webcam appear in the scene in Unity. First time doing something like this, so any help to then implement the tracking would be much appreciated.
     
  44. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    Thank you very much for reporting.
    Other Samples are working properly?
     
  45. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    I think this code would be helpful.
    http://thume.ca/projects/2012/11/04/simple-accurate-eye-center-tracking-in-opencv/
    https://github.com/trishume/eyeLike
     
  46. slava_pankratov

    slava_pankratov

    Joined:
    Jan 17, 2015
    Posts:
    45
    Hi! I'm getting a crash while trying to use seamlessClone() method (access violation error). Any ideas? Thanks
     
  47. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    The following code worked without problems.
    http://devmemo.hatenablog.jp/entry/2014/03/05/071003
    Mat seems must be 8-bit 3-channel.

    Code (CSharp):
    1.                         Mat src = Imgcodecs.imread (Utils.getFilePath ("seamlessclone/src.jpg"), Imgcodecs.CV_LOAD_IMAGE_COLOR);
    2.                         Mat dst = Imgcodecs.imread (Utils.getFilePath ("seamlessclone/dst.jpg"), Imgcodecs.CV_LOAD_IMAGE_COLOR);
    3.                         Mat mask = Imgcodecs.imread (Utils.getFilePath ("seamlessclone/mask.bmp"), Imgcodecs.CV_LOAD_IMAGE_COLOR);
    4.                         Mat result = new Mat ();
    5.  
    6.                         Point point = new Point (190, 120);
    7.                         Photo.seamlessClone (src, dst, mask, point, result, Photo.NORMAL_CLONE);
    8.  
    9.                         Debug.Log ("result ToString " + result.ToString ());
    10.                         Imgproc.cvtColor (result, result, Imgproc.COLOR_BGR2RGB);
    11.  
    12.  
    13.                         Texture2D texture = new Texture2D (result.cols (), result.rows (), TextureFormat.RGBA32, false);
    14.  
    15.        
    16.                         Utils.matToTexture2D (result, texture);
    17.  
    18.                         gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
    seamlessclone.PNG
     
  48. wave330

    wave330

    Joined:
    Feb 10, 2016
    Posts:
    2
  49. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,536
    OpenCV for Unity
    Released Version 2.0.0


    Version changes
    2.0.0
    [Common]Updated to OpenCV3.1.0.
    [Common]Included Old Version based on “OpenCV2.4.11”.
    [Common]Included Beta Version of Windows10 UWP Support.(This is beta version based on OpenCV3.0.0. opencv_contrib modules is not supported.)
     
  50. Grislymanor

    Grislymanor

    Joined:
    Aug 15, 2014
    Posts:
    23
    For the Voforia Sample (
    ), I achieved the video play sample (on IOS) with consistent 7fps. I noticed in the above post that you suggested changing the parameters of the "
    CascadeClassifier::detectMultiScale()" and possibly reducing the size of the "webcam" to increase fps. Would this apply to the Voforia Sample?