示例#1
0
        private void runNeuralNet_Click(object sender, EventArgs e)
        {
            reset.Enabled = true;

            var bmp   = new BitmapImage(PanelToBitmap());
            var blobs = blobFinder.From(bmp);

            if (blobs.Any())
            {
                panel1.CreateGraphics().DrawRectangles(Pens.Red, blobs.ToArray());

                var imageSampler = new ImageSampler();
                var samples      = imageSampler.SampleImage(bmp).GetSamples().Select(s => s.NormalizedLuminosity).ToArray();
                var output       = bnn.ComputeOutputs(samples);

                if (output[0] > 0.90 && output[1] < 0.05)
                {
                    BackColor = Color.Green;
                }
                else
                {
                    BackColor = Color.Red;
                }
            }
            repaint = false;
        }
示例#2
0
        /**
         * Render using the specified options and the specified display. If the
         * specified options do not exist - defaults will be used.
         *
         * @param optionsName name of the {@link RenderObject} which contains the
         *            options
         * @param display display object
         */
        public void render(string optionsName, IDisplay display)
        {
            if (string.IsNullOrEmpty(optionsName))
            {
                optionsName = "::options";
            }
            renderObjects.updateScene(scene);
            Options opt = lookupOptions(optionsName);

            if (opt == null)
            {
                opt = new Options();
            }
            scene.setCamera(lookupCamera(opt.getstring("camera", null)));

            // baking
            string bakingInstanceName = opt.getstring("baking.instance", null);

            if (bakingInstanceName != null)
            {
                Instance bakingInstance = lookupInstance(bakingInstanceName);
                if (bakingInstance == null)
                {
                    UI.printError(UI.Module.API, "Unable to bake instance \"{0}\" - not found", bakingInstanceName);
                    return;
                }
                scene.setBakingInstance(bakingInstance);
            }
            else
            {
                scene.setBakingInstance(null);
            }

            string       samplerName = opt.getstring("sampler", "bucket");
            ImageSampler sampler     = null;

            if (samplerName == "none" || samplerName == "null")
            {
                sampler = null;
            }
            else if (samplerName == "bucket")
            {
                sampler = bucketRenderer;
            }
            else if (samplerName == "ipr")
            {
                sampler = progressiveRenderer;
            }
            else if (samplerName == "fast")
            {
                sampler = new SimpleRenderer();
            }
            else
            {
                UI.printError(UI.Module.API, "Unknown sampler type: {0} - aborting", samplerName);
                return;
            }
            scene.render(opt, sampler, display);
        }
示例#3
0
    // Use this for initialization
    void Start()
    {
        _faceDetector = new OpenCVFaceDetector(Config);
        _faceDetector.OnFaceDetected += OnFaceDetected;
        _faceDetector.Start();

        _imgSampler = new ImageSampler(Texture);
        _imgSampler.OnImageSampled += OnImageSampled;
    }
示例#4
0
 void OnImageSampled(ImageSampler s, GstImageInfo ifo)
 {
     if (_detect)
     {
         _faceDetector.BindImage(ifo);
         _processing = true;
     }
     _detect = false;
 }
示例#5
0
        /**
         * Render using the specified options and the specified display. If the
         * specified options do not exist - defaults will be used.
         *
         * @param optionsName name of the {@link RenderObject} which contains the
         *            options
         * @param display display object
         */
        public void render(string optionsName, IDisplay display)
        {
            if (string.IsNullOrEmpty(optionsName))
            {
                optionsName = "::options";
            }
            renderObjects.updateScene(scene);
            Options opt = lookupOptions(optionsName);

            if (opt == null)
            {
                opt = new Options();
            }
            scene.setCamera(lookupCamera(opt.getstring("camera", null)));

            // shader override
            String shaderOverrideName = opt.getstring("override.shader", "none");
            bool   overridePhotons    = opt.getbool("override.photons", false);

            if (shaderOverrideName.Equals("none"))
            {
                scene.setShaderOverride(null, false);
            }
            else
            {
                IShader shader = lookupShader(shaderOverrideName);
                if (shader == null)
                {
                    UI.printWarning(UI.Module.API, "Unable to find shader \"{0}\" for override, disabling", shaderOverrideName);
                }
                scene.setShaderOverride(shader, overridePhotons);
            }

            // baking
            string bakingInstanceName = opt.getstring("baking.instance", null);

            if (bakingInstanceName != null)
            {
                Instance bakingInstance = lookupInstance(bakingInstanceName);
                if (bakingInstance == null)
                {
                    UI.printError(UI.Module.API, "Unable to bake instance \"{0}\" - not found", bakingInstanceName);
                    return;
                }
                scene.setBakingInstance(bakingInstance);
            }
            else
            {
                scene.setBakingInstance(null);
            }

            ImageSampler sampler = PluginRegistry.imageSamplerPlugins.createObject(opt.getstring("sampler", "bucket"));

            scene.render(opt, sampler, display);
        }
