Search Unity

[RELEASED] OpenCV for Unity

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

  1. LAFI

    LAFI

    Joined:
    Sep 5, 2014
    Posts:
    47
    for "”DetectFaceSample" when i cange the texture it' dosn't worrk???
     
  2. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    Using the Mat.submat (), it is possible to extract a rectangle from Mat.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. using OpenCVForUnity;
    5.  
    6. namespace OpenCVForUnitySample
    7. {
    8.         /// <summary>
    9.         /// DetectFace sample.
    10.         /// </summary>
    11.         public class DetectFaceSample : MonoBehaviour
    12.         {
    13.  
    14.                 // Use this for initialization
    15.                 void Start ()
    16.                 {
    17.  
    18.                         Texture2D imgTexture = Resources.Load ("lena") as Texture2D;
    19.          
    20.                         Mat imgMat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC4);
    21.          
    22.                         Utils.texture2DToMat (imgTexture, imgMat);
    23.                         Debug.Log ("imgMat dst ToString " + imgMat.ToString ());
    24.  
    25.  
    26.                         //CascadeClassifier cascade = new CascadeClassifier (Utils.getFilePath ("lbpcascade_frontalface.xml"));
    27.                         CascadeClassifier cascade = new CascadeClassifier (Utils.getFilePath ("haarcascade_frontalface_alt.xml"));
    28.  
    29.                         Mat grayMat = new Mat ();
    30.                         Imgproc.cvtColor (imgMat, grayMat, Imgproc.COLOR_RGBA2GRAY);
    31.                         Imgproc.equalizeHist (grayMat, grayMat);
    32.  
    33.  
    34.                         MatOfRect faces = new MatOfRect ();
    35.      
    36.                         if (cascade != null)
    37.                                 cascade.detectMultiScale (grayMat, faces, 1.1, 2, 2,
    38.                                            new Size (20, 20), new Size ());
    39.  
    40.                         OpenCVForUnity.Rect[] rects = faces.toArray ();
    41.                         for (int i = 0; i < rects.Length; i++) {
    42.                                 Debug.Log ("detect faces " + rects [i]);
    43.  
    44.                                 Imgproc.rectangle (imgMat, new Point (rects [i].x, rects [i].y), new Point (rects [i].x + rects [i].width, rects [i].y + rects [i].height), new Scalar (255, 0, 0, 255), 2);
    45.                         }
    46.  
    47.                         //Extracts a rectangular submatrix.
    48.                         Mat faceMat = imgMat.submat (rects [0]);
    49.  
    50.                         Texture2D texture = new Texture2D (faceMat.cols (), faceMat.rows (), TextureFormat.RGBA32, false);
    51.          
    52.                         Utils.matToTexture2D (faceMat, texture);
    53.  
    54. //                        Texture2D texture = new Texture2D (imgMat.cols (), imgMat.rows (), TextureFormat.RGBA32, false);
    55. //
    56. //                        Utils.matToTexture2D (imgMat, texture);
    57.  
    58.                         gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
    59.  
    60.  
    61.                 }
    62.  
    63.                 // Update is called once per frame
    64.                 void Update ()
    65.                 {
    66.  
    67.                 }
    68.  
    69.                 void OnGUI ()
    70.                 {
    71.                         float screenScale = 1.0f;
    72.                         if (Screen.width < Screen.height) {
    73.                                 screenScale = Screen.width / 240.0f;
    74.                         } else {
    75.                                 screenScale = Screen.height / 360.0f;
    76.                         }
    77.                         Matrix4x4 scaledMatrix = Matrix4x4.Scale (new Vector3 (screenScale, screenScale, screenScale));
    78.                         GUI.matrix = scaledMatrix;
    79.      
    80.      
    81.                         GUILayout.BeginVertical ();
    82.                         if (GUILayout.Button ("back")) {
    83.                                 Application.LoadLevel ("OpenCVForUnitySample");
    84.                         }
    85.      
    86.      
    87.                         GUILayout.EndVertical ();
    88.                 }
    89.         }
    90. }
    submatMat.PNG
     
    LAFI likes this.
  3. LAFI

    LAFI

    Joined:
    Sep 5, 2014
    Posts:
    47
    th
    thank you so much yeahhhhh that's what i want
    also you need to change Imgproc.rectangle with crope.reactangle , i have an error
    thank you
     
  4. Misiek

    Misiek

    Joined:
    Feb 10, 2013
    Posts:
    1
    Hey I'm having issues with face detection, I'm following tutorial step by step and it doesn't work for me. A lot of stuff works but not face detection :/ here's a video showing my workflow starting with new project:

    Am I doing something wrong? I'll be grateful for all the tips.

    update:
    interestingly face detection works on laptop (the video was recorded on the desktop computer), both use nvidia with latest drivers, desktop is windows 10, did anyone tried face detection on windows 10, still weird that all the other test scenes work just fine

     
    Last edited: Aug 18, 2015
  5. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    How do you track just ONE face at a time? Is there possibly a code sample you could provide? I read of an OpenCV algorithm called camshift. Does OpenCV for Unity support this?
     
  6. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    CamShift sample is scheduled to be added to "OpenCV for Unity" of the next version.
    When you try it, please replace the following code with ”WebCamTextureToMatSample.cs”.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. using OpenCVForUnity;
    5.  
    6. using System.Collections.Generic;
    7.  
    8. namespace OpenCVForUnitySample
    9. {
    10.         /// <summary>
    11.         /// CamShift sample.
    12.         /// referring to the http://www.computervisiononline.com/blog/tutorial-using-camshift-track-objects-video.
    13.         /// </summary>
    14.         public class CamShiftSample : MonoBehaviour
    15.         {
    16.    
    17.                 /// <summary>
    18.                 /// The web cam texture.
    19.                 /// </summary>
    20.                 WebCamTexture webCamTexture;
    21.  
    22.                 /// <summary>
    23.                 /// The web cam device.
    24.                 /// </summary>
    25.                 WebCamDevice webCamDevice;
    26.  
    27.                 /// <summary>
    28.                 /// The colors.
    29.                 /// </summary>
    30.                 Color32[] colors;
    31.  
    32.                 /// <summary>
    33.                 /// The is front facing.
    34.                 /// </summary>
    35.                 public bool isFrontFacing = false;
    36.  
    37.                 /// <summary>
    38.                 /// The width.
    39.                 /// </summary>
    40.                 int width = 640;
    41.  
    42.                 /// <summary>
    43.                 /// The height.
    44.                 /// </summary>
    45.                 int height = 480;
    46.  
    47.                 /// <summary>
    48.                 /// The rgba mat.
    49.                 /// </summary>
    50.                 Mat rgbaMat;
    51.  
    52.                 /// <summary>
    53.                 /// The texture.
    54.                 /// </summary>
    55.                 Texture2D texture;
    56.  
    57.                 /// <summary>
    58.                 /// The init done.
    59.                 /// </summary>
    60.                 bool initDone = false;
    61.  
    62.                 /// <summary>
    63.                 /// The roi point list.
    64.                 /// </summary>
    65.                 List<Point> roiPointList;
    66.  
    67.                 /// <summary>
    68.                 /// The roi rect.
    69.                 /// </summary>
    70.                 OpenCVForUnity.Rect roiRect;
    71.  
    72.                 /// <summary>
    73.                 /// The hsv mat.
    74.                 /// </summary>
    75.                 Mat hsvMat;
    76.  
    77.                 /// <summary>
    78.                 /// The roi hist mat.
    79.                 /// </summary>
    80.                 Mat roiHistMat;
    81.  
    82.                 /// <summary>
    83.                 /// The termination.
    84.                 /// </summary>
    85.                 TermCriteria termination;
    86.    
    87.                 // Use this for initialization
    88.                 void Start ()
    89.                 {
    90.                         roiPointList = new List<Point> ();
    91.                         termination = new TermCriteria (TermCriteria.EPS | TermCriteria.COUNT, 10, 1);
    92.                        
    93.                         StartCoroutine (init ());
    94.  
    95.                 }
    96.  
    97.                 private IEnumerator init ()
    98.                 {
    99.                         if (webCamTexture != null) {
    100.                                 webCamTexture.Stop ();
    101.                                 initDone = false;
    102.                
    103.                                 rgbaMat.Dispose ();
    104.                                 hsvMat.Dispose ();
    105.                                 if (roiHistMat != null)
    106.                                         roiHistMat.Dispose ();
    107.                                 roiPointList.Clear ();
    108.                         }
    109.  
    110.                         // Checks how many and which cameras are available on the device
    111.                         for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; cameraIndex++) {
    112.                
    113.                
    114.                                 if (WebCamTexture.devices [cameraIndex].isFrontFacing == isFrontFacing) {
    115.                    
    116.                    
    117.                                         Debug.Log (cameraIndex + " name " + WebCamTexture.devices [cameraIndex].name + " isFrontFacing " + WebCamTexture.devices [cameraIndex].isFrontFacing);
    118.  
    119.                                         webCamDevice = WebCamTexture.devices [cameraIndex];
    120.  
    121.                                         webCamTexture = new WebCamTexture (webCamDevice.name, width, height);
    122.  
    123.                                         break;
    124.                                 }
    125.                
    126.                
    127.                         }
    128.            
    129.                         if (webCamTexture == null) {
    130.                                 webCamDevice = WebCamTexture.devices [0];
    131.                                 webCamTexture = new WebCamTexture (webCamDevice.name, width, height);
    132.                         }
    133.            
    134.                         Debug.Log ("width " + webCamTexture.width + " height " + webCamTexture.height + " fps " + webCamTexture.requestedFPS);
    135.            
    136.            
    137.            
    138.                         // Starts the camera
    139.                         webCamTexture.Play ();
    140.  
    141.  
    142.                         while (true) {
    143.                                 //If you want to use webcamTexture.width and webcamTexture.height on iOS, you have to wait until webcamTexture.didUpdateThisFrame == 1, otherwise these two values will be equal to 16. (http://forum.unity3d.com/threads/webcamtexture-and-error-0x0502.123922/)
    144.                                 #if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
    145.                                 if (webCamTexture.width > 16 && webCamTexture.height > 16) {
    146.                                 #else
    147.                                 if (webCamTexture.didUpdateThisFrame) {
    148.                                         #endif
    149.  
    150.                                         Debug.Log ("width " + webCamTexture.width + " height " + webCamTexture.height + " fps " + webCamTexture.requestedFPS);
    151.                                         Debug.Log ("videoRotationAngle " + webCamTexture.videoRotationAngle + " videoVerticallyMirrored " + webCamTexture.videoVerticallyMirrored + " isFrongFacing " + webCamDevice.isFrontFacing);
    152.                    
    153.                                         colors = new Color32[webCamTexture.width * webCamTexture.height];
    154.                    
    155.                                         rgbaMat = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC4);
    156.                                         hsvMat = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC3);
    157.                    
    158.                                         texture = new Texture2D (webCamTexture.width, webCamTexture.height, TextureFormat.RGBA32, false);
    159.  
    160.                                         gameObject.transform.eulerAngles = new Vector3 (0, 0, 0);
    161.                                         #if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
    162.                     gameObject.transform.eulerAngles = new Vector3 (0, 0, -90);
    163.                                         #endif
    164.  
    165. //                                        gameObject.transform.rotation = gameObject.transform.rotation * Quaternion.AngleAxis (webCamTexture.videoRotationAngle, Vector3.back);
    166.  
    167.                                         gameObject.transform.localScale = new Vector3 (webCamTexture.width, webCamTexture.height, 1);
    168.  
    169. //                                        bool videoVerticallyMirrored = webCamTexture.videoVerticallyMirrored;
    170. //                                        float scaleX = 1;
    171. //                                        float scaleY = videoVerticallyMirrored ? -1.0f : 1.0f;
    172. //                                        if (webCamTexture.videoRotationAngle == 270)
    173. //                                                scaleY = -1.0f;
    174. //                                        gameObject.transform.localScale = new Vector3 (scaleX * gameObject.transform.localScale.x, scaleY * gameObject.transform.localScale.y, 1);
    175.  
    176.  
    177.                                         gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
    178.  
    179.                                         #if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
    180.                                         Camera.main.orthographicSize = (((float)Screen.height/(float)Screen.width) * (float)webCamTexture.height) / 2.0f;
    181. #else
    182.                                         Camera.main.orthographicSize = webCamTexture.height / 2;
    183.                                         #endif
    184.  
    185.                                         initDone = true;
    186.                    
    187.                                         break;
    188.                                 } else {
    189.                                         yield return 0;
    190.                                 }
    191.                         }
    192.  
    193.  
    194.                        
    195.                 }
    196.    
    197.                 // Update is called once per frame
    198.                 void Update ()
    199.                 {
    200.                         if (!initDone)
    201.                                 return;
    202.        
    203.                         #if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
    204.                         if (webCamTexture.width > 16 && webCamTexture.height > 16) {
    205.                         #else
    206.                         if (webCamTexture.didUpdateThisFrame) {
    207.                                 #endif
    208.                        
    209.                                 Utils.webCamTextureToMat (webCamTexture, rgbaMat, colors);
    210.  
    211.                
    212.                                 if (webCamTexture.videoVerticallyMirrored) {
    213.                                         if (webCamDevice.isFrontFacing) {
    214.                                                 if (webCamTexture.videoRotationAngle == 0) {
    215.                                                         Core.flip (rgbaMat, rgbaMat, 1);
    216.                                                 } else if (webCamTexture.videoRotationAngle == 90) {
    217.                                                         Core.flip (rgbaMat, rgbaMat, 0);
    218.                                                 } else if (webCamTexture.videoRotationAngle == 270) {
    219.                                                         Core.flip (rgbaMat, rgbaMat, 1);
    220.                                                 }
    221.                                         } else {
    222.                                                 if (webCamTexture.videoRotationAngle == 90) {
    223.                                    
    224.                                                 } else if (webCamTexture.videoRotationAngle == 270) {
    225.                                                         Core.flip (rgbaMat, rgbaMat, -1);
    226.                                                 }
    227.                                         }
    228.                                 } else {
    229.                                         if (webCamDevice.isFrontFacing) {
    230.                                                 if (webCamTexture.videoRotationAngle == 0) {
    231.                                                         Core.flip (rgbaMat, rgbaMat, 1);
    232.                                                 } else if (webCamTexture.videoRotationAngle == 90) {
    233.                                                         Core.flip (rgbaMat, rgbaMat, 0);
    234.                                                 } else if (webCamTexture.videoRotationAngle == 270) {
    235.                                                         Core.flip (rgbaMat, rgbaMat, 1);
    236.                                                 }
    237.                                         } else {
    238.                                                 if (webCamTexture.videoRotationAngle == 90) {
    239.                                    
    240.                                                 } else if (webCamTexture.videoRotationAngle == 270) {
    241.                                                         Core.flip (rgbaMat, rgbaMat, -1);
    242.                                                 }
    243.                                         }
    244.                                 }
    245.  
    246.                                
    247.                                 Imgproc.cvtColor (rgbaMat, hsvMat, Imgproc.COLOR_RGBA2RGB);
    248.                                 Imgproc.cvtColor (hsvMat, hsvMat, Imgproc.COLOR_RGB2HSV);
    249.  
    250.  
    251.                                 Point[] points = roiPointList.ToArray ();
    252.  
    253.                                 if (roiPointList.Count == 4) {
    254.                                        
    255.  
    256.                                         using (Mat backProj = new Mat ()) {
    257.                                                 Imgproc.calcBackProject (new List<Mat> (new Mat[]{hsvMat}), new MatOfInt (0), roiHistMat, backProj, new MatOfFloat (0, 180), 1.0);
    258.  
    259.                                                 RotatedRect r = Video.CamShift (backProj, roiRect, termination);
    260.                                                 r.points (points);
    261.                                         }
    262.  
    263.                                         #if ((UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR)
    264.                             //Touch
    265.                             int touchCount = Input.touchCount;
    266.                             if (touchCount == 1)
    267.                             {
    268.                                
    269.                                 if(Input.GetTouch(0).phase == TouchPhase.Ended){
    270.                                    
    271.                                     roiPointList.Clear ();
    272.                                 }
    273.                                
    274.                             }
    275.                                         #else
    276.                                         if (Input.GetMouseButtonUp (0)) {
    277.                                                 roiPointList.Clear ();
    278.                                         }
    279. #endif
    280.                                 }
    281.  
    282.  
    283.                                 if (roiPointList.Count < 4) {
    284.  
    285.                                         #if ((UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR)
    286.                             //Touch
    287.                             int touchCount = Input.touchCount;
    288.                             if (touchCount == 1)
    289.                             {
    290.                                 Touch t = Input.GetTouch(0);
    291.                                 if(t.phase == TouchPhase.Ended){
    292.                                     roiPointList.Add (convertScreenPoint (new Point (t.position.x, t.position.y), gameObject, Camera.main));
    293. //                                    Debug.Log ("touch X " + t.position.x);
    294. //                                    Debug.Log ("touch Y " + t.position.y);
    295.  
    296.                                     if (!(new OpenCVForUnity.Rect (0, 0, hsvMat.width (), hsvMat.height ()).contains (roiPointList [roiPointList.Count - 1]))) {
    297.                                         roiPointList.RemoveAt (roiPointList.Count - 1);
    298.                                     }
    299.                                 }
    300.                                
    301.                             }
    302. #else
    303.                                         //Mouse
    304.                                         if (Input.GetMouseButtonUp (0)) {
    305.                                                
    306.                                                 roiPointList.Add (convertScreenPoint (new Point (Input.mousePosition.x, Input.mousePosition.y), gameObject, Camera.main));
    307. //                                                Debug.Log ("mouse X " + Input.mousePosition.x);
    308. //                                                Debug.Log ("mouse Y " + Input.mousePosition.y);
    309.  
    310.                                                 if (!(new OpenCVForUnity.Rect (0, 0, hsvMat.width (), hsvMat.height ()).contains (roiPointList [roiPointList.Count - 1]))) {
    311.                                                         roiPointList.RemoveAt (roiPointList.Count - 1);
    312.                                                 }
    313.                                         }
    314. #endif
    315.  
    316.                            
    317.                                         if (roiPointList.Count == 4) {
    318.  
    319.                                                 using (MatOfPoint roiPointMat = new MatOfPoint (roiPointList.ToArray ())) {
    320.                                                         roiRect = Imgproc.boundingRect (roiPointMat);
    321.                                                 }
    322.  
    323.                                
    324.                                                 if (roiHistMat != null) {
    325.                                                         roiHistMat.Dispose ();
    326.                                                         roiHistMat = null;
    327.                                                 }
    328.                                                 roiHistMat = new Mat ();
    329.  
    330.                                                 using (Mat roiHSVMat = new Mat(hsvMat, roiRect))
    331.                                                 using (Mat maskMat = new Mat ()) {
    332.  
    333.                                                        
    334.                                                         Imgproc.calcHist (new List<Mat> (new Mat[]{roiHSVMat}), new MatOfInt (0), maskMat, roiHistMat, new MatOfInt (16), new MatOfFloat (0, 180));
    335.                                                         Core.normalize (roiHistMat, roiHistMat, 0, 255, Core.NORM_MINMAX);
    336.                                
    337. //                                                        Debug.Log ("roiHist " + roiHistMat.ToString ());
    338.                                                 }
    339.                                         }
    340.                                 }
    341.  
    342.                                 if (points.Length < 4) {
    343.  
    344.                                         for (int i = 0; i < points.Length; i++) {
    345.                                                 Core.circle (rgbaMat, points [i], 6, new Scalar (0, 0, 255, 255), 2);
    346.                                         }
    347.  
    348.                                 } else {
    349.  
    350.                                         for (int i = 0; i < 4; i++) {
    351.                                                 Core.line (rgbaMat, points [i], points [(i + 1) % 4], new Scalar (255, 0, 0, 255), 2);
    352.                                         }
    353.  
    354.                                         Core.rectangle (rgbaMat, roiRect.tl (), roiRect.br (), new Scalar (0, 255, 0, 255), 2);
    355.                                 }
    356.  
    357.                                 Core.putText (rgbaMat, "PLEASE TOUCH 4 POINTS", new Point (5, 25), Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar (255, 255, 255, 255), 2, Core.LINE_AA, false);
    358.  
    359.        
    360.                                 Utils.matToTexture2D (rgbaMat, texture, colors);
    361.        
    362.                                 gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
    363.  
    364.                         }
    365.  
    366.                 }
    367.    
    368.                 void OnDisable ()
    369.                 {
    370.                         webCamTexture.Stop ();
    371.                 }
    372.    
    373.                 void OnGUI ()
    374.                 {
    375.                         float screenScale = Screen.width / 240.0f;
    376.                         Matrix4x4 scaledMatrix = Matrix4x4.Scale (new Vector3 (screenScale, screenScale, screenScale));
    377.                         GUI.matrix = scaledMatrix;
    378.        
    379.        
    380.                         GUILayout.BeginVertical ();
    381.                         if (GUILayout.Button ("back")) {
    382.                                 Application.LoadLevel ("OpenCVForUnitySample");
    383.                         }
    384.                         if (GUILayout.Button ("change camera")) {
    385.                                 isFrontFacing = !isFrontFacing;
    386.                                 StartCoroutine (init ());
    387.                         }
    388.        
    389.        
    390.                         GUILayout.EndVertical ();
    391.                 }
    392.  
    393.                 /// <summary>
    394.                 /// Converts the screen point.
    395.                 /// </summary>
    396.                 /// <returns>The screen point.</returns>
    397.                 /// <param name="screenPoint">Screen point.</param>
    398.                 /// <param name="quad">Quad.</param>
    399.                 /// <param name="cam">Cam.</param>
    400.                 static Point convertScreenPoint (Point screenPoint, GameObject quad, Camera cam)
    401.                 {
    402.                         #if ((UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR)
    403.                     Vector2 tl = cam.WorldToScreenPoint (new Vector3 (quad.transform.localPosition.x + quad.transform.localScale.y / 2, quad.transform.localPosition.y + quad.transform.localScale.x / 2, quad.transform.localPosition.z));
    404.                     Vector2 tr = cam.WorldToScreenPoint (new Vector3 (quad.transform.localPosition.x + quad.transform.localScale.y / 2, quad.transform.localPosition.y - quad.transform.localScale.x / 2, quad.transform.localPosition.z));
    405.                     Vector2 br = cam.WorldToScreenPoint (new Vector3 (quad.transform.localPosition.x - quad.transform.localScale.y / 2, quad.transform.localPosition.y - quad.transform.localScale.x / 2, quad.transform.localPosition.z));
    406.                     Vector2 bl = cam.WorldToScreenPoint (new Vector3 (quad.transform.localPosition.x - quad.transform.localScale.y / 2, quad.transform.localPosition.y + quad.transform.localScale.x / 2, quad.transform.localPosition.z));
    407. #else
    408.                         Vector2 tl = cam.WorldToScreenPoint (new Vector3 (quad.transform.localPosition.x - quad.transform.localScale.x / 2, quad.transform.localPosition.y + quad.transform.localScale.y / 2, quad.transform.localPosition.z));
    409.                         Vector2 tr = cam.WorldToScreenPoint (new Vector3 (quad.transform.localPosition.x + quad.transform.localScale.x / 2, quad.transform.localPosition.y + quad.transform.localScale.y / 2, quad.transform.localPosition.z));
    410.                         Vector2 br = cam.WorldToScreenPoint (new Vector3 (quad.transform.localPosition.x + quad.transform.localScale.x / 2, quad.transform.localPosition.y - quad.transform.localScale.y / 2, quad.transform.localPosition.z));
    411.                         Vector2 bl = cam.WorldToScreenPoint (new Vector3 (quad.transform.localPosition.x - quad.transform.localScale.x / 2, quad.transform.localPosition.y - quad.transform.localScale.y / 2, quad.transform.localPosition.z));
    412. #endif
    413.  
    414.                         Mat srcRectMat = new Mat (4, 1, CvType.CV_32FC2);
    415.                         Mat dstRectMat = new Mat (4, 1, CvType.CV_32FC2);
    416.  
    417.                        
    418.                         srcRectMat.put (0, 0, tl.x, tl.y, tr.x, tr.y, br.x, br.y, bl.x, bl.y);
    419.                         dstRectMat.put (0, 0, 0.0, 0.0, quad.transform.localScale.x, 0.0, quad.transform.localScale.x, quad.transform.localScale.y, 0.0, quad.transform.localScale.y);
    420.  
    421.                        
    422.                         Mat perspectiveTransform = Imgproc.getPerspectiveTransform (srcRectMat, dstRectMat);
    423.  
    424. //                        Debug.Log ("srcRectMat " + srcRectMat.dump ());
    425. //                        Debug.Log ("dstRectMat " + dstRectMat.dump ());
    426. //                        Debug.Log ("perspectiveTransform " + perspectiveTransform.dump ());
    427.  
    428.                         MatOfPoint2f srcPointMat = new MatOfPoint2f (screenPoint);
    429.                         MatOfPoint2f dstPointMat = new MatOfPoint2f ();
    430.  
    431.                         Core.perspectiveTransform (srcPointMat, dstPointMat, perspectiveTransform);
    432.  
    433. //                        Debug.Log ("srcPointMat " + srcPointMat.dump ());
    434. //                        Debug.Log ("dstPointMat " + dstPointMat.dump ());
    435.  
    436.                         return dstPointMat.toArray () [0];
    437.                 }
    438.         }
    439. }
     
  7. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
  8. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    OpenCV for Unity
    Released Version 1.1.9


    Version changes
    1.1.9
    [Common]Add CamShiftSample.(Object Tracking)
    [Common]Add OpenCVForUnityMenuItem.cs.( This script set plugin import settings automatically from MenuItem.)
     
  9. EdilsonJunior

    EdilsonJunior

    Joined:
    Mar 17, 2015
    Posts:
    29
    this appearing a size of output error in all instances and nothing appears , how can I solve this? erro.jpg
     
  10. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    if Unity4,
    Please move a folder like the next image.
    スクリーンショット 2015-07-25 22.14.57.png
    After having set up Plugin, Plugin may work well when you reboot Unity.
     
  11. EdilsonJunior

    EdilsonJunior

    Joined:
    Mar 17, 2015
    Posts:
    29
    I created the plugin and organized folders but still the same. What I do?
    e.jpg e.jpg
     
  12. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    Do you have Pro License?
    if Unity4, Unity Pro License is required in order to run "OpenCV for Unity" in Editor.
    If you do not have, please try to run in Unity5.
     
  13. EdilsonJunior

    EdilsonJunior

    Joined:
    Mar 17, 2015
    Posts:
    29
    using the free Unity5 will work?
     
  14. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    Yes.
    Anyone became able to use native plugin by Editor without a pro license from Unity5.
     
  15. KeithT

    KeithT

    Joined:
    Nov 23, 2011
    Posts:
    83
    The Beta 3.0.0 does not compile in Unity 5. Problem with the CamShiftSample.cs

    Error 1 'OpenCVForUnity.Core' does not contain a definition for 'circle' C:\opencv\Assets\OpenCVForUnity\Samples\CamShiftSample\CamShiftSample.cs 345 18 UnityVS.opencv.CSharp

    Same again for line, rectangle, putText
     
  16. KeithT

    KeithT

    Joined:
    Nov 23, 2011
    Posts:
    83
    Yes we can build for android using a personal Unity 5 licence for OpenCV2
     
  17. kennethwoodruff

    kennethwoodruff

    Joined:
    May 20, 2013
    Posts:
    2
    Hi everyone. I've been using OCVfU quite a lot in the past few weeks on a face tracking/creation project. Huge thanks to the developer(s)!

    I have a big question though. I am trying to get accurate facial landmarks using the FaceTracker example as a starting point, and even thought I am resetting it and feeding fresh points with each cycle, it seems to operate in a more predictive fashion than I need. I would like accurate position data so I can take measurements, but it seems to infer positioning and shape rather than deriving it. Is there a way to replace the tracking model, or tweak some setting or mode I haven't yet seen, to get more accurate results? Thanks for your time.
     
  18. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    From OpenCV3 it seems the method of "circle","line","rectangle","putText" has moved from "Core" class to "Imgproc" class.
    To fix error, please replace "Core" of error points to "Imgproc".
     
  19. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Get the following error with Beta 3.0 /Samples/FaceRecognizerSample/FaceRecognizerSample.cs(44,91): error CS0117: `Face' does not contain a definition for `createEigenFaceRecognizer'
     
  20. EdilsonJunior

    EdilsonJunior

    Joined:
    Mar 17, 2015
    Posts:
    29
    how do I generate the density of the object from the points of optcalFlowSimple ?
     
  21. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    Thank you for an error report.
    Please tell me the environment where an error happened.
     
  22. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    Since ”OpenCV for Unity” is a clone of "OpenCV Java", please refer to the example of "OpenCV Java".
     
  23. EdilsonJunior

    EdilsonJunior

    Joined:
    Mar 17, 2015
    Posts:
    29
    the applications do not run properly on android, android is my 4.1.2 . the screen goes blank .
    the attached image shows what's going on.
    what's the problem?
    2015-08-29-18-20-45.jpg
     
  24. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    Does other samples work fine?
    Is error message displayed in LogCat?
     
  25. EdilsonJunior

    EdilsonJunior

    Joined:
    Mar 17, 2015
    Posts:
    29
    not all samples are white .
    in unity runs perfect, but the cell does not run .
     
  26. EdilsonJunior

    EdilsonJunior

    Joined:
    Mar 17, 2015
    Posts:
    29
    to run the build , it shows the following information .
    errado.png
     
  27. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    Please try setup again in reference to New Setup Tutorial Video for Unity5.
     
  28. EdilsonJunior

    EdilsonJunior

    Joined:
    Mar 17, 2015
    Posts:
    29
    Thank you very much for your help, I wonder if it is possible to inform the distance between the detected point and webcam?
     
  29. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Have been trying to get BackgroundSubtraction working. Referenced a couple Java OpenCV code samples and am very close(I think). The following compiles correctly and we still see a webcamTexture. Howver, I need to either display the created foreground mask(_fgMask) and-or combine it with my original webCamTexture. Can any C# or OpenCV experts help?

    My C# source so far

    using OpenCVForUnity;
    using System.Collections;
    using System.Drawing;
    using System.Drawing.Imaging;
    using UnityEngine;

    public class OpenCV_backgroundSubtraction : MonoBehaviour
    {
    private float _minSize;
    private float _maxSize;

    private WebCamTexture webCamTexture;

    private WebCamDevice webCamDevice;

    private Color32[] colors;

    /// <summary>
    /// The is front facing.
    /// </summary>
    public bool isFrontFacing = false;

    private int width = 640;

    private int height = 480;

    private Mat rgbaMat;

    private Mat grayMat;

    private Mat _fgMask;

    private Mat _rgbaMat;

    private Texture2D texture;

    private MatOfRect faces;

    private BackgroundSubtractorMOG2 _mBGSub;
    private VideoCapture _camera;

    private bool initDone = false;

    // Use this for initialization
    private void Start()
    {
    StartCoroutine(init());
    }

    private IEnumerator init()
    {
    if (webCamTexture != null)
    {
    _minSize = (float)width / 6.0f;
    _maxSize = _minSize * 1.5f;

    webCamTexture.Stop();
    initDone = false;

    rgbaMat.Dispose();
    grayMat.Dispose();
    }
    _mBGSub = new BackgroundSubtractorMOG2(2, 16, true);

    _camera = new VideoCapture();

    if (webCamTexture == null)
    {
    webCamDevice = WebCamTexture.devices[0];
    webCamTexture = new WebCamTexture(webCamDevice.name, width, height);
    }

    // Starts the camera
    webCamTexture.Play();

    while (true)
    {
    if (webCamTexture.didUpdateThisFrame)
    {
    colors = new Color32[webCamTexture.width * webCamTexture.height];

    rgbaMat = new Mat(webCamTexture.height, webCamTexture.width, CvType.CV_8UC4);
    grayMat = new Mat(webCamTexture.height, webCamTexture.width, CvType.CV_8UC1);

    texture = new Texture2D(webCamTexture.width, webCamTexture.height, TextureFormat.RGBA32, false);

    gameObject.GetComponent<Renderer>().material.mainTexture = texture;
    // Camera.main.orthographicSize = webCamTexture.height / 2;

    Camera.main.orthographicSize = webCamTexture.height / 2;

    initDone = true;

    break;
    }
    else
    {
    yield return 0;
    }
    }
    }

    // Update is called once per frame
    private void Update()
    {
    Bitmap bmp = null;
    // if (!initDone)
    // return;

    //*/

    if (webCamTexture.didUpdateThisFrame)
    {
    Utils.webCamTextureToMat(webCamTexture, rgbaMat, colors);
    _fgMask = new Mat(webCamTexture.height, webCamTexture.width, CvType.CV_8UC1);
    _rgbaMat = _fgMask.clone();
    processFrame();

    bmp = new System.Drawing.Bitmap(100, 100, PixelFormat.Format32bppArgb);

    Utils.matToTexture2D(rgbaMat, texture, colors);
    }

    //*/
    }

    protected void processFrame()//
    {
    _camera.retrieve(_rgbaMat, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGB);

    _mBGSub.apply(_rgbaMat, _fgMask, 0.1);
    Imgproc.cvtColor(_fgMask, _rgbaMat, Imgproc.COLOR_GRAY2BGRA, 4);
    }

    private void OnDisable()
    {
    webCamTexture.Stop();
    }

    private void OnGUI()
    {
    }
    }

    //}
     
  30. jjuam

    jjuam

    Joined:
    Jun 12, 2015
    Posts:
    51
    Many thanks for the info!

    I want know how can I use this for several images at the same time. I mean, I have an app with 6 photos saved in a folder, and I want to recognize the eyes on each picture. Is there an easy way to use this plugin for several images at the same time? I tried using diferents quads in which I put every image, and then use the plugin, but I´m not getting what I wish...

    Thanks a lot!!
     
  31. EdilsonJunior

    EdilsonJunior

    Joined:
    Mar 17, 2015
    Posts:
    29
    I wonder if it is possible to inform the distance between the detected point and webcam?
     
  32. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. using OpenCVForUnity;
    5.  
    6. namespace OpenCVForUnitySample
    7. {
    8.         /// <summary>
    9.         /// WebCamTexture to mat sample.
    10.         /// </summary>
    11.         public class BackgroundSubtractorMOGSample : MonoBehaviour
    12.         {
    13.    
    14.                 /// <summary>
    15.                 /// The web cam texture.
    16.                 /// </summary>
    17.                 WebCamTexture webCamTexture;
    18.  
    19.                 /// <summary>
    20.                 /// The web cam device.
    21.                 /// </summary>
    22.                 WebCamDevice webCamDevice;
    23.  
    24.                 /// <summary>
    25.                 /// The colors.
    26.                 /// </summary>
    27.                 Color32[] colors;
    28.  
    29.                 /// <summary>
    30.                 /// The is front facing.
    31.                 /// </summary>
    32.                 public bool isFrontFacing = false;
    33.  
    34.                 /// <summary>
    35.                 /// The width.
    36.                 /// </summary>
    37.                 int width = 640;
    38.  
    39.                 /// <summary>
    40.                 /// The height.
    41.                 /// </summary>
    42.                 int height = 480;
    43.  
    44.                 /// <summary>
    45.                 /// The rgba mat.
    46.                 /// </summary>
    47.                 Mat rgbaMat;
    48.  
    49.                 /// <summary>
    50.                 /// The gray mat.
    51.                 /// </summary>
    52.                 Mat grayMat;
    53.  
    54.                 /// <summary>
    55.                 /// The fgmask mat.
    56.                 /// </summary>
    57.                 Mat fgmaskMat;
    58.  
    59.                 /// <summary>
    60.                 /// The background substractor MO g2.
    61.                 /// </summary>
    62.                 BackgroundSubtractorMOG2 backgroundSubstractorMOG2;
    63.  
    64.                 /// <summary>
    65.                 /// The texture.
    66.                 /// </summary>
    67.                 Texture2D texture;
    68.  
    69.                 /// <summary>
    70.                 /// The init done.
    71.                 /// </summary>
    72.                 bool initDone = false;
    73.  
    74.    
    75.                 // Use this for initialization
    76.                 void Start ()
    77.                 {
    78.                         backgroundSubstractorMOG2 = new BackgroundSubtractorMOG2 (2, 16, true);
    79.                        
    80.                         StartCoroutine (init ());
    81.  
    82.                 }
    83.  
    84.                 private IEnumerator init ()
    85.                 {
    86.                         if (webCamTexture != null) {
    87.                                 webCamTexture.Stop ();
    88.                                 initDone = false;
    89.                
    90.                                 rgbaMat.Dispose ();
    91.                         }
    92.  
    93.                         // Checks how many and which cameras are available on the device
    94.                         for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; cameraIndex++) {
    95.                
    96.                
    97.                                 if (WebCamTexture.devices [cameraIndex].isFrontFacing == isFrontFacing) {
    98.                    
    99.                    
    100.                                         Debug.Log (cameraIndex + " name " + WebCamTexture.devices [cameraIndex].name + " isFrontFacing " + WebCamTexture.devices [cameraIndex].isFrontFacing);
    101.  
    102.                                         webCamDevice = WebCamTexture.devices [cameraIndex];
    103.  
    104.                                         webCamTexture = new WebCamTexture (webCamDevice.name, width, height);
    105.  
    106.                                         break;
    107.                                 }
    108.                
    109.                
    110.                         }
    111.            
    112.                         if (webCamTexture == null) {
    113.                                 webCamDevice = WebCamTexture.devices [0];
    114.                                 webCamTexture = new WebCamTexture (webCamDevice.name, width, height);
    115.                         }
    116.            
    117.                         Debug.Log ("width " + webCamTexture.width + " height " + webCamTexture.height + " fps " + webCamTexture.requestedFPS);
    118.            
    119.            
    120.            
    121.                         // Starts the camera
    122.                         webCamTexture.Play ();
    123.  
    124.  
    125.                         while (true) {
    126.                                 //If you want to use webcamTexture.width and webcamTexture.height on iOS, you have to wait until webcamTexture.didUpdateThisFrame == 1, otherwise these two values will be equal to 16. (http://forum.unity3d.com/threads/webcamtexture-and-error-0x0502.123922/)
    127.                                 #if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
    128.                                 if (webCamTexture.width > 16 && webCamTexture.height > 16) {
    129.                                 #else
    130.                                 if (webCamTexture.didUpdateThisFrame) {
    131.                                         #endif
    132.  
    133.                                         Debug.Log ("width " + webCamTexture.width + " height " + webCamTexture.height + " fps " + webCamTexture.requestedFPS);
    134.                                         Debug.Log ("videoRotationAngle " + webCamTexture.videoRotationAngle + " videoVerticallyMirrored " + webCamTexture.videoVerticallyMirrored + " isFrongFacing " + webCamDevice.isFrontFacing);
    135.                    
    136.                                         colors = new Color32[webCamTexture.width * webCamTexture.height];
    137.                    
    138.                                         rgbaMat = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC4);
    139.                                         grayMat = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC1);
    140.                                         fgmaskMat = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC1);
    141.                    
    142.                                         texture = new Texture2D (webCamTexture.width, webCamTexture.height, TextureFormat.RGBA32, false);
    143.  
    144.                                         gameObject.transform.eulerAngles = new Vector3 (0, 0, 0);
    145.                                         #if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
    146.                     gameObject.transform.eulerAngles = new Vector3 (0, 0, -90);
    147.                                         #endif
    148.  
    149. //                                        gameObject.transform.rotation = gameObject.transform.rotation * Quaternion.AngleAxis (webCamTexture.videoRotationAngle, Vector3.back);
    150.  
    151.                                         gameObject.transform.localScale = new Vector3 (webCamTexture.width, webCamTexture.height, 1);
    152.  
    153. //                                        bool videoVerticallyMirrored = webCamTexture.videoVerticallyMirrored;
    154. //                                        float scaleX = 1;
    155. //                                        float scaleY = videoVerticallyMirrored ? -1.0f : 1.0f;
    156. //                                        if (webCamTexture.videoRotationAngle == 270)
    157. //                                                scaleY = -1.0f;
    158. //                                        gameObject.transform.localScale = new Vector3 (scaleX * gameObject.transform.localScale.x, scaleY * gameObject.transform.localScale.y, 1);
    159.  
    160.  
    161.                                         gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
    162.  
    163.                                         #if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
    164.                                         Camera.main.orthographicSize = (((float)Screen.height/(float)Screen.width) * (float)webCamTexture.height) / 2.0f;
    165.                                         #else
    166.                                         Camera.main.orthographicSize = webCamTexture.height / 2;
    167.                                         #endif
    168.  
    169.                                         initDone = true;
    170.                    
    171.                                         break;
    172.                                 } else {
    173.                                         yield return 0;
    174.                                 }
    175.                         }
    176.                 }
    177.    
    178.                 // Update is called once per frame
    179.                 void Update ()
    180.                 {
    181.                         if (!initDone)
    182.                                 return;
    183.        
    184.                         #if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
    185.                         if (webCamTexture.width > 16 && webCamTexture.height > 16) {
    186.                         #else
    187.                         if (webCamTexture.didUpdateThisFrame) {
    188.                                 #endif
    189.                        
    190.                                 Utils.webCamTextureToMat (webCamTexture, rgbaMat, colors);
    191.  
    192.                
    193.                                 if (webCamTexture.videoVerticallyMirrored) {
    194.                                         if (webCamDevice.isFrontFacing) {
    195.                                                 if (webCamTexture.videoRotationAngle == 0) {
    196.                                                         Core.flip (rgbaMat, rgbaMat, 1);
    197.                                                 } else if (webCamTexture.videoRotationAngle == 90) {
    198.                                                         Core.flip (rgbaMat, rgbaMat, 0);
    199.                                                 } else if (webCamTexture.videoRotationAngle == 270) {
    200.                                                         Core.flip (rgbaMat, rgbaMat, 1);
    201.                                                 }
    202.                                         } else {
    203.                                                 if (webCamTexture.videoRotationAngle == 90) {
    204.                                    
    205.                                                 } else if (webCamTexture.videoRotationAngle == 270) {
    206.                                                         Core.flip (rgbaMat, rgbaMat, -1);
    207.                                                 }
    208.                                         }
    209.                                 } else {
    210.                                         if (webCamDevice.isFrontFacing) {
    211.                                                 if (webCamTexture.videoRotationAngle == 0) {
    212.                                                         Core.flip (rgbaMat, rgbaMat, 1);
    213.                                                 } else if (webCamTexture.videoRotationAngle == 90) {
    214.                                                         Core.flip (rgbaMat, rgbaMat, 0);
    215.                                                 } else if (webCamTexture.videoRotationAngle == 270) {
    216.                                                         Core.flip (rgbaMat, rgbaMat, 1);
    217.                                                 }
    218.                                         } else {
    219.                                                 if (webCamTexture.videoRotationAngle == 90) {
    220.                                    
    221.                                                 } else if (webCamTexture.videoRotationAngle == 270) {
    222.                                                         Core.flip (rgbaMat, rgbaMat, -1);
    223.                                                 }
    224.                                         }
    225.                                 }
    226.  
    227.                                 Imgproc.cvtColor (rgbaMat, grayMat, Imgproc.COLOR_RGBA2GRAY);
    228.  
    229.                                 backgroundSubstractorMOG2.apply (grayMat, fgmaskMat, 0.1f);
    230.                                
    231.        
    232.                                 Utils.matToTexture2D (fgmaskMat, texture, colors);
    233.        
    234.                                 gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
    235.  
    236.                         }
    237.  
    238.                 }
    239.    
    240.                 void OnDisable ()
    241.                 {
    242.                         webCamTexture.Stop ();
    243.                 }
    244.    
    245.                 void OnGUI ()
    246.                 {
    247.                         float screenScale = Screen.width / 240.0f;
    248.                         Matrix4x4 scaledMatrix = Matrix4x4.Scale (new Vector3 (screenScale, screenScale, screenScale));
    249.                         GUI.matrix = scaledMatrix;
    250.        
    251.        
    252.                         GUILayout.BeginVertical ();
    253.                         if (GUILayout.Button ("back")) {
    254.                                 Application.LoadLevel ("OpenCVForUnitySample");
    255.                         }
    256.                         if (GUILayout.Button ("change camera")) {
    257.                                 isFrontFacing = !isFrontFacing;
    258.                                 StartCoroutine (init ());
    259.                         }
    260.        
    261.        
    262.                         GUILayout.EndVertical ();
    263.                 }
    264.         }
    265. }
     
  33. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
  34. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Thanks!

    Still having a problem getting a 'clean' mask.

    Is there any other setting other than the threshold value in the BackgroundSubtractorMOG2 constructo
    I should be adjusting?







     
  35. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    Please refer to an example of "OpenCV Java".
    http://stackoverflow.com/a/27545979
     
  36. thed-venth

    thed-venth

    Joined:
    Aug 13, 2014
    Posts:
    8
    hi!
    can we do face morph by using this plugin?

    here is the sample of the face morph what I mean
     
  37. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    I think that it is probably feasible.
    By using this sample, you can get face’s points and connections.
    https://www.assetstore.unity3d.com/en/#!/content/35284
     
  38. EdilsonJunior

    EdilsonJunior

    Joined:
    Mar 17, 2015
    Posts:
    29
  39. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
  40. EdilsonJunior

    EdilsonJunior

    Joined:
    Mar 17, 2015
    Posts:
    29
  41. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    OpenCV for Unity
    Released Version 1.2.0


    Version changes
    1.2.0
    [Common]Add Utils. getGraphicsDeviceType().
    [Common]Add SampleScene Setup Tutorial Video for Unity5.
     
  42. FragrantJH

    FragrantJH

    Joined:
    Aug 24, 2015
    Posts:
    1
    I use Open CV for unity with Vuforia engine now.
    I have an issue with using both of them I think.

    My OS : Windows 7, 64x
    Unity : 4.6.1
    Vuforia : 4.2.3
    OpenCV for Unity : 1.1.9

    The situation is like this,
    I created project and ran work perfectly yesterday.
    Today when I try to run the project Vuforia's play mode is error. I do not get this situations..

    upload_2015-9-10_12-13-4.png

    To fix this problem export my project -> generate a new project -> import Vuforia package -> add ARCamera -> import my package
    It works fine !!!!!!!!!! so ridiculous.

    I think there are some reasons on either Vuforia or OpenCV for Unity.

    Do you supporters have any ideas for that ?
    Am I wrong with moving *.dll files to Plugins folder?
    Please help me !
     
  43. adroitandy

    adroitandy

    Joined:
    Nov 4, 2013
    Posts:
    30
    Hi,
    I have been using the plugin for one of my projects to convert webcam texture to mat, but on running on one of my test Mac machines the app crashes with with an exception in "
    /Users/xinsensong/Desktop/MAC/090515/MacVideoCapture/VideoCapture.app/Contents/Plugins/opencvforunity.bundle/Contents/MacOS/libopencv_imgproc.2.4.11.dylib" , the error is Symbol not found: ___sincos_stret. I have attached the complete error log. please let me know if this is an issue with the OS version or device configuration.
     

    Attached Files:

  44. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    "OpenCV for Unity" requires OSX 10.8 or later.
    Please test on OSX 10.8 or later.
     
  45. EdilsonJunior

    EdilsonJunior

    Joined:
    Mar 17, 2015
    Posts:
    29
  46. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    Unfortunately,
    Because I do not know a lot about the algorithm of OpenCV, I cannot give you good advice.
     
  47. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,018
    Code (csharp):
    1.  cascade.detectMultiScale (equalizeHistMat, faces, 1.1f, 2, 0
    2.                                                          | Objdetect.CASCADE_FIND_BIGGEST_OBJECT
    3.                                                          | Objdetect.CASCADE_SCALE_IMAGE, new OpenCVForUnity.Size (equalizeHistMat.cols () * 0.15, equalizeHistMat.cols () * 0.15), new Size ());
    "FaceTrackerARSample " This code on Android is very slow,How to optimize it?
     
  48. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,018
    On CameraImageToMatSample.cs, I want to get rgb texture,
    so I change code
    Code (csharp):
    1.   inputMat = newMat (image.Height, image.Width, CvType.CV_8UC1);
    to
    Code (csharp):
    1.  inputMat = newMat (image.Height, image.Width, CvType.CV_8UC4);
    But..texture have 5 picture...why?

    If I used "Image.PIXEL_FORMAT.RGB888;" Vuforia say "image is not available yet".....

    Thanks. 6EBAD7BF-082E-4C7D-A864-25F3B1B5DE1E.jpg
     
  49. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,565
    Please use the "CvType.CV_8UC3".
    Code (CSharp):
    1. inputMat = newMat (image.Height, image.Width, CvType.CV_8UC3);
     
  50. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Is it possible to do swipe detection using OpenCV?