/// <summary> /// Raises the save button event. /// </summary> public void OnSaveButton() { if (patternRawImage.texture != null) { Texture2D patternTexture = (Texture2D)patternRawImage.texture; Mat patternMat = new Mat(patternRect.size(), CvType.CV_8UC3); Utils.texture2DToMat(patternTexture, patternMat); Imgproc.cvtColor(patternMat, patternMat, Imgproc.COLOR_RGB2BGR); string savePath = Application.persistentDataPath; Debug.Log("savePath " + savePath); Imgcodecs.imwrite(savePath + "/patternImg.jpg", patternMat); #if UNITY_5_3 || UNITY_5_3_OR_NEWER SceneManager.LoadScene("WebCamTextureMarkerLessARExample"); #else Application.LoadLevel("WebCamTextureMarkerLessARExample"); #endif } }
private void detectInRegion(Mat img, Rect r, List <Rect> detectedObjectsInRegions) { Rect r0 = new Rect(new Point(), img.size()); Rect r1 = new Rect(r.x, r.y, r.width, r.height); Inflate(r1, (int)((r1.width * innerParameters.coeffTrackingWindowSize) - r1.width) / 2, (int)((r1.height * innerParameters.coeffTrackingWindowSize) - r1.height) / 2); r1 = Intersect(r0, r1); if ((r1.width <= 0) || (r1.height <= 0)) { Debug.Log("DetectionBasedTracker::detectInRegion: Empty intersection"); return; } int d = Math.Min(r.width, r.height); d = (int)Math.Round(d * innerParameters.coeffObjectSizeToTrack); MatOfRect tmpobjects = new MatOfRect(); Mat img1 = new Mat(img, r1); //subimage for rectangle -- without data copying regionCascade.detectMultiScale(img1, tmpobjects, parameters.scaleFactor, parameters.minNeighbors, 0 | Objdetect.CASCADE_DO_CANNY_PRUNING | Objdetect.CASCADE_SCALE_IMAGE | Objdetect.CASCADE_FIND_BIGGEST_OBJECT, new Size(d, d), new Size()); Rect[] tmpobjectsArray = tmpobjects.toArray(); int len = tmpobjectsArray.Length; for (int i = 0; i < len; i++) { Rect tmp = tmpobjectsArray [i]; Rect curres = new Rect(new Point(tmp.x + r1.x, tmp.y + r1.y), tmp.size()); detectedObjectsInRegions.Add(curres); } }