示例#6
0
    protected override void OnCameraSourceCreated(TxKitEyes creator, ICameraSource src)
    {
        base.OnCameraSourceCreated(creator, src);

        if (_imgSampler != null)
        {
            _imgSampler.Destroy();
        }
        _imgSampler = new ImageSampler(src.GetBaseTexture());
        _imgSampler.OnImageSampled += OnImageArrived;
    }
示例#7
0
        private void ChooseNormalMapButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "jpg files (*.jpg)|*.jpg|" +
                                    "png files (*.png)|*.png|All files (*.*)|*.*";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                ImageSampler isamp = new ImageSampler(new Bitmap(openFileDialog.FileName), drawingBox.Width, drawingBox.Height);
                isamp.Transform(v => Vector3.Normalize(new Vector3(v.X * 2 - 1, -(v.Y * 2 - 1), v.Z)));
                scene.Normals = isamp;
                drawingBox.Invalidate();
            }
        }
示例#8
0
        public EditorForm()
        {
            InitializeComponent();
            Shader     shader     = new PreciseShader();
            GlobalData globalData = new GlobalData(Color.White, new Vector3(0, 0, 10000));
            var        normals    = new ImageSampler(new Bitmap("..\\..\\data\\Normals.jpg"), drawingBox.Width, drawingBox.Height);

            normals.Transform(v => Vector3.Normalize(new Vector3(v.X * 2 - 1, -(v.Y * 2 - 1), v.Z)));
            scene = new Scene(new MemoryBitmap(drawingBox.Width, drawingBox.Height), shader, globalData)
            {
                MainTex = new ImageSampler(new Bitmap("..\\..\\data\\Image.jpg"), drawingBox.Width, drawingBox.Height),
                Normals = normals
            };
            CreateMesh();
        }
示例#9
0
    // Use this for initialization
    void Start()
    {
        if (SourceTexture == null)
        {
            SourceTexture = GameObject.FindObjectOfType <GstCustomTexture> ();
        }

        _imgSampler = new ImageSampler(SourceTexture);
        _imgSampler.OnImageSampled += OnImageSampled;

        _detector = new UnityOpenCVObjectDetectorAPI();
        _sampling = true;

        _tmp = new GstImageInfo();
        _tmp.Create(1, 1, GstImageInfo.EPixelFormat.EPixel_Alpha8);

        TrackingManager.Instance.Ref();
    }
示例#10
0
        private IEnumerable <ImageSampler> ReadTrainingSet(string trainingLedgerPath)
        {
            var viewer = new ImageViewer();

            if (prettyPictures)
            {
                Task.Run(() =>
                {
                    viewer.Show();
                    Application.Run(viewer);
                });
            }
            else
            {
                Console.WriteLine("This may take a while... ");
            }

            var count       = 1;
            var updateAt    = 25;
            var lines       = File.ReadAllLines(trainingLedgerPath);
            var samplesList = new List <ImageSampler>();

            for (var i = 0; i < lines.Count(); i++)
            {
                using (var example = new ImageSampler(lines[i]))
                {
                    if (prettyPictures)
                    {
                        example.DrawToViewer(viewer);
                    }
                    else if (count % updateAt == 0)
                    {
                        Console.WriteLine($"Finished {count}...");
                    }

                    samplesList.Add(example);
                }
            }

            return(samplesList.ToArray());
        }
