Search Unity

[RELEASED] OpenCV for Unity

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

  1. summerice

    summerice

    Joined:
    Mar 12, 2015
    Posts:
    8
    Hi,why display such alarms:
    Scene 'Texture2DToMatExample' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
    To add a scene to the build settings use the menu File->Build Settings...
    UnityEngine.SceneManagement.SceneManager:LoadScene(String)
    OpenCVForUnityExample.OpenCVForUnityExample:OnTexture2DToMatExampleButtonClick() (at Assets/OpenCVForUnity/Examples/OpenCVForUnityExample.cs:47)
    UnityEngine.EventSystems.EventSystem:Update()
     
  2. hiepjack123

    hiepjack123

    Joined:
    Dec 27, 2017
    Posts:
    1
    Hello. Can this plugin allow us to do the hand tracking like kinect one ? Thank you very much!
     
  3. reimajina

    reimajina

    Joined:
    Mar 14, 2017
    Posts:
    8
    hi i want to ask, is webgl face mask compatible for mobile browser?
     
  4. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    I received your email, but when I try to reply to your email address, I get an error and cannot reply. Could you please resend it to me using a different email address?
     
  5. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Could you add all of the “***.unity” in the “OpenCVForUnity/Examples” folder to [Build Settings] – [Scene In Build]?
    AddAllSceneToBuildSettings.png
     
  6. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    For now, OpenPoseExample takes more than 2000 ms to estimate human pose. Perhaps real-time processing is difficult.
     
  7. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
  8. ncume

    ncume

    Joined:
    Aug 12, 2021
    Posts:
    3
    Hi, is it possible to use VideoCapture to stream RTSP camera? I can use openCV in py or C++ to stream RTSP camera, but I failed by using openCVForUnity.
    My code is as follows, when i change the object on videocapture from '0' to the rtsp link, it failed. So if it can work rtsp camera by videocapture, please teach me how to fix it. Thank you!
     

    Attached Files:

  9. willtospawn

    willtospawn

    Joined:
    Apr 1, 2019
    Posts:
    7
    Hello, is it possible to use the package to run equivalent of numpy masked array operations, e.g.
    zeros
    ,
    ones
    ,
    around
    ,
    where
    ? Thanks!
     
  10. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    To play streaming file, ffmpeg.dll is required.
    1)Download "OpenCV for Windows Version 4.5.3"(https://sourceforge.net/projects/opencvlibrary/).
    2)Copy "opencv_videoio_ffmpeg453_64.dll" to the root directory of the Project.
    ffmpeg_copy_ffmpeg.png
    3)Edit User Variables.
    https://stackoverflow.com/questions...reply-when-cv2-videocapture-rtsp-onvif-camera
    ffmepg_edit_user_variables.png

    I succeeded in playing this file.
    Code (CSharp):
    1.             //capture.open(Utils.getFilePath(VIDEO_FILENAME));
    2.             capture.open("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov", Videoio.CAP_FFMPEG);
    ffmpeg_play_ffmpeg.png
     
    Last edited: Aug 18, 2021
  11. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    OpenCVForUnity is a clone of OpenCV Java, you are able to use the same API as OpenCV Java 4.5.3.
    https://enoxsoftware.github.io/OpenCVForUnity/3.0.0/doc/html/index.html

    In opencv, the "Mat.ones()" and "Mat.zeros()" methods exist, but the numpy-specific "around" and "where" methods do not.
    If you want to perform complex operations on each element of Mat, you need to extract the data array (or use pointer access).
    https://github.com/EnoxSoftware/Ope...mple/MatBasicProcessingExample.cs#L2086-L2164
     
  12. ncume

    ncume

    Joined:
    Aug 12, 2021
    Posts:
    3
    Well, I know it can play file.But I prefer to ask to stream the rtsp "camera" because I need to use the live image by rtsp camera. Thank you~~
     
  13. Babil44

    Babil44

    Joined:
    Aug 19, 2021
    Posts:
    1
    Hi EnoxSoftware.

    What should I do to detect age and gender in the ResnetSSDFaceDetectionExample scene? I downloaded the necessary files. I will be happy if you help.
     
  14. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    When I delivered the camera stream with VLC media player using the rtsp protocol, I was able to successfully receive the stream with OpenCVForUnity.
    2021-08-20_17h35_18.png
    2021-08-20_17h38_44.png
    capture.open("rtsp://127.0.0.1:8554/", Videoio.CAP_FFMPEG);
     
  15. Bersaelor

    Bersaelor

    Joined:
    Oct 8, 2016
    Posts:
    111
    @EnoxSoftware I saw you update the package again 3 days ago, for the issue described in https://forum.unity.com/threads/fai...tive-plugin-files-bc.1137496/#post-7381241are we waiting for an official fix now, or do you plan to use the workaround

    For example, use the emar tool to build the archive
    emar r NativePluginExample.a NativePluginExample.bc
    in the OpenCV package?

    With 2021.2.0b8 the warning is still

    Code (CSharp):
    1. emcc2: warning: EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead [-Wdeprecated]
    2. emcc2: error: /var/folders/qb/xtrq8wsn0lz_s_b08h7n_s2w0000gn/T/tmp_02jtg1kopencvforunity.a: File has a suffix of a static library ('.a',), but instead is an LLVM bitcode file! When linking LLVM bitcode files use .bc or .o.
     
  16. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Could you send me an email using the contact form below?
    https://enoxsoftware.com/opencvforunity/contact/technical-inquiry/
     
    Bersaelor likes this.
  17. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Check out the hand tracking package in NatML.
     
    Last edited: Mar 18, 2022
  18. unity_20C34E656E90DA5C3D83

    unity_20C34E656E90DA5C3D83

    Joined:
    Aug 24, 2021
    Posts:
    1
    hello I use your package I want to connect my webcam via a new VideoCatpure (0)

    Code (CSharp):
    1.                 videoCapture = new VideoCapture(0);
    2.                 Debug.Log("State 1");
    3.                 videoCapture.set(Videoio.CAP_PROP_CONVERT_RGB, 1);
    4.                 Debug.Log("State 2");
    5.                 videoCapture.set(Videoio.CAP_PROP_FRAME_WIDTH, requestedWidth);
    6.                 Debug.Log("State 3");
    7.                 videoCapture.set(Videoio.CAP_PROP_FRAME_HEIGHT, requestedHeight);
    8.                 Debug.Log("State 4");
    9.                 videoCapture.set(Videoio.CAP_PROP_FPS, (int)requestedFPS);
    the problem is that the functions seem very slow to be executed, I tried to pass it through couroutine so that it does not block my scene while it is loading but it still blocks, do you have any idea?
     
  19. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    I've tested the "Examples/MainModules/videoio/VideoCaptureCameraInputExample" included in the package on Windows Editor, and I haven't encountered any delay in the function. In my experience, the time it takes for the camera image to appear is about the same as when using Unity's WebCamTexture.
     
  20. V0odo0

    V0odo0

    Joined:
    Jan 8, 2012
    Posts:
    328
    Hi. I have a question about Aruco.drawMarker. As I understand correctly, it draws aruco marker image into provided mat but I'm unable to get the correct result. Every draw attempt even with the same parameters gives me incorrect image with pixels spread all around the texture.



    My thought that I was using incorrect mat and texture2d formats but I've tried several CvType and TextureFormat combinations with no luck.

    Here is the sample code:
    Code (CSharp):
    1. Dictionary dict = Aruco.getPredefinedDictionary(Aruco.DICT_4X4_1000);
    2. var markerId = 0;
    3. var markerSize = 6;
    4.  
    5. using (Mat m = new Mat(markerSize, markerSize, CvType.CV_8UC4))
    6. {
    7.     Aruco.drawMarker(dict, markerId, 0, m);
    8.  
    9.     var t = new Texture2D(m.width(), m.height(), TextureFormat.RGBA32, false);
    10.     t.filterMode = FilterMode.Point;
    11.     t.Apply();
    12.  
    13.     Utils.matToTexture2D(m, t, false);
    14. }
    My task is to generate aruco marker image and prepare it for printing in runtime.
     
    Last edited: Aug 28, 2021
  21. FraPev

    FraPev

    Joined:
    May 19, 2021
    Posts:
    5
    Good morning,
    I am a student and my professor has purchased the OpenCV for Unity asset. I imported the asset to my computer and it works. The problem arises when I close the program and reopen it. I attach screenshots of the error messages.
    By deleting the code that uses the asset it opens without any problems. Could you tell me what the problem is?
    Thank you very much
     

    Attached Files:

  22. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    You need to input the markerSize as the third argument of the Aruco.drawMarker method.
    I have modified the code as follows.

    Code (CSharp):
    1.      
    2.            Dictionary dict = Aruco.getPredefinedDictionary(Aruco.DICT_4X4_1000);
    3.             var markerId = 0;
    4.             var markerSize = 6;
    5.  
    6.             var texture = new Texture2D(markerSize, markerSize, TextureFormat.RGB24, false);
    7.             texture.filterMode = FilterMode.Point;
    8.             texture.Apply();
    9.  
    10.             using (Mat m = new Mat(markerSize, markerSize, CvType.CV_8UC4))
    11.             {
    12.                 Aruco.drawMarker(dict, markerId, markerSize, m);
    13.  
    14.                 Utils.matToTexture2D(m, texture);
    15.             }
    16.  
    See also the examples in Examples/ContribModules/aruco/ArUcoExample/ArUcoCreateMarkerExample.
     
    V0odo0 likes this.
  23. UnityQueries

    UnityQueries

    Joined:
    Jul 6, 2021
    Posts:
    9
    Hi, I am going to purchase this asset before that I was checking the free trial version of OpenCV for Unity in that I need some help :

    Can anyone please share some of the references for the Openpose example using web camera.

    Thank you.
     
  24. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Could you tell me the environment you tested?
    OpenCV for Unity version :
    Unity version :
     
  25. FraPev

    FraPev

    Joined:
    May 19, 2021
    Posts:
    5
    OpenCV for Unity version : 2.4.5
    Unity version : 2020.3.8f1
     
  26. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    The same version worked fine in my environment. Do you have the same problem on other PCs?
     
  27. UnityQueries

    UnityQueries

    Joined:
    Jul 6, 2021
    Posts:
    9
    Hi, I am working on an OpenPose example using the free trail version. In that, I am able to get the skeleton tracking for a single person using the web camera.

    I need some help for the following scenario :

    Can you please share a procedure or some of the references for the skeleton tracking for multiple persons and also how can I generate a 3d coordinates of body parts.

    Thank you.
     
  28. SilvioPSabatini

    SilvioPSabatini

    Joined:
    Aug 24, 2021
    Posts:
    1
    With my professor's PC it works. Is it possible that one license cannot be used (or be active) with two different computers?
     
  29. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    There are no such restrictions.
    Could you send me an email using the contact form below? I will send you the project I have set up.
    https://enoxsoftware.com/opencvforunity/contact/technical-inquiry/
     
  30. FraPev

    FraPev

    Joined:
    May 19, 2021
    Posts:
    5
  31. InformaticaIQx

    InformaticaIQx

    Joined:
    Jan 7, 2020
    Posts:
    6
    Hello, @EnoxSoftware,

    I am trying to build a project for WebGL platform. In my last test I tried to build a new project with OpenCV for Unity 2.4.5 on Unity 2019.1.0, but the build failed. My steps were the following:

    1) Make a new empty project on Unity 2019.1.0
    2) Import OpenCV for Unity 2.4.5 (all checked)
    3) Make a development build for WebGL platform
    4) The build fails resulting in the error below:

    Failed running "C:\Program Files\Unity\Hub\Editor\2019.1.0f2\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\python.exe" -E "C:\Program Files\Unity\Hub\Editor\2019.1.0f2\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emcc" @"C:\Users\User\Documents\Projects\New Unity Project\Assets\..\Temp\emcc_arguments.resp"

    Any advice?

    Thanks
     
  32. fruitgum

    fruitgum

    Joined:
    Jan 11, 2019
    Posts:
    1
    @EnoxSoftware
    I'd like to test the trial version but I'm not sure how to import it into my project. The zip file contains a ton of subfolders, do I just drag the parent folder into the project?
     
  33. UnityQueries

    UnityQueries

    Joined:
    Jul 6, 2021
    Posts:
    9
    Hello, @EnoxSoftware,

    I am using OpenCV for my Unity project in that I was working on the OpenPose. I am able to get the OpenPose for a single person. I need help for the OpenPose for multiple persons.

    Can you please help me or share some of the references to get the OpenPose for multiple persons using Unity.

    Thanks in advance.
     
  34. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Is there enough space left on the HDD? Build errors may occur if there is not enough space left on the HDD.
     
  35. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Could you unzip OpenCVForUnity2.4.5TrialVersion.zip and import OpenCVForUnity2.4.5TrialVersion.unitypackage into UnityEditor?
     
  36. InformaticaIQx

    InformaticaIQx

    Joined:
    Jan 7, 2020
    Posts:
    6
    Thanks for the reply.
    Yes, there is fair enough space left on the HDD.
     
  37. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Unfortunately, I don't have an OpenPose example that detects multiple persons.
    The following page is a good reference for detecting multiple people.
    https://learnopencv.com/multi-person-pose-estimation-in-opencv-using-openpose/
     
  38. InformaticaIQx

    InformaticaIQx

    Joined:
    Jan 7, 2020
    Posts:
    6
    @EnoxSoftware

    OK. I have figured it out.

    The problem was that the OpenCVForUnity/Plugins/WebGL/2019.1/opencvforunity.bc file was not configured for the WebGL platform. Afterwards, you have to delete the one in the 2018.2 folder.

    And that's all. Build succeeded.
     
  39. sushanta1991

    sushanta1991

    Joined:
    Apr 3, 2011
    Posts:
    305
    I tried to use COLORMAP_HOT but it's not working. But if I try to use cvtColor then that piece of code is working.

    This piece of code is not working with COLORMAP
    Code (csharp):
    1.  
    2. if (webCamTexture.isPlaying && webCamTexture.didUpdateThisFrame)
    3.             {
    4.                 Utils.webCamTextureToMat(webCamTexture, rgbaMat);
    5.                 croppedMat = new Mat(rgbaMat, cropRect);
    6.                 Mat effectMat = croppedMat.clone();
    7.                 Imgproc.applyColorMap(croppedMat, effectMat, Imgproc.COLORMAP_HOT);
    8.                 Utils.matToTexture2D(effectMat, texture);
    9.                 cameraFrame.texture = texture;
    10.             }
    11.  
    12.  

    If I use cvtColor this piece of code is working.
    Code (csharp):
    1.  
    2. if (webCamTexture.isPlaying && webCamTexture.didUpdateThisFrame)
    3.             {
    4.                 Utils.webCamTextureToMat(webCamTexture, rgbaMat);
    5.                 croppedMat = new Mat(rgbaMat, cropRect);
    6.                 Mat effectMat = croppedMat.clone();
    7.                 Imgproc.cvtColor(croppedMat, effectMat, Imgproc.COLOR_RGB2GRAY, 3);
    8.                 Utils.matToTexture2D(effectMat, texture);
    9.                 cameraFrame.texture = texture;
    10.             }
    11.  
    Can anyone please suggest what I am doing wrong?

    I tried all COLORMAP but non of them works.
     
    Last edited: Sep 23, 2021
  40. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Enclose the point where the error occurs in Utils.setDebugMode() method, and the error on the C++ side will be displayed on the console.
    Code (CSharp):
    1. Utils.setDebugMode (true);
    2. Imgproc.applyColorMap(croppedMat, effectMat, Imgproc.COLORMAP_HOT);
    3. Utils.setDebugMode (false);
    Code (CSharp):
    1. colormap.cpp:736: error: (-5:Bad argument) cv::ColorMap only supports source images of type CV_8UC1 or CV_8UC3 in function 'cv::colormap::ColorMap::eek:perator ()'
    The error is probably due to the fact that the croppedMat type is 8UC4.
     
  41. Wailander

    Wailander

    Joined:
    May 2, 2017
    Posts:
    12
    Hi, is aruco detection supported on Android ? It crashes on the mobile app Opencvforunityexample.

    Edit: did some testing :
    it crashes on my Redmi note 8 pro but not on my Lenovo tab M10.
    Only Aruco WebcamTexture Example crash, but that's what I need.
    The crashing device seems to use arm64 v8, and the other v7.
     
    Last edited: Sep 25, 2021
  42. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Could you tell me the environment you tested?
    OpenCV for Unity version :
    Unity version :

    Also,
    Does this crash also occur with ArUcoExample? If the crash only occurs with the ArucoWebcamTextureExample, using the latest version of OpenCVForUnity may solve the problem.
     
  43. sushanta1991

    sushanta1991

    Joined:
    Apr 3, 2011
    Posts:
    305
    Thank you for the reply.

    I was able to convert Mat to 8UC3 by using COLOR_BGRA2BGR

    Code (csharp):
    1.  
    2. Mat dst = new Mat();
    3.             Imgproc.cvtColor(_image, dst, Imgproc.COLOR_BGRA2BGR);
    4.             Imgproc.applyColorMap(dst, dst, Imgproc.COLORMAP_CIVIDIS);
    5.  
    6.  
     
    EnoxSoftware likes this.
  44. Wailander

    Wailander

    Joined:
    May 2, 2017
    Posts:
    12
    Hi, thx for the reply, I've not yet bought the asset, I wanted to see if it was working fine before, so I'm using the app from the playstore.
    Looking at the app system info it's unity 2019.3.10f1 and opencvforunity 2.4.1.
    ArUcoExample is working indeed, that's weird...
     
  45. sushanta1991

    sushanta1991

    Joined:
    Apr 3, 2011
    Posts:
    305
    Hi @EnoxSoftware

    How can I create this in opencvforunity?

    Code (csharp):
    1.  
    2. cv::Mat kernel =
    3.     (cv::Mat_<float>(3, 3)
    4.         <<
    5.         0.272, 0.534, 0.131,
    6.         0.349, 0.686, 0.168,
    7.         0.393, 0.769, 0.189);
    8. cv::transform(input_img, output_img, kernel);
    9.  
    I can use Core.transform but how to create that kernel matrix?
     
  46. kukewilly

    kukewilly

    Joined:
    Jan 3, 2019
    Posts:
    46
    Hey devs. Thank you for the amazing asset this has helped me so much on my project!

    I'm currently having an issue getting the position transform of my ARGameObject to match it's real-space position relative to the camera. I have the camera position 0.4m away from the marker in "test setup" picture below, but the z value in the position transform is reading out as 0.21m. When I move the camera back 0.8m, it reads ~0.4m for the z value. This leads me to believe that some parameter is off by a factor of 2 or 0.5. Is there a resource that describes how the variables like: chArUcoBoradSquareLength, chArUcoBoradMarkerLength (ArUcoCameraCalibrationExamples.cs), markerLength (ArUcoWebCamTextureExample.cs) are measured off the charuco board and aruco markers. edit: The ARGameObject is positioned correctly visually over the aruco marker. It looks bigger because it's showing the top face of the cube, just to clarify.

    test setup.png

    The second and third pictures show how I am measuring them currently.

    lengths.png

    aruco length.png

    Am I doing something wrong or has anyone encountered this problem before? When I calibrate I am taking 40 pictures and they are taken at a variety of depths, positions, and rotations. Are there other parameters I am not setting that I didn't mention?

    Thanks!
     
    Last edited: Sep 28, 2021
  47. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564

    At least in my tests, I haven't seen any major errors. The error is within a few centimeters of the actual measured value.
    In the ArUcoWebCamTextureExample scene, the "ARGameObject" is positioned relative to the "ARCamera" world coordinate position when the AR marker is detected.
    Note that in our example, the initial Z-position of the "ARCamera" is 0.3.
    To observe the detection values that are not affected by "ARCamera", look at the ARM matrix calculated in line 709 of ArUcoWebCamTextureExample.cs. (The value of ARM.m23 is position-Z)
    As for the meaning of the values of chArUcoBoradSquareLength, chArUcoBoradMarkerLength, and markerLength, I think your measurement location is correct.
     
  48. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Wailander likes this.
  49. Wailander

    Wailander

    Joined:
    May 2, 2017
    Posts:
    12
  50. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Code (CSharp):
    1.             Mat kernel = new Mat(3, 3, CvType.CV_32FC1);
    2.             kernel.put(0, 0,
    3.                 0.272, 0.534, 0.131,
    4.                 0.349, 0.686, 0.168,
    5.                 0.393, 0.769, 0.189);
    6.  
    7.             Mat output_img = new Mat();
    8.  
    9.             Core.transform(input_img, output_img, kernel);