public void Connect(CVImageLink input)
        {
            Disconnect();

            FLink = input;

            if (FLink.Allocated)
            {
                FImageAttributesFresh = true;
                FImageFresh           = true;
            }

            AddListeners();
        }
Exemplo n.º 2
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (SpreadMax == 0)
            {
                RemoveListeners();
                return;
            }

            int slice = FPinInSlice[0];

            if (FInput != FPinInInput[slice])
            {
                FInput = FPinInInput[slice];
                AddListeners();
                if (FInput.Allocated)
                {
                    UpdateAttributes(FInput.ImageAttributes);
                    UpdateImage();
                }
            }
        }
Exemplo n.º 3
0
		//called when data for any output pin is requested
		public void Evaluate(int SpreadMax)
		{
			if (SpreadMax == 0)
			{
				RemoveListeners();
				return;
			}

			int slice = FPinInSlice[0];
			if (FInput != FPinInInput[slice])
			{
				FInput = FPinInInput[slice];
				AddListeners();
				if (FInput.Allocated)
				{
					UpdateAttributes(FInput.ImageAttributes);
					UpdateImage();
				}
			}
		}
 public bool ConnectedTo(CVImageLink input)
 {
     return(input == FLink);
 }
 public void Disconnect()
 {
     RemoveListeners();
     FLink = null;
 }
Exemplo n.º 6
0
		void SetupOutput(int count)
		{
			FOutImage.SliceCount = count;
			for (int i = 0; i < count; i++)
			{
				FOutImage[i] = new CVImageLink();
			}
		}
Exemplo n.º 7
0
		public void Evaluate(int SpreadMax)
		{
			if (!FInitialised)
			{
				FOutput[0] = new CVImageLink();
				FInitialised = true;
			}

			try
			{
				if (FInput.PluginIO.IsConnected)
				{
					if (this.RenderRequest != null) { this.RenderRequest(this, this.FHost); }

					if (this.AssignedContext == null) { return; }

					var device = this.AssignedContext.Device;
					var context = this.AssignedContext;

					DX11Texture2D t = this.FInput[0][this.AssignedContext];
					var height = t.Height;
					var width = t.Width;
					
					var imageLink = FOutput[0];
					var imageAttributes = imageLink.ImageAttributes;
					var desiredImageFormat = ToOpenCVFormat(t.Format);

					if (desiredImageFormat == TColorFormat.UnInitialised)
						throw (new Exception("No suitible image type available for this texture type" + t.Format.ToString()));
					

					//--
					//check attributes and reinitialise the image if we haven't got the right image ready
					//
					if (imageAttributes == null || FOffscreenBuffer == null || !imageAttributes.Initialised || FOffscreenBuffer.Description.Format != t.Description.Format || imageAttributes.Width != t.Width || imageAttributes.Height != t.Height || imageAttributes.ColourFormat != desiredImageFormat)
					{
						if (FOffscreenBuffer != null)
							FOffscreenBuffer.Dispose();

						var description = new Texture2DDescription()
						{
							Width = width,
							Height = height,
							Format = t.Format,
							MipLevels = 1,
							Usage = ResourceUsage.Staging,
							BindFlags = BindFlags.None,
							CpuAccessFlags = CpuAccessFlags.Read,
							SampleDescription = new SampleDescription(1, 0),
							ArraySize = 1
						};
						
						FOffscreenBuffer = new Texture2D(this.AssignedContext.Device, description);

						imageLink.Initialise(new CVImageAttributes(desiredImageFormat, t.Width, t.Height));
					}
					//
					//--


					//--
					//copy the texture to offscreen buffer
					//
					context.CurrentDeviceContext.CopyResource(t.Resource, FOffscreenBuffer);
					//
					//--


					//--
					//copy the data out of the offscreen buffer
					//
					var surface = FOffscreenBuffer.AsSurface();
					var bytesPerRow = imageAttributes.Stride;

					var data = MapForRead(context.CurrentDeviceContext);
					lock (imageLink.BackLock)
					{
						var image = imageLink.BackImage;
						try
						{
							var source = data.Data.DataPointer;

							image.SetPixels(source);

							var destination = image.Data;

							for (int row = 0; row < t.Height; row++)
							{
								CopyMemory(destination, source, bytesPerRow);

								source += data.RowPitch;
								destination += bytesPerRow;
							}
						}
						finally
						{
							UnMap(context.CurrentDeviceContext);
						}
					}
					//
					//--

					imageLink.Swap();
				}
			}
			catch (Exception e)
			{
				FLogger.Log(e);
			}
		}