示例#11
0
        private static Texture CreateSplatTexture(Engine engine)
        {
            // To generate a Gaussian splat, create a single-channel 3x3 texture with a bright pixel in
            // its center, then magnify it using a Gaussian filter kernel.
            var splat = new LinearImage(3, 3, 1);

            splat.SetPixelData(1, 1, 0.25f);
            splat = ImageSampler.ResampleImage(splat, TEXTURE_SIZE, TEXTURE_SIZE, ImageSamplerFilter.GaussianScalars);

            var buffer = new PixelBufferDescriptor(splat, PixelDataFormat.R, PixelDataType.Float);

            var texture = TextureBuilder.Create()
                          .WithWidth(TEXTURE_SIZE)
                          .WithHeight(TEXTURE_SIZE)
                          .WithLevels(1)
                          .WithSampler(TextureSamplerType.Texture2d)
                          .WithFormat(TextureFormat.R32F)
                          .Build(engine);

            texture.SetImage(engine, 0, buffer);

            return(texture);
        }
示例#12
0
        /**
         * Render the scene using the specified options, image sampler and display.
         *
         * @param options rendering options object
         * @param sampler image sampler
         * @param display display to send the image to, a default display will
         *            be created if <code>null</code>
         */
        public void render(Options options, ImageSampler sampler, IDisplay display)
        {
            if (display == null)
                display = null;// new FrameDisplay();

            if (bakingInstance != null)
            {
                UI.printDetailed(UI.Module.SCENE, "Creating primitives for lightmapping ...");
                bakingPrimitives = bakingInstance.getBakingPrimitives();
                if (bakingPrimitives == null)
                {
                    UI.printError(UI.Module.SCENE, "Lightmap baking is not supported for the given instance.");
                    return;
                }
                int n = bakingPrimitives.getNumPrimitives();
                UI.printInfo(UI.Module.SCENE, "Building acceleration structure for lightmapping ({0} num primitives) ...", n);
                bakingAccel = AccelerationStructureFactory.create("auto", n, true);
                bakingAccel.build(bakingPrimitives);
            }
            else
            {
                bakingPrimitives = null;
                bakingAccel = null;
            }
            bakingViewDependent = options.getbool("baking.viewdep", bakingViewDependent);

            if ((bakingInstance != null && bakingViewDependent && camera == null) || (bakingInstance == null && camera == null))
            {
                UI.printError(UI.Module.SCENE, "No camera found");
                return;
            }

            // read from options
            threads = options.getInt("threads", 0);
            lowPriority = options.getbool("threads.lowPriority", true);
            imageWidth = options.getInt("resolutionX", 640);
            imageHeight = options.getInt("resolutionY", 480);
            // limit resolution to 16k
            imageWidth = MathUtils.clamp(imageWidth, 1, 1 << 14);
            imageHeight = MathUtils.clamp(imageHeight, 1, 1 << 14);

            // get acceleration structure info
            // count scene primitives
            long numPrimitives = 0;
            for (int i = 0; i < instanceList.getNumPrimitives(); i++)
                numPrimitives += instanceList.getNumPrimitives(i);
            UI.printInfo(UI.Module.SCENE, "Scene stats:");
            UI.printInfo(UI.Module.SCENE, "  * Infinite instances:  {0}", infiniteInstanceList.getNumPrimitives());
            UI.printInfo(UI.Module.SCENE, "  * Instances:           {0}", instanceList.getNumPrimitives());
            UI.printInfo(UI.Module.SCENE, "  * Primitives:          {0}", numPrimitives);
            string accelName = options.getstring("accel", null);
            if (accelName != null)
            {
                rebuildAccel = rebuildAccel || acceltype != accelName;
                acceltype = accelName;
            }
            UI.printInfo(UI.Module.SCENE, "  * Instance accel:      {0}", acceltype);
            if (rebuildAccel)
            {
                intAccel = AccelerationStructureFactory.create(acceltype, instanceList.getNumPrimitives(), false);
                intAccel.build(instanceList);
                rebuildAccel = false;
            }
            UI.printInfo(UI.Module.SCENE, "  * Scene bounds:        {0}", getBounds());
            UI.printInfo(UI.Module.SCENE, "  * Scene center:        {0}", getBounds().getCenter());
            UI.printInfo(UI.Module.SCENE, "  * Scene diameter:      {0}", getBounds().getExtents().Length());
            UI.printInfo(UI.Module.SCENE, "  * Lightmap bake:       {0}", bakingInstance != null ? (bakingViewDependent ? "view" : "ortho") : "off");
            if (sampler == null)
                return;
            if (!lightServer.build(options))
                return;
            // render
            UI.printInfo(UI.Module.SCENE, "Rendering ...");
            sampler.prepare(options, this, imageWidth, imageHeight);
            sampler.render(display);
            lightServer.showStats();
            // discard baking tesselation/accel structure
            bakingPrimitives = null;
            bakingAccel = null;
            UI.printInfo(UI.Module.SCENE, "Done.");
        }
