public override void Process()
 {
     try
     {
         CvInvoke.cvResize(FInput.Image.CvMat, FOutput.Image.CvMat, INTER.CV_INTER_LINEAR);
         FOutput.Send();
     }
     catch (Exception e)
     {
         ImageUtils.Log(e);
     }
 }
示例#2
0
        private void ThreadedFunction()
        {
            while (FThreadRunning)
            {
                if (FInput.Connected)
                {
                    lock (FLockProcess)
                    {
                        for (int i = 0; i < SliceCount; i++)
                        {
                            if (!FInput[i].Allocated)
                            {
                                continue;
                            }

                            if (FInput[i].ImageAttributesChanged || !FOutput[i].Link.Allocated)
                            {
                                try
                                {
                                    FProcess[i].Initialise();
                                }
                                catch
                                {
                                    continue;
                                }
                            }

                            try
                            {
                                if (FInput[i].ImageChanged)
                                {
                                    for (int iProcess = i; iProcess < SliceCount; iProcess += (FInput.SliceCount > 0 ? FInput.SliceCount : int.MaxValue))
                                    {
                                        FProcess[iProcess].Process();
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                ImageUtils.Log(e);
                            }
                        }
                    }

                    Thread.Sleep(1);
                }
                else
                {
                    Thread.Sleep(10);
                }
            }
        }
        public static Texture CreateTexture(CVImageAttributes attributes, Device device)
        {
            TColourFormat format = attributes.ColourFormat;
            TColourFormat newFormat;
            bool          useConverted = NeedsConversion(format, out newFormat);

            try
            {
                return(new Texture(device, Math.Max(attributes.Width, 1), Math.Max(attributes.Height, 1), 1, Usage.None, GetDXFormat(useConverted ? newFormat : format), Pool.Managed));
            }
            catch (Exception e)
            {
                ImageUtils.Log(e);
                return(new Texture(device, 1, 1, 1, Usage.None, Format.X8R8G8B8, Pool.Managed));
            }
        }
 private void ThreadedFunction()
 {
     while (FThreadRunning)
     {
         lock (FLockProcess)
         {
             try
             {
                 for (int i = 0; i < FProcess.SliceCount; i++)
                 {
                     FProcess[i].Process();
                 }
             }
             catch (Exception e)
             {
                 ImageUtils.Log(e);
             }
         }
     }
 }
        public void UpdateTexture(Texture texture)
        {
            lock (FLockTexture)
            {
                if (!FNeedsRefresh.ContainsKey(texture))
                {
                    FNeedsTexture = true;
                    return;
                }

                if (!FNeedsRefresh[texture])
                {
                    return;
                }

                if (FInput.ImageAttributesChanged)
                {
                    //reset flag we just dropped
                    FInput.ImageAttributesChanged = true;
                    return;
                }

                FNeedsRefresh[texture] = false;

                Surface       srf  = texture.GetSurfaceLevel(0);
                DataRectangle rect = srf.LockRectangle(LockFlags.Discard);

                if (FNeedsConversion)
                {
                    if (!FBufferConverted.Allocated)
                    {
                        srf.UnlockRectangle();
                        return;
                    }

                    FInput.GetImage(FBufferConverted);
                    FBufferConverted.LockForReading();
                    try
                    {
                        rect.Data.WriteRange(FBufferConverted.FrontImage.Data, FBufferConverted.ImageAttributes.BytesPerFrame);
                    }
                    finally
                    {
                        FBufferConverted.ReleaseForReading();
                    }
                }
                else
                {
                    FInput.LockForReading();
                    try
                    {
                        rect.Data.WriteRange(FInput.Data, FInput.ImageAttributes.BytesPerFrame);
                    }
                    catch (Exception e)
                    {
                        ImageUtils.Log(e);
                    }
                    finally
                    {
                        FInput.ReleaseForReading();
                    }
                }

                srf.UnlockRectangle();
            }
        }
示例#6
0
        public void UpdateTexture(Texture texture)
        {
            lock (FLockTexture)
            {
                if (!FNeedsRefresh.ContainsKey(texture))
                {
                    FNeedsTexture = true;
                    return;
                }

                if (!FNeedsRefresh[texture])
                {
                    return;
                }

                if (FInput.ImageAttributesChanged)
                {
                    //reset flag we just dropped
                    FInput.ImageAttributesChanged = true;
                    return;
                }

                FNeedsRefresh[texture] = false;

                Surface       srf  = texture.GetSurfaceLevel(0);
                DataRectangle rect = srf.LockRectangle(LockFlags.Discard);

                Size imageSize = FNeedsConversion ? FBufferConverted.ImageAttributes.Size : FInput.ImageAttributes.Size;

                if (srf.Description.Width != imageSize.Width || srf.Description.Height != imageSize.Height)
                {
                    ImageUtils.Log(new Exception("AsTextureInstance : srf dimensions don't match image dimensions"));
                    return;
                }

                if (FNeedsConversion)
                {
                    if (!FBufferConverted.Allocated)
                    {
                        srf.UnlockRectangle();
                        return;
                    }

                    FInput.GetImage(FBufferConverted);
                    FBufferConverted.LockForReading();
                    try
                    {
                        rect.Data.WriteRange(FBufferConverted.FrontImage.Data, FBufferConverted.ImageAttributes.BytesPerFrame);
                    }
                    finally
                    {
                        FBufferConverted.ReleaseForReading();
                    }
                }
                else
                {
                    FInput.LockForReading();
                    try
                    {
                        rect.Data.WriteRange(FInput.Data, FInput.ImageAttributes.BytesPerFrame);
                    }
                    catch (Exception e)
                    {
                        ImageUtils.Log(e);
                    }
                    finally
                    {
                        FInput.ReleaseForReading();
                    }
                }

                srf.UnlockRectangle();
            }
        }