private VisionResult Fm_SoftwareCliab_DetectLabel(string arg1, Module arg2, Nozzle arg3)
        {
            VisionResult rtn = new VisionResult();

            if (this.bSet_CamLive)
            {
                this.bCamLive_Click(this, new EventArgs());
                Thread.Sleep(100);
            }

            Camera camera = Camera.Bottom1;

            if (arg3 == Nozzle.Nz3 || arg3 == Nozzle.Nz4)
            {
                camera = Camera.Bottom2;
            }

            var roi = SystemEntiy.Instance[arg2].MachineConfig[arg3].ViewRoi;

            using (VisionImage img = CameraDefine.Instance.Camera[arg2][camera].Snap())
            {
                rtn = VisionCalHelper.Instance.DetectUI(arg1, img, roi);
                Algorithms.Copy(img, this.imageSet.imageSet.Image);
            }

            return(rtn);
        }
        private void ImageSet_VisionDetect(string func)
        {
            if (this.imageSet.imageSet.Roi.Count > 0)
            {
                Camera       camera = (Camera)this.cameraComboBox.SelectedIndex;
                VisionResult rtn    = new VisionResult();
                if (this.bSet_CamLive)
                {
                    this.bCamLive_Click(this, new EventArgs());
                    Thread.Sleep(100);
                }

                using (VisionImage img = CameraDefine.Instance.Camera[this.Module][camera].Snap())
                {
                    rtn = VisionCalHelper.Instance.DetectUI(func, img, this.imageSet.imageSet.Roi[0].Shape);
                    Algorithms.Copy(img, this.imageSet.imageSet.Image);
                    if (rtn.State == VisionResultState.OK)
                    {
                        var    xyPt    = SystemEntiy.Instance[this.Module].XYPos;
                        PointF wroldPt = new PointF();
                        if (SystemEntiy.Instance[this.Module].WroldPt(camera, xyPt, rtn.Point, out wroldPt))
                        {
                            SystemEntiy.Instance[this.Module].XYGoPosTillStop(wroldPt);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("请绘制ROI");
            }
        }
Esempio n. 3
0
        public VisionResult GetResult(string imageFileName, PredictionResponse prediction)
        {
            var file   = new FileInfo(imageFileName);
            var img    = new Bitmap(file.FullName);
            var topBox = prediction.
                         Predictions.Where(i => i.TagName == "Box").OrderByDescending(i => i.Probability)
                         .FirstOrDefault();
            var buttons = GetButtonsInsideBox(topBox, prediction);
            var result  = new VisionResult()
            {
                Box     = FromPrediction(file.Extension, img, topBox),
                Buttons = buttons.Select(i => FromPrediction(file.Extension, img, i)).ToList()
            };

            return(null);
        }
Esempio n. 4
0
        public VisionResultTestTools(int startingFreeTiles = 0, int startingAllies = 0, int startingEnemies = 0)
        {
            _result = new VisionResult();

            for (int i = 0; i < startingFreeTiles; i++)
            {
                _result.FreeTiles.Add(new Tile(0, 0, null, null));
            }
            for (int i = 0; i < startingAllies; i++)
            {
                _result.Allies.Add(_factory.Create(EntityId.Headquarter, _fakedAllyClanInfo));
            }
            for (int i = 0; i < startingEnemies; i++)
            {
                _result.Enemies.Add(_factory.Create(EntityId.Headquarter, _fakedEnemyClanInfo));
            }
        }
        private VisionResult ProgramEditCtrl_DetectUI(string arg1, RectangleContour arg2, Module arg3)
        {
            VisionResult rtn = new VisionResult();

            if (this.bSet_CamLive)
            {
                this.bCamLive_Click(this, new EventArgs());
                Thread.Sleep(100);
            }

            using (VisionImage img = CameraDefine.Instance.Camera[arg3][Camera.Top].Snap())
            {
                rtn = VisionCalHelper.Instance.DetectUI(arg1, img, arg2);
                Algorithms.Copy(img, this.imageSet.imageSet.Image);
            }

            return(rtn);
        }
        private void bCalDown_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.cbDownVision.Text))
            {
                VisionResult rtn = DetectLabel?.Invoke(this.cbDownVision.Text, this.module.Module, this.selectNz3.SelectNz);

                if (rtn.State == VisionResultState.OK)
                {
                    var entiy = SystemEntiy.Instance[this.module.Module];
                    var curPt = SystemEntiy.Instance[this.module.Module].XYPos;
                    //PointF wroldPt = new PointF();
                    //SystemEntiy.Instance[this.module.Module].WroldPt(this.selectNz3.SelectNz,
                    //    SystemEntiy.Instance[this.module.Module].MachineConfig[this.selectNz3.SelectNz].RotateCamPoint,
                    //    rtn.Point, out wroldPt);
                    var wroldPt = SystemEntiy.Instance[this.module.Module].RotatePtDown(this.selectNz3.SelectNz, rtn.Point, -rtn.Angle);
                    entiy.XYGoPos(wroldPt);
                    entiy.RGoAngle(entiy.MachineAxis.R[(int)this.selectNz3.SelectNz].Pos - rtn.Angle, this.selectNz3.SelectNz);
                }
            }
        }
        /// <summary>
        /// Sends out a query to the computer vision api and validates the result
        /// </summary>
        /// <param name="attachment"></param>
        /// <returns></returns>
        private async Task <VisionResult> QueryComputerVisionApi(byte[] attachment)
        {
            var endpoint = "https://westeurope.api.cognitive.microsoft.com/vision/v1.0/analyze?visualFeatures=Categories,Description,Color,Faces&details=Celebrities&language=en";

            var imageBinaryContent = new ByteArrayContent(attachment);
            var multipartContent   = new MultipartFormDataContent {
                { imageBinaryContent, "image" }
            };

            var requestMessage = new HttpRequestMessage(HttpMethod.Post, endpoint)
            {
                Content = multipartContent
            };

            requestMessage.Headers.Add("Ocp-Apim-Subscription-Key", _configuration["computerVisionKey"]);

            _logger.LogDebug($"Posting to Computer Vision: {endpoint}");

            var response = await _httpClient.SendAsync(requestMessage);

            VisionResult result = null;

            var responseString = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                _logger.LogInformation($"Luis response: {responseString}");
                result = JsonConvert.DeserializeObject <VisionResult>(responseString);
            }
            else
            {
                _logger.LogInformation($"Ooops, could not query vision api: {response.StatusCode} {response.ReasonPhrase} {responseString}");
            }

            return(result);
        }
        private void bPasteTest_Click(object sender, EventArgs e)
        {
            if (this.cbDownVision.SelectedIndex < 0)
            {
                return;
            }

            var    entiy = SystemEntiy.Instance[this.module.Module];
            Nozzle nz    = this.selectNz3.SelectNz;
            // 记录要贴附的坐标
            PointF pasteXY    = entiy.XYPos;
            double pasteAngle = (double)this.numPasteAngle.Value;

            // Z轴到安全高度
            entiy.ZGoSafeTillStop();
            // 到拍照位
            entiy.XYGoPosTillStop(entiy.MachineConfig[nz].RotateCamPoint);
            // R角度到0
            entiy.RGoAngleTillStop(0, nz);

            Thread.Sleep(50);

            // 拍照
            VisionResult rtn = DetectLabel?.Invoke(this.cbDownVision.Text, this.module.Module, this.selectNz3.SelectNz);

            if (rtn.State == VisionResultState.OK)
            {
                PointF result = entiy.RotatePtDown(nz, rtn.Point, -rtn.Angle + pasteAngle);
                PointF offset = new PointF();
                offset.X = result.X - entiy.MachineConfig[nz].DownMarkPt.X;
                offset.Y = result.Y - entiy.MachineConfig[nz].DownMarkPt.Y;
                PointF realPt = new PointF();
                realPt.X = pasteXY.X + offset.X + entiy.MachineConfig[nz].NzToCam.X;
                realPt.Y = pasteXY.Y + offset.Y + entiy.MachineConfig[nz].NzToCam.Y;

                if (!this.cbCheck.Checked)
                {
                    realPt = entiy.GetPasteOffset(nz, pasteXY, realPt);
                }
                else
                {
                    this.upPt    = pasteXY;
                    this.pastePt = realPt;
                }

                entiy.RGoAngle(-rtn.Angle + pasteAngle, nz);
                entiy.XYGoPosTillStop(realPt);
                entiy.ZGoPaste(nz);
                Thread.Sleep(1000);
                entiy.MachineIO.VaccumSuck[(int)nz].SetIO(false);
                Thread.Sleep(100);
                entiy.MachineIO.VaccumPO[(int)nz].SetIO(true);
                Thread.Sleep(100);
                entiy.MachineIO.VaccumPO[(int)nz].SetIO(false);
                entiy.ZGoSafeTillStop();
                entiy.XYGoPosTillStop(pasteXY);
            }
            else
            {
                MessageBox.Show("Label 侦测失败!!");
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Check vision
        /// </summary>
        public VisionResult CheckVision()
        {
            VisionResult result     = new VisionResult();
            float        dist       = 0;
            SensorType   sensorType = SensorType.Inner;

            if (DevTools.Instance().Invisible || Player.Instance == null)
            {
                result.playerVisible = false;
            }
            else
            {
                bool visible = false;
                for (int i = 0; i <= 3; i++)
                {
                    Vector3 pos;
                    switch (i)
                    {
                    case 1:
                        pos = Player.Instance.GetFeetPos();
                        break;

                    case 2:
                        pos = Player.Instance.GetHeadPos();
                        break;

                    default:
                        pos = Player.Instance.GetTargetPos();
                        break;
                    }

                    visible            = CheckPoint(pos, out dist, out sensorType);
                    result.visionPoint = (VisionPoint)i;
                    if (visible)
                    {
                        break;
                    }
                }

                if (visible && Player.Instance.hiding)
                {
                    float hidingDist = (entity.GetState() is AIStateAggresion || entity.GetState() is AIStateCover ? hidingDistAggression : hidingDistAttention);
                    if (dist > hidingDist)
                    {
                        visible = false;
                    }
                }

                result.playerVisible = visible;
                result.sensorType    = sensorType;
            }

            GameObject[] points = GetAttentionPoints();
            if (points.Length > 0)
            {
                foreach (GameObject go in points)
                {
                    if (!go.activeSelf)
                    {
                        continue;
                    }

                    if (go.transform.IsChildOf(transform))
                    {
                        continue;
                    }

                    if (CheckPoint(go.transform.position, out dist, out sensorType))
                    {
                        if (sensorType == SensorType.Outer)
                        {
                            result.attentionPoint = go.transform;
                            break;
                        }
                    }
                }
            }

            points = GetFearPoints();
            if (points.Length > 0)
            {
                foreach (GameObject go in points)
                {
                    if (!go.activeSelf)
                    {
                        continue;
                    }

                    if (go.transform.IsChildOf(transform))
                    {
                        continue;
                    }

                    if (CheckPoint(go.transform.position, out dist, out sensorType))
                    {
                        if (sensorType == SensorType.Outer)
                        {
                            result.fearPoint = go.transform;
                            break;
                        }
                    }
                }
            }

            visionResult = result;
            return(visionResult);
        }
Esempio n. 10
0
 /// <summary>
 /// Reset vision result and vision pivot angle
 /// </summary>
 public void ResetVision()
 {
     visionPivot.eulerAngles = transform.eulerAngles;
     visionRot    = transform.eulerAngles;
     visionResult = new VisionResult();
 }