コード例 #1
0
        public IEnumerator <ITask> UpdateBinHandler(UpdateBin update)
        {
            ColorBin existing = _state.ColorBins.Find(
                delegate(ColorBin test)
            {
                return(test.Name == update.Body.Name);
            }
                );

            if (existing != null)
            {
                int index = _state.ColorBins.IndexOf(existing);
                _state.ColorBins[index] = update.Body;

                update.ResponsePort.Post(DefaultUpdateResponseType.Instance);
                SendNotification(_subMgrPort, update);
                SaveState(_state);
            }
            else
            {
                update.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(
                        FaultCodes.Receiver,
                        DsspFaultCodes.UnknownEntry,
                        "A Color Bin named " + update.Body.Name + " could not be found."
                        )
                    );
            }
            yield break;
        }
コード例 #2
0
        public IEnumerator <ITask> InsertBinHandler(InsertBin insert)
        {
            ColorBin existing = _state.ColorBins.Find(
                delegate(ColorBin test)
            {
                return(test.Name == insert.Body.Name);
            }
                );

            if (existing == null)
            {
                _state.ColorBins.Add(insert.Body);
                insert.ResponsePort.Post(DefaultInsertResponseType.Instance);
                SendNotification(_subMgrPort, insert);
                SaveState(_state);
            }
            else
            {
                insert.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(
                        FaultCodes.Receiver,
                        DsspFaultCodes.DuplicateEntry,
                        "A Color Bin named " + insert.Body.Name + " already exists."
                        )
                    );
            }
            yield break;
        }
コード例 #3
0
        IEnumerator <ITask> ProcessImage(List <ColorBin> bins)
        {
            Fault fault = null;

            cam.QueryFrameRequest request = new cam.QueryFrameRequest();
            request.Format = Guid.Empty;// new Guid("b96b3cae-0728-11d3-9d7b-0000f81ef32e");

            byte[]   frame     = null;
            DateTime timestamp = DateTime.MinValue;
            int      height    = 0;
            int      width     = 0;

            yield return(Arbiter.Choice(
                             _camPort.QueryFrame(request),
                             delegate(cam.QueryFrameResponse response)
            {
                timestamp = response.TimeStamp;
                frame = response.Frame;
                width = response.Size.Width;
                height = response.Size.Height;
            },
                             delegate(Fault f)
            {
                fault = f;
            }
                             ));

            ImageProcessedRequest processed = new ImageProcessedRequest();

            if (fault != null)
            {
                _mainPort.Post(new ImageProcessed(processed));
                yield break;
            }

            int size = width * height * 3;

            processed.TimeStamp = timestamp;
            List <FoundBlob> results = processed.Results;

            foreach (ColorBin bin in bins)
            {
                FoundBlob blob = new FoundBlob();

                blob.Name        = bin.Name;
                blob.XProjection = new int[width];
                blob.YProjection = new int[height];

                results.Add(blob);
            }

            int offset;

            for (int y = 0; y < height; y++)
            {
                offset = y * width * 3;

                for (int x = 0; x < width; x++, offset += 3)
                {
                    int r, g, b;

                    b = frame[offset];
                    g = frame[offset + 1];
                    r = frame[offset + 2];

                    for (int i = 0; i < bins.Count; i++)
                    {
                        ColorBin bin = bins[i];

                        if (bin.Test(r, g, b))
                        {
                            results[i].AddPixel(x, y);
                        }
                    }
                }
            }

            foreach (FoundBlob blob in results)
            {
                if (blob.Area > 0)
                {
                    blob.MeanX = blob.MeanX / blob.Area;
                    blob.MeanY = blob.MeanY / blob.Area;

                    blob.CalculateMoments();
                }
            }

            _mainPort.Post(new ImageProcessed(processed));
        }