Search Unity

[RELEASED] OpenCV for Unity

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

  1. sushanta1991

    sushanta1991

    Joined:
    Apr 3, 2011
    Posts:
    305

    Thanks for replying.

    I tried the above code but I am getting an error.

    core::transform_10() : OpenCV(4.5.3-dev) C:\Users\satoo\Desktop\opencv\modules\core\src\matmul.dispatch.cpp:439: error: (-215:Assertion failed) scn == m.cols || scn + 1 == m.cols in function 'cv::transform'

    Code (csharp):
    1.  
    2. Utils.setDebugMode(true);
    3. Mat kernel = new Mat(3, 3, CvType.CV_32FC1);
    4. kernel.put(0, 0,
    5.     0.272, 0.534, 0.131,
    6.     0.349, 0.686, 0.168,
    7.     0.393, 0.769, 0.189);
    8. Mat output_img = croppedMat.clone();
    9. Core.transform(croppedMat, output_img, kernel);
    10. Utils.setDebugMode(false);
    11. Utils.matToTexture2D(output_img, texture);
    12. cameraFrame.texture = texture;
    13.  

    I tried another way to get an effect called "Robinson Effect" which looks like this.

    Code (csharp):
    1.  
    2.  
    3. public static Mat Get_RobinsonColorEffect(Mat _image)
    4.         {
    5.             Mat dst = new Mat(_image.rows(), _image.cols(), _image.type());
    6.             Mat kernel = new Mat(3, 3, CvType.CV_32F);
    7.             kernel.put(0, 0, -1);
    8.             kernel.put(0, 1, 0);
    9.             kernel.put(0, 2, 1);
    10.             kernel.put(1, 0 - 2);
    11.             kernel.put(1, 1, 0);
    12.             kernel.put(1, 2, 2);
    13.             kernel.put(2, 0, -1);
    14.             kernel.put(2, 1, 0);
    15.             kernel.put(2, 2, 1);
    16.             Imgproc.filter2D(_image, dst, -1, kernel);
    17.             return dst;
    18.         }
    19.  
    this piece of code works.

    actually, I was trying to do a sepia effect with opencvforunity but was unable to get it working. Just trying my luck with it right now :)

    Your plugin is really great. Though I am not too familiar with OpenCV, still I am able to convert most of the sample code in another language to c# with your plugin. Thanks for making it easier for us.
    Like this wall painting sample, I made with your plugin for fun :D https://sushanta1991.blogspot.com/2021/09/how-to-paint-wall-using-opencv-in-unity.html
    Right now I am trying the free version of your plugin, I am pretty sure we will get your pro version as well.
     
  2. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Code (CSharp):
    1.  error: (-215:Assertion failed) scn == m.cols || scn + 1 == m.cols in function 'cv::transform'
    In the case of this kernel, it seems that the number of channels in input_img needs to be 3.
     
  3. kukewilly

    kukewilly

    Joined:
    Jan 3, 2019
    Posts:
    46
    Thanks for the reply. So I Debug.Log(ARM.m23) and it is also showing 0.2m, and the ARCamera position transform changes to z = 0 on Start but is z = 0.3 when not running. So I think that's why both values are the same. Either way it seems like the detection values in ARM are not accurate for some reason??

    Edit: This is where I log ARM.m23

    Code (CSharp):
    1.         private void UpdateARObjectTransform (Mat rvec, Mat tvec)
    2.         {
    3.             // Convert to unity pose data.
    4.             double[] rvecArr = new double[3];
    5.             rvec.get (0, 0, rvecArr);
    6.             double[] tvecArr = new double[3];
    7.             tvec.get (0, 0, tvecArr);
    8.             PoseData poseData = ARUtils.ConvertRvecTvecToPoseData (rvecArr, tvecArr);
    9.  
    10.             // Changes in pos/rot below these thresholds are ignored.
    11.             if (enableLowPassFilter) {
    12.                 ARUtils.LowpassPoseData (ref oldPoseData, ref poseData, positionLowPass, rotationLowPass);
    13.             }
    14.             oldPoseData = poseData;
    15.  
    16.             // Convert to transform matrix.
    17.             ARM = ARUtils.ConvertPoseDataToMatrix (ref poseData, true);
    18.             PM = ARM;
    19.             Debug.Log(ARM.m23);
    20.  
    21.             if (shouldMoveARCamera) {
    22.  
    23.                 ARM = arGameObject.transform.localToWorldMatrix * ARM.inverse;
    24.  
    25.                 ARUtils.SetTransformFromMatrix (arCamera.transform, ref ARM);
    26.  
    27.             } else {
    28.  
    29.                 ARM = arCamera.transform.localToWorldMatrix * ARM;
    30.  
    31.                 ARUtils.SetTransformFromMatrix (arGameObject.transform, ref ARM);
    32.                 ARUtils.SetTransformFromMatrix (playerGameObject.transform, ref PM);
    33.             }
    34.         }
    test setup 2.png

    Also: I did a test moving the AR camera 0.1m in the -x direction but the -x position value for the ARGameobject only changed by -0.05m. So it seems like there is some sort of scale factor that is off. Any ideas?

    test setup 3.png
     
  4. kukewilly

    kukewilly

    Joined:
    Jan 3, 2019
    Posts:
    46
    I've found that changing the resolution of my camera has a large effect. My camera is 1920x1080 res and 30fps but I was requesting 640x360. When I increase it to 1920x1080 the frame rate collapses and I end up with a black feed. When I request 1260x720 it runs well and the z transform has increased to 0.28m. So it's approaching the 0.4m on my ruler and would get closer at 1920x1080 but it wont run.

    I calibrated the camera with the requested resolution at 640x360. Does this matter if my camera is 1080p? Do I need to request 360p and then resize the frame to 1080p?
     
  5. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    I have only tested when the calibration resolution and camera resolution are the same size, so I don't know what the effect of running at different resolutions would be.
    From the attached screen capture, it looks like the test was run with a camera resolution of 640x480.
    Is the calibration data done at 640x480 resolution?
     
  6. znerolnoht

    znerolnoht

    Joined:
    Apr 20, 2015
    Posts:
    5
    Hi,
    Apologies for the noob question.

    I'm using the example scene MultiObjectTrackingBasedOnColorExample
    I'm trying to make a custom color, white.

    In the ColorObject class, there's an area for defining color. However, it requires a HSVmin and HSVmax value.
    There's a comment in the code that states
    //TODO: use "calibration mode" to find HSV min and HSV max values

    However, I can't find any reference to "calibration mode" in the code or documentation.
    Can someone point me to the "calibration mode" and or any documentation on it?

    Also, I've tried simply setting the HSV min and max values by hand. I think the below values should be correct but they don't work at all.
    Code (CSharp):
    1. setHSVmin (new Scalar (0, 0, 200));
    2. setHSVmax (new Scalar (179, 0, 255));
    Any help is greatly appreciated.
     
  7. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    MultiObjectTrackingBasedOnColorExample is a rewrite of the following example using OpenCVForUnity.

    Unfortunately, "calibration mode" is not implemented.

    Could you please try the attached code with the white color detection added?
     

    Attached Files:

  8. kukewilly

    kukewilly

    Joined:
    Jan 3, 2019
    Posts:
    46
    [Solved] I figured out what was happening and it's a bit embarrassing, but I'm posting anyway so no one else does the same thing. I was manually changing the markerLength value in ArucoWebcamTextureExample, but it was initializing at run time as 0.1 in the inspector. It seems pretty accurate now. Bad I know... I was stuck on this for 2 weeks (ROFL).
     
  9. ncume

    ncume

    Joined:
    Aug 12, 2021
    Posts:
    3
    May I ask you for this code because I still can't fix the problems?
    And I also want to ask if videocapture with rtsp is compatible with android platform?
     
  10. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
  11. pallavimohan

    pallavimohan

    Joined:
    Dec 24, 2020
    Posts:
    1
    Hi! Is there a way I can get my hands on an older version of this (OpenCV 2.4.1)? I need it for a project urgently.
    Thanks!
     
  12. J_Kost

    J_Kost

    Joined:
    Feb 16, 2021
    Posts:
    32
    Hi, is there a particular reason that Texture2DToMat only supports 1,3 and 4 channel 8-bit Mats? I would have liked to convert 32-Bit precision RenderTexture values into a Mat.
     
  13. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    The Texture2DToMat() method uses the Color32 class internally, so it supports only 8bits. The fastTexture2DToMat() method can convert non-8-bit Texture2D to Mat.
    https://enoxsoftware.github.io/Open..._utils.html#a88cb8fa0a189a741e5b59172713760c1
    Also, There is no direct way to convert RenderTexture to Mat.
    https://github.com/EnoxSoftware/Ope...CaptureExample/ImwriteScreenCaptureExample.cs
     
    J_Kost likes this.
  14. J_Kost

    J_Kost

    Joined:
    Feb 16, 2021
    Posts:
    32
    I'll give fastTexture2DToMat() a try then, thanks! I have the RenderTexture's Data copied into a Texture2D with Textureformat RGBAFloat. So that's what I'll try to convert to Mat.

    Edit: Works perfectly, thanks a bunch. Just for my understanding: Due to a mistake of mine, I was accidentally converting a RFloat (i.e. CV_32FC1) into a CV_32FC4 like this.
    Capture.PNG

    Why does this work a few times, then cause a SegFault (see log below)? I.e. Why does it not fault out right away?

    Code (CSharp):
    1. Stacktrace:
    2.  
    3.   at <unknown> <0xffffffff>
    4.   at (wrapper managed-to-native) OpenCVForUnity.UnityUtils.Utils.OpenCVForUnity_ByteArrayToMatData (intptr,intptr) [0x0000a] in <6c73ca1fc58e4a868e1d8ed0bb99ffaf>:0
    5.   at OpenCVForUnity.UnityUtils.Utils.fastTexture2DToMat (UnityEngine.Texture2D,OpenCVForUnity.CoreModule.Mat,bool,int) [0x00046] in C:\Users\-\-\AR_Foundation_Protoype\Assets\OpenCVForUnity\org\opencv\unity\Utils.cs:453
    6.   at ReferenceTextures..ctor (UnityEngine.Texture2D,UnityEngine.Texture2D,UnityEngine.Texture2D) [0x0003a] in C:\Users\-\-\AR_Foundation_Protoype\Assets\Scripts\ReferenceImageHandler.cs:21
    7.   at ReferenceImageHandler.CopyFromRenderTexturesOnce () [0x001f2] in C:\Users\-\-\AR_Foundation_Protoype\Assets\Scripts\ReferenceImageHandler.cs:299
    8.   at ReferenceImageHandler.RenderCurrentReferenceFrame () [0x00025] in C:\Users\-\-\AR_Foundation_Protoype\Assets\Scripts\ReferenceImageHandler.cs:345
    9.   at ReferenceImageHandler.UpdateReferenceCamera (Visometry.VisionLib.SDK.Core.Frame,UnityEngine.Texture2D) [0x00242] in C:\Users\-\-\AR_Foundation_Protoype\Assets\Scripts\ReferenceImageHandler.cs:218
    10.   at SamplingCoordinator.ProcDataSet () [0x00040] in C:\Users\-\-\AR_Foundation_Protoype\Assets\Scripts\Coordinators\SamplingCoordinator.cs:286
    11.   at SamplingCoordinator.Update () [0x00051] in C:\Users\-\-\AR_Foundation_Protoype\Assets\Scripts\Coordinators\SamplingCoordinator.cs:434
    12.   at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) [0x00020] in <695d1cc93cca45069c528c15c9fdd749>:0
    13.  
    14. =================================================================
    15. Got a SIGSEGV while executing native code. This usually indicates
    16. a fatal error in the mono runtime or one of the native libraries
    17. used by your application.
    18. =================================================================
    19.  
    20. Received signal SIGSEGV
    21. Stack trace:
    22. 0x00007ffa75520e70 (opencvforunity) OpenCVForUnity_ByteArrayToMatData
    23. 0x0000021a52711571 (Mono JIT Code) (wrapper managed-to-native) OpenCVForUnity.UnityUtils.Utils:OpenCVForUnity_ByteArrayToMatData (intptr,intptr)
    24. 0x0000021a52710edb (Mono JIT Code) [Utils.cs:453] OpenCVForUnity.UnityUtils.Utils:fastTexture2DToMat (UnityEngine.Texture2D,OpenCVForUnity.CoreModule.Mat,bool,int)
    25. 0x0000021a50dffcab (Mono JIT Code) [ReferenceImageHandler.cs:21] ReferenceTextures:.ctor (UnityEngine.Texture2D,UnityEngine.Texture2D,UnityEngine.Texture2D)
    26. 0x0000021a5270e703 (Mono JIT Code) [ReferenceImageHandler.cs:299] ReferenceImageHandler:CopyFromRenderTexturesOnce ()
    27. 0x0000021a5270d1bb (Mono JIT Code) [ReferenceImageHandler.cs:345] ReferenceImageHandler:RenderCurrentReferenceFrame ()
    28. 0x0000021a52708443 (Mono JIT Code) [ReferenceImageHandler.cs:218] ReferenceImageHandler:UpdateReferenceCamera (Visometry.VisionLib.SDK.Core.Frame,UnityEngine.Texture2D)
    29. 0x0000021a52705833 (Mono JIT Code) [SamplingCoordinator.cs:286] SamplingCoordinator:ProcDataSet ()
    30. 0x0000021cc0a52e13 (Mono JIT Code) [SamplingCoordinator.cs:434] SamplingCoordinator:Update ()
    31. 0x0000021cb7e16fa8 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    32. 0x00007ffa9278e630 (mono-2.0-bdwgc) [mini-runtime.c:2812] mono_jit_runtime_invoke
    33. 0x00007ffa92712ac2 (mono-2.0-bdwgc) [object.c:2921] do_runtime_invoke
    34. 0x00007ffa9271bb1f (mono-2.0-bdwgc) [object.c:2968] mono_runtime_invoke
    35. 0x00007ff796519464 (Unity) scripting_method_invoke
    36. 0x00007ff796511db5 (Unity) ScriptingInvocation::Invoke
    37. 0x00007ff7964bff14 (Unity) MonoBehaviour::CallMethodIfAvailable
    38. 0x00007ff7964c001c (Unity) MonoBehaviour::CallUpdateMethod
    39. 0x00007ff795989008 (Unity) BaseBehaviourManager::CommonUpdate<BehaviourManager>
    40. 0x00007ff795992f5a (Unity) BehaviourManager::Update
    41. 0x00007ff795dfb89a (Unity) `InitPlayerLoopCallbacks'::`2'::UpdateScriptRunBehaviourUpdateRegistrator::Forward
    42. 0x00007ff795ddc3ec (Unity) ExecutePlayerLoop
    43. 0x00007ff795ddc4c3 (Unity) ExecutePlayerLoop
    44. 0x00007ff795de32f9 (Unity) PlayerLoop
    45. 0x00007ff797229381 (Unity) PlayerLoopController::UpdateScene
    46. 0x00007ff797227016 (Unity) Application::TickTimer
    47. 0x00007ff797b9ff81 (Unity) MainMessageLoop
    48. 0x00007ff797ba3fc1 (Unity) WinMain
    49. 0x00007ff7999d9526 (Unity) __scrt_common_main_seh
    50. 0x00007ffb07797034 (KERNEL32) BaseThreadInitThunk
    51. 0x00007ffb08702651 (ntdll) RtlUserThreadStart
     
    Last edited: Nov 4, 2021
  15. metaphysician

    metaphysician

    Joined:
    May 29, 2012
    Posts:
    190
    hi there! just tried your software demo and the ArUco marker tracking and it works reasonably well on my smaller sized (35mm) markers. it is not great in terms of distance, though, as it drops connection/tracking at about 40cm from the camera. however, i did NOT do any calibration beforehand and the documentation included seems sparse on how exactly to calibrate markers correctly. calibration seems important, but i need to have a tracking setup that can track a 35mm tag from about 100cm away max.

    i'm happy to do the calibration but i don't know if there's any other way to optimize the distance tracking besides this. there seem to be lots of options in the OpenCV code but i don't know how much you're exposing in Unity, and i didn't see much in the way of information to help with tracking markers specifically. any assistance appreciated!
     
  16. unisip

    unisip

    Joined:
    Sep 15, 2010
    Posts:
    340
    Hey, I have a project where I need to match features in two 360 images taken from relatively close positions (in order to do some camera pose estimation). I am new to OpenCV but willing to learn it.

    Before I get into this Unity asset, I would like confirmation that it exposes what's needed for feature matching. Are there any examples of feature matching between two images in the source ?

    From what I read here and there, it looks like what would be ideal for my use case would be to use ORB and FLANN
     
    Last edited: Nov 22, 2021
  17. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    An example of feature matching is included in OpenCVForUnity.
    https://github.com/EnoxSoftware/Ope...atures2d/Feature2DExample/Feature2DExample.cs
    Feature2DExample.png
     
  18. kosowski

    kosowski

    Joined:
    Jun 19, 2014
    Posts:
    15
    Hello @EnoxSoftware ,
    ¿How do you convert a Mat to MatOfPoint2f? In Java I can create a MatOfPoint from a Mat, but doing it in the plugin gives me a "CvException: Incompatible Mat" error.
    Thanks!
     
  19. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Could you tell me the test code you tried?
    Mat type must be CvType.CV_32FC2.
    Code (CSharp):
    1.             Mat mat = new Mat(1, 10, CvType.CV_32FC2);
    2.             MatOfPoint2f matOfPoint2f = new MatOfPoint2f(mat);
     
    kosowski likes this.
  20. kosowski

    kosowski

    Joined:
    Jun 19, 2014
    Posts:
    15
    Oh, I see, thanks for the answer! I was trying to first convert the Mat to MatOfPoint following some Java example. Something like this
    Code (CSharp):
    1. Aruco.detectMarkers (gray, dictionary, cornersAruco, ids, detectorParams);
    2. Mat m = cornersAruco[0];
    3. MatOfPoint mpoints = new MatOfPoint( m);
    4. MatOfPoint2f points2f = new MatOfPoint2f(mpoints.toArray());
     
  21. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    https://docs.opencv.org/4.x/d9/d6a/group__aruco.html#gab9159aa69250d8d3642593e508cb6baa
    The corners of the detectMarker() method in OpenCV 4.5.4 are CvType.32FC2.
    It is possible to convert Mat to MatOfPoint2f as shown in the following code.
    Code (CSharp):
    1. Aruco.detectMarkers (gray, dictionary, cornersAruco, ids, detectorParams);
    2. MatOfPoint2f points2f = new MatOfPoint2f(cornersAruco[0]);
    Also,
    There is a way to convert MatOfPoint to MatOfPoint2f more efficiently, as shown in the following post.
    https://stackoverflow.com/a/40448515
     
    kosowski likes this.
  22. DankP3

    DankP3

    Joined:
    Jul 17, 2017
    Posts:
    93
    Sorry, new to OpenCv and a modest coder. I am trying to align two images. I expect the images I receive to only have translations, although they could possibly have minor rotations. I had concluded that findTransformECC() would be appropriate followed by warpAffine() (or possibly transform() if just adding a translation). However, I am failing to implement this in unity. Are there any examples? or am i using inappropriate methods.
    Thanks
     
  23. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Unfortunately I don't have an example that uses the findTransformECC() method.
    Also,
    Enclose the point where the error occurs in Utils.setDebugMode() method, and the error on the C++ side will be displayed on the console.
     
  24. elvis-satta

    elvis-satta

    Joined:
    Nov 13, 2013
    Posts:
    19
    Hi, I'd like to convert the CircleDetectionExample scene to PlayMaker but couldn't figure out how to handle arrays from the Imgproc_Hough Circles. Could you help me please?
    Thanks
     
  25. LucasJeudi8

    LucasJeudi8

    Joined:
    Jul 1, 2020
    Posts:
    1
    Hi @EnoxSoftware,

    I'm trying to add CUDA backend to openCV. After replacing the opencvforunity.dll with the dll from the extra package i now find myself in the same situation as the quoted post. Is the issue still present or did i miss something?

    I'm using Unity 2020.3 and OpenCV for Unity 2.4.6.
     
    Last edited: Dec 9, 2021
  26. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Unfortunately, I have yet to find a solution to this problem.
     
  27. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,084
    This occurs for BackgroundSubtractorComparisonExample
    NullReferenceException: Object reference not set to an instance of an object
    OpenCVForUnity.ImgprocModule.Imgproc.cvtColor (OpenCVForUnity.CoreModule.Mat src, OpenCVForUnity.CoreModule.Mat dst, System.Int32 code) (at Assets/OpenCVForUnity/org/opencv/imgproc/Imgproc.cs:8194)
    OpenCVForUnityExample.BackgroundSubtractorMOG2Example.Update () (at Assets/OpenCVForUnity/Examples/MainModules/video/BackgroundSubtractorMOG2Example/BackgroundSubtractorMOG2Example.cs:143)
     
  28. sq_eye

    sq_eye

    Joined:
    Aug 27, 2021
    Posts:
    2
    Hi,I want to generate Gabor wave with gray background, but I generate Gabor picture with black background, may I ask how can I generate Gabor picture with gray background? The code is as follows:


    Code (CSharp):
    1. Mat m = OpenCVForUnity.ImgprocModule.Imgproc.getGaborKernel(ksize, sigma, theta, lambd, gamma, psi, ktype);
    2.  
    3.         Mat m2 = new Mat(ksize, CvType.CV_8UC1);
    4.  
    5.         m2 = m.clone();
    6.  
    7.         m2.convertTo(m2, CvType.CV_8UC1, 255);
    8.  
    9.         Texture2D texture = new Texture2D(m2.cols(), m2.rows(), TextureFormat.RGB24, false);
    10.  
    11.         Utils.matToTexture2D(m2, texture);
    12.  
    13.         return texture;
    i got:

    upload_2021-12-20_9-31-44.png

    i want:
    upload_2021-12-20_9-32-30.png


    hope you help.
     
  29. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    The "BackgroundSubtractorMOG2Example" you are using is an example from an older version.
    Try the "Examples/MainModules/video/BackgroundSubtractorComparisonExample" instead, which is included in the latest version.
     
  30. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,084
    When I try running BackgroundSubtractorComparisonExample - it gives the above error regarding cvtColor
     
  31. EnoxSoftware

    EnoxSoftware

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

    Also, please add the following code in the Start() method to observe the exceptions raised on the native side.
    Code (CSharp):
    1. "Utils.setDebugMode(true);"
    And could you please let me know the error message output to the console?
     
  32. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,084
    NullReferenceException: Object reference not set to an instance of an object
    OpenCVForUnity.ImgprocModule.Imgproc.cvtColor (OpenCVForUnity.CoreModule.Mat src, OpenCVForUnity.CoreModule.Mat dst, System.Int32 code) (at Assets/OpenCVForUnity/org/opencv/imgproc/Imgproc.cs:8194)
    OpenCVForUnityExample.BackgroundSubtractorMOG2Example.Update () (at Assets/OpenCVForUnity/Examples/MainModules/video/BackgroundSubtractorMOG2Example/BackgroundSubtractorMOG2Example.cs:144)

    Imgproc.cs:8194 Error occurs for imgproc_Imgproc_cvtColor_11

    public static void cvtColor(Mat src, Mat dst, int code)
    {
    if (src != null) src.ThrowIfDisposed();
    if (dst != null) dst.ThrowIfDisposed();

    imgproc_Imgproc_cvtColor_11(src.nativeObj, dst.nativeObj, code);


    }
     
  33. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    It seems that importing the old example BackgroundSubtractorMOG2Example into the latest OpenCVForUnity will break the scene.
    Could you please check if the scene is set up properly as shown in the screen capture below?

    BackgroundSubtractorMOG2Exa.jpg
     
  34. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    This article is an example of using OpenCVplusUnity instead of OpenCVForUnity, but I think it is very helpful.
    https://qiita.com/aazz/items/13aaa53f7bc8b2df943e
     
  35. excelremontka

    excelremontka

    Joined:
    Apr 18, 2020
    Posts:
    12
    Hello guys. Can you please tell me.How you can remove a watermark from an image?
     
  36. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    To remove the watermark, you need to purchase the paid version from AssetStore.
     
  37. excelremontka

    excelremontka

    Joined:
    Apr 18, 2020
    Posts:
    12
    В пакете есть пример?
     
  38. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,450
    "Is there an example in the package?"

    Please note that this is an English speaking forum. Your post was flagged for moderator approval but I've released it.
     
  39. excelremontka

    excelremontka

    Joined:
    Apr 18, 2020
    Posts:
    12
    "Is there an example in the package?"

    thank you very much)
     
  40. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
  41. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    331
    Hello!
    I should develop a quite simple application to track one person position on the ground inside a aisle.
    Years ago I did something like that with a Kinect, but I think that's actually a bit obsolete, and the Kinect can't "see" after few meters.
    I don't need a really good accuracy, but the aisle is about 4 meters long, so for this project I'd like to use a webcam and OpenCV.
    I've downloaded the trial version and I've run the examples, but honestly I can't understand if there's a really simple body tracking example that I can start with.
    Unfortunately I'm bit in a hurry and I can't dig too much in the documentation, so any help to understand if this can be realized with OpenCV would be much appreciated!
    Many thanks!
     
  42. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    You can use YoloObjectDetectionWebCamTextureExample or MobileNetSSDWebCamTextureExample to detect people.
    opencv3.3.1_features.png
     
  43. Abdul_Malik_Badshah

    Abdul_Malik_Badshah

    Joined:
    Oct 28, 2016
    Posts:
    13
    I am using an external USB Camera to get Texture2d and then convert it to Mat for further processing. In the WebCamtexturetoMat example, i can see the "frameMat" in created only once in the _Initialize() and on every update the webCamTexture is converted to "framMat", without creating the framMat with new initialization every time.

    In my case, if I initialize the frameMat just once at Start and just converty texture2d to mat using "Utils.texture2DToMat(tempTexture2D, frameMat, false);" I always get a black screen.

    however, if I recreate the mat at every update before converting texture2d to Mat

    frameMat = new Mat(height, width, CvType.CV_8UC4);
    Utils.texture2DToMat(tempTexture2D, frameMat, false);

    then I can see the image, (not black screen), even though the image is still shaky.

    can anyone tell me what the actual problem is
     
  44. Maouhaturaiyo

    Maouhaturaiyo

    Joined:
    Nov 25, 2019
    Posts:
    1
    Hello. I used an Markerless Example in WebGL, but when the marker is recognized I get an error or it is very slow.
    Is there a solution?I will attach an error image so it would be helpful if you could answer.Many thanks.
    Opencv for unity 2.4.6
    Unity Editor 2021.2.6f1
    PC spec
    windows 10 64bit
    i7-3770k CU 3.50GHZ 3.50GHZ
    RAM 16GB
    GTX1070
     

    Attached Files:

  45. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    As you said, WebCamTextureToMatExample generates "frameMat" only once, at the timing of _Initialize. This process assumes that the size of Texture2D is invariant on every update, but it works fine so far.
    The Texture2D to Mat conversion can fail if the sizes are different or if they have already been disposed, in which case an exception will be thrown.
    It would be useful to add the following code before Utils.texture2DToMat to prevent size mismatch.
    Code (CSharp):
    1.  
    2. if (frameMat.cols() ! = texture2D.width || frameMat.rows() ! = texture2D.height)
    3. {
    4.     Debug.Log("Recreate the mat!!!") ;
    5.     frameMat = new Mat(height, width, CvType.CV_8UC4);
    6. }
    7.  
    In order to determine the cause of this strange problem, could you please share the minimal sample code where the problem occurs?
     
  46. arcade_jon

    arcade_jon

    Joined:
    Feb 9, 2018
    Posts:
    11
    Hi. I am using OpenCVForUnity on an Apple M1 machine and cannot get it to work in editor - I keep getting:

    DllNotFoundException: opencvforunity assembly:<unknown assembly> type:<unknown type> member:(null)

    OpenCV is working fine in the resulting iOS app (although I do need to remove a rogue opencvforunity framework in Xcode to make it work).

    Is Apple silicon supported?

    Thanks
     
  47. EnoxSoftware

    EnoxSoftware

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

    arcade_jon

    Joined:
    Feb 9, 2018
    Posts:
    11
    Sure - it's:
    OpenCV for Unity version : 2.4.6
    Unity version : 2021.2.8f1
    macOS version : MacOS 12.1
    Xcode version : 13.2.1

    Thanks
     
  49. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,564
    Do you get the same error with the latest version (2.4.7) of OpenCVForUnity?
     
  50. arcade_jon

    arcade_jon

    Joined:
    Feb 9, 2018
    Posts:
    11
    Yes - same error with 2.4.7.

    Not sure if helpful, but I have tried to set the macOS plugin platform settings -> CPU to Apple Silicon, but when I then run 'Set Plugin Import Settings', it reverts the CPU value to 'Any CPU'. I've tried combinations of restarting and running the 'Set Plugin Import Settings' but no luck. Do you think it is the actual .dll that needs re-configuring for Apple Silicon?

    thanks