示例#13
0
 void OnImageArrived(ImageSampler sampler, GstImageInfo img)
 {
     _newImageArrived = true;
     _textureUpdated  = false;
 }
示例#14
0
 void OnImageSampled(ImageSampler sampler, GstImageInfo img)
 {
     _processing = true;
     img.CloneTo(_tmp);
     TrackingManager.Instance.AddTicket(this);
 }
示例#15
0
        /**
         * Render the scene using the specified options, image sampler and display.
         *
         * @param options rendering options object
         * @param sampler image sampler
         * @param display display to send the image to, a default display will
         *            be created if <code>null</code>
         */
        public void render(Options options, ImageSampler sampler, IDisplay display)
        {
            stats.reset();
            if (display == null)
            {
                display = null;// new FrameDisplay();
            }
            if (bakingInstance != null)
            {
                UI.printDetailed(UI.Module.SCENE, "Creating primitives for lightmapping ...");
                bakingPrimitives = bakingInstance.getBakingPrimitives();
                if (bakingPrimitives == null)
                {
                    UI.printError(UI.Module.SCENE, "Lightmap baking is not supported for the given instance.");
                    return;
                }
                int n = bakingPrimitives.getNumPrimitives();
                UI.printInfo(UI.Module.SCENE, "Building acceleration structure for lightmapping ({0} num primitives) ...", n);
                bakingAccel = AccelerationStructureFactory.create("auto", n, true);
                bakingAccel.build(bakingPrimitives);
            }
            else
            {
                bakingPrimitives = null;
                bakingAccel      = null;
            }
            bakingViewDependent = options.getbool("baking.viewdep", bakingViewDependent);

            if ((bakingInstance != null && bakingViewDependent && camera == null) || (bakingInstance == null && camera == null))
            {
                UI.printError(UI.Module.SCENE, "No camera found");
                return;
            }

            // read from options
            threads     = options.getInt("threads", 0);
            lowPriority = options.getbool("threads.lowPriority", true);
            imageWidth  = options.getInt("resolutionX", 640);
            imageHeight = options.getInt("resolutionY", 480);
            // limit resolution to 16k
            imageWidth  = MathUtils.clamp(imageWidth, 1, 1 << 14);
            imageHeight = MathUtils.clamp(imageHeight, 1, 1 << 14);

            // prepare lights
            createAreaLightInstances();

            // get acceleration structure info
            // count scene primitives
            long numPrimitives = 0;

            for (int i = 0; i < instanceList.getNumPrimitives(); i++)
            {
                numPrimitives += instanceList.getNumPrimitives(i);
            }
            UI.printInfo(UI.Module.SCENE, "Scene stats:");
            UI.printInfo(UI.Module.SCENE, "  * Infinite instances:  {0}", infiniteInstanceList.getNumPrimitives());
            UI.printInfo(UI.Module.SCENE, "  * Instances:           {0}", instanceList.getNumPrimitives());
            UI.printInfo(UI.Module.SCENE, "  * Primitives:          {0}", numPrimitives);
            string accelName = options.getstring("accel", null);

            if (accelName != null)
            {
                rebuildAccel = rebuildAccel || acceltype != accelName;
                acceltype    = accelName;
            }
            UI.printInfo(UI.Module.SCENE, "  * Instance accel:      {0}", acceltype);
            if (rebuildAccel)
            {
                intAccel = AccelerationStructureFactory.create(acceltype, instanceList.getNumPrimitives(), false);
                intAccel.build(instanceList);
                rebuildAccel = false;
            }
            UI.printInfo(UI.Module.SCENE, "  * Scene bounds:        {0}", getBounds());
            UI.printInfo(UI.Module.SCENE, "  * Scene center:        {0}", getBounds().getCenter());
            UI.printInfo(UI.Module.SCENE, "  * Scene diameter:      {0}", getBounds().getExtents().Length());
            UI.printInfo(UI.Module.SCENE, "  * Lightmap bake:       {0}", bakingInstance != null ? (bakingViewDependent ? "view" : "ortho") : "off");
            if (sampler == null)
            {
                return;
            }
            if (!lightServer.build(options))
            {
                return;
            }
            // render
            UI.printInfo(UI.Module.SCENE, "Rendering ...");
            stats.setResolution(imageWidth, imageHeight);
            sampler.prepare(options, this, imageWidth, imageHeight);
            sampler.render(display);
            // show statistics
            stats.displayStats();
            lightServer.showStats();
            // discard area lights
            removeAreaLightInstances();

            // discard baking tesselation/accel structure
            bakingPrimitives = null;
            bakingAccel      = null;
            UI.printInfo(UI.Module.SCENE, "Done.");
        }