Exemplo n.º 8
0
        public void Evaluate(int SpreadMax)
        {
            if (!FInitialised)
            {
                FOutput[0]   = new CVImageLink();
                FInitialised = true;
            }

            try
            {
                if (FInput.PluginIO.IsConnected)
                {
                    if (this.RenderRequest != null)
                    {
                        this.RenderRequest(this, this.FHost);
                    }

                    if (this.AssignedContext == null)
                    {
                        return;
                    }

                    var device  = this.AssignedContext.Device;
                    var context = this.AssignedContext;

                    DX11Texture2D t      = this.FInput[0][this.AssignedContext];
                    var           height = t.Height;
                    var           width  = t.Width;

                    var imageLink          = FOutput[0];
                    var imageAttributes    = imageLink.ImageAttributes;
                    var desiredImageFormat = ToOpenCVFormat(t.Format);

                    if (desiredImageFormat == TColorFormat.UnInitialised)
                    {
                        throw (new Exception("No suitible image type available for this texture type" + t.Format.ToString()));
                    }


                    //--
                    //check attributes and reinitialise the image if we haven't got the right image ready
                    //
                    if (imageAttributes == null || FOffscreenBuffer == null || !imageAttributes.Initialised || FOffscreenBuffer.Description.Format != t.Description.Format || imageAttributes.Width != t.Width || imageAttributes.Height != t.Height || imageAttributes.ColourFormat != desiredImageFormat)
                    {
                        if (FOffscreenBuffer != null)
                        {
                            FOffscreenBuffer.Dispose();
                        }

                        var description = new Texture2DDescription()
                        {
                            Width             = width,
                            Height            = height,
                            Format            = t.Format,
                            MipLevels         = 1,
                            Usage             = ResourceUsage.Staging,
                            BindFlags         = BindFlags.None,
                            CpuAccessFlags    = CpuAccessFlags.Read,
                            SampleDescription = new SampleDescription(1, 0),
                            ArraySize         = 1
                        };

                        FOffscreenBuffer = new Texture2D(this.AssignedContext.Device, description);

                        imageLink.Initialise(new CVImageAttributes(desiredImageFormat, t.Width, t.Height));
                    }
                    //
                    //--


                    //--
                    //copy the texture to offscreen buffer
                    //
                    context.CurrentDeviceContext.CopyResource(t.Resource, FOffscreenBuffer);
                    //
                    //--


                    //--
                    //copy the data out of the offscreen buffer
                    //
                    var surface     = FOffscreenBuffer.AsSurface();
                    var bytesPerRow = imageAttributes.Stride;

                    var data = MapForRead(context.CurrentDeviceContext);
                    lock (imageLink.BackLock)
                    {
                        var image = imageLink.BackImage;
                        try
                        {
                            var source = data.Data.DataPointer;

                            image.SetPixels(source);

                            var destination = image.Data;

                            for (int row = 0; row < t.Height; row++)
                            {
                                CopyMemory(destination, source, bytesPerRow);

                                source      += data.RowPitch;
                                destination += bytesPerRow;
                            }
                        }
                        finally
                        {
                            UnMap(context.CurrentDeviceContext);
                        }
                    }
                    //
                    //--

                    imageLink.Swap();
                }
            }
            catch (Exception e)
            {
                FLogger.Log(e);
            }
        }