public PipelineText <TO> ConvertText <P, TO>() where P : class, IAggregateStructure <TT, TO> { var initial = (IEnumerable <TT>) this.CurrentStream; var transform = _factory.CreateGlobalInstance <P>(); var processor = new TransformText <P, TT, TO>(transform); _tracker.TrackInstance(processor); var index = processor.GetIndexRef(); _indexTree.AddRef(index); var result = processor.Transform(initial); var pipe = new PipelineText <TO>(_factory, this.Context, result, _indexTree, this); return(pipe); }
protected override bool ProcessTexture(WebCamTexture input, ref Texture2D output) { Mat image = OpenCvSharp.Unity.TextureToMat(input, TextureParameters); Mat downscaled = image.Resize(Size.Zero, downScale, downScale); Rect2d obj = Rect2d.Empty; var areaRect = new OpenCvSharp.Rect(); int tempCount = processor.ProcessTexture(input, TextureParameters); if (meatlist.Count < tempCount) { Debug.Log(tempCount + " meat change"); for (int i = 0; i < meatlist.Count; i++) { DropTracking(i); } meatlist = new List <DetectedMeat>(processor.Meats); } //Debug.Log("meat count : " + meatlist.Count); // If not dragged - show the tracking data if (meatlist.Count > 0) { for (int i = 0; i < meatlist.Count; i++) { DetectedMeat meat = meatlist[meatlist.Count - i - 1]; // we have to tracker - let's initialize one if (tracker.Count <= i || tracker[i] == null) { // but only if we have big enough "area of interest", this one is added to avoid "tracking" some 1x2 pixels areas if (new Vector2(meat.Region.X, meat.Region.Y).magnitude >= minimumAreaDiagonal) { obj = new Rect2d(meat.Region.X * downScale, meat.Region.Y * downScale, meat.Region.Width * downScale, meat.Region.Height * downScale); // initial tracker with current image and the given rect, one can play with tracker types here if (tracker.Count <= i) { tracker.Add(Tracker.Create(TrackerTypes.MedianFlow)); meatText.Add(InstantiateText.Instxt(gameObject.GetComponent <RectTransform>(), meat.Region)); Debug.Log("add tracker"); } else if (tracker[i] == null) { Debug.Log("replace tracker"); tracker[i] = Tracker.Create(TrackerTypes.MedianFlow); meatText[i] = InstantiateText.Instxt(gameObject.GetComponent <RectTransform>(), meat.Region); } tracker[i].Init(downscaled, obj); //GameObject text = InstantiateText.Instxt(gameObject.GetComponent<RectTransform>(), meat.Region); //frameSize.Add(downscaled.Size()); //var newVec = new Vector2((float)obj.X, -(float)obj.Y) - new Vector2(image.Width / 2.0f, -image.Height / 2.0f); //GameObject a = GameObject.Instantiate(UIText, gameObject.transform.parent); //a.transform.localPosition = (newVec + new Vector2((float)obj.Width / 2.0f, 0)) * gameObject.transform.localScale.x; } } // if we already have an active tracker - just to to update with the new frame and check whether it still tracks object else { // drop tracker if the frame's size has changed, this one is necessary as tracker doesn't hold it well //if (frameSize.Count > i && frameSize[i].Height != 0 && frameSize[i].Width != 0) //DropTracking(i); if (!tracker[i].Update(downscaled, ref obj)) { Debug.Log("404 not found"); obj = Rect2d.Empty; DropTracking(i); } } // save tracked object location if (0 != obj.Width && 0 != obj.Height) { areaRect = new OpenCvSharp.Rect((int)obj.X, (int)obj.Y, (int)obj.Width, (int)obj.Height); } // render rect we've tracker or one is being drawn by the user if (null != tracker[i] && obj.Width != 0) { Cv2.Rectangle((InputOutputArray)(image), areaRect * (1.0 / downScale), Scalar.LightGreen, 4); TransformText.Trnstxt(meatText[i], gameObject.GetComponent <RectTransform>(), areaRect); //Cv2.PutText((InputOutputArray)(image), i.ToString("000"), new Point(areaRect.X, areaRect.Y), HersheyFonts.HersheySimplex, 2, Scalar.Yellow, 3); } } } // mark detected objects //processor.MarkDetected(image); // processor.Image now holds data we'd like to visualize output = OpenCvSharp.Unity.MatToTexture(image, output); // if output is valid texture it's buffer will be re-used, otherwise it will be re-created return(true); }