示例#16
0
        public BuildingStoryLayout(ICoroutineService coroutineService, IEmbeddedResources embeddedResources,
                                   IInputService inputService, Lazy <INavigationService> navigationServiceLazy)
        {
            this.embeddedResources     = embeddedResources;
            this.inputService          = inputService;
            this.navigationServiceLazy = navigationServiceLazy;
            this.coroutineService      = coroutineService;
            planeModel     = embeddedResources.SimplePlaneXzModel();
            lineModel      = embeddedResources.LineModel();
            frustumModel   = embeddedResources.SimpleFrustumModel();
            colorMaterials = new IMaterial[]
            {
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1f, 0f, 0f) * 0.8f, 1.0f)).SetIgnoreLighting(true),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0f, 1f, 0f) * 0.8f, 1.0f)).SetIgnoreLighting(true),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0f, 0f, 1f) * 0.8f, 1.0f)).SetIgnoreLighting(true),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1f, 1f, 0f) * 0.8f, 1.0f)).SetIgnoreLighting(true),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1f, 0f, 1f) * 0.8f, 1.0f)).SetIgnoreLighting(true),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0f, 1f, 1f) * 0.8f, 1.0f)).SetIgnoreLighting(true),
            };
            frustumMaterial = StandardMaterial.New()
                              .SetDiffuseColor(new Color4(0f, 1f, 0f))
                              .SetIgnoreLighting(true)
                              .FromGlobalCache();
            lineMaterial = StandardMaterial.New()
                           .SetDiffuseColor(Color4.White)
                           .SetIgnoreLighting(true)
                           .FromGlobalCache();
            currentLineMaterial = StandardMaterial.New()
                                  .SetDiffuseColor(Color4.Red)
                                  .SetIgnoreLighting(true)
                                  .FromGlobalCache();
            lineRenderState = StandardRenderState.New().SetLineWidth(3).FromGlobalCache();

            var mirrorSampler = new ImageSampler
            {
                AddressModeU = ImageSamplerAddressMode.Mirror,
                AddressModeV = ImageSamplerAddressMode.Mirror,
                AddressModeW = ImageSamplerAddressMode.Mirror,
            }.FromGlobalCache();

            floorMaterial = StandardMaterial.New()
                            .SetDiffuseMap(embeddedResources.Image("Textures/museum_floor.jpg"))
                            .SetNoSpecular(true)
                            .SetSampler(mirrorSampler)
                            .FromGlobalCache();
            ceilingMaterial = StandardMaterial.New()
                              .SetDiffuseMap(embeddedResources.Image("Textures/museum_ceiling.jpg"))
                              .SetNoSpecular(true)
                              .SetSampler(mirrorSampler)
                              .FromGlobalCache();
            wallMaterial = StandardMaterial.New()
                           .SetDiffuseMap(embeddedResources.Image("Textures/museum_wall.jpg"))
                           .SetDiffuseColor(new Color4(92, 82, 72))
                           //.SetNoSpecular(true)
                           .SetNormalMap(embeddedResources.Image("Textures/museum_wall_2_norm.jpg"))
                           .FromGlobalCache();
            rawWallMaterial = StandardMaterial.New()
                              .SetDiffuseColor(Color4.Green)
                              .SetIgnoreLighting(true)
                              .FromGlobalCache();
        }