void Update() { int cantFind = 0; IEnumerator iter = positions.GetEnumerator(); while (iter.MoveNext()) { GameObject tmp = iter.Current as GameObject; Detecter tmp1 = tmp.GetComponent <Detecter>(); if (tmp1.is_fined) { Level = int.Parse(tmp.name); cantFind += 1; } } if (cantFind != 0) { transform.position = Vector3.Lerp(transform.position, positions[Level].transform.position, Time.deltaTime); lookPlayer = false; } else if (cantFind == 0) { lookPlayer = true; } if (lookPlayer) { transform.position = Vector3.Lerp(transform.position, player.position + offset, Time.deltaTime * 10); } }
public Result Classify(List <Vector2> positions, float deltaTime, bool isEnd, List <SmartPhoneTouchReciever> hitObjects) { var detecter = new Detecter(); var selector = new RecieverSelector(); // collect data Detecter.RESULT tapResult = detecter.IsTap(positions, deltaTime, isEnd); Detecter.RESULT flickResult = detecter.IsFlick(positions, deltaTime, isEnd); Detecter.RESULT longTouchResult = detecter.IsLongTouch(positions, deltaTime, isEnd); int tapIndex = selector.GetRecieverIndex(hitObjects, SmartPhoneTouchMode.Tap); int flickIndex = selector.GetRecieverIndex(hitObjects, SmartPhoneTouchMode.Flick); int longTouchIndex = selector.GetRecieverIndex(hitObjects, SmartPhoneTouchMode.LongTouch); if (tapIndex == -1) { tapResult = Detecter.RESULT.NO; } if (flickIndex == -1) { flickResult = Detecter.RESULT.NO; } if (longTouchIndex == -1) { longTouchResult = Detecter.RESULT.NO; } // classify if (longTouchResult == Detecter.RESULT.YES) { return(new Result(longTouchIndex, SmartPhoneTouchMode.LongTouch)); } if (flickResult == Detecter.RESULT.YES) { return(new Result(flickIndex, SmartPhoneTouchMode.Flick)); } if (tapResult == Detecter.RESULT.YES) { return(new Result(tapIndex, SmartPhoneTouchMode.Tap)); } if (longTouchResult == Detecter.RESULT.UNkNOWN) { if (tapResult == Detecter.RESULT.NO && flickResult == Detecter.RESULT.NO) { return(new Result(longTouchIndex, SmartPhoneTouchMode.LongTouch)); } } return(new Result(-1, SmartPhoneTouchMode.None)); }
private void OnEnable() { _player = GetComponent <PlayerProperty>(); _playerShotter = GetComponent <PlayerShot>(); _rig2D = GetComponent <Rigidbody2D>(); _trigger = new GameObject("Aim Detecter").AddComponent <CircleCollider2D>(); _trigger.transform.parent = transform; _trigger.transform.position = transform.position; _trigger.radius = _player.DetectRadius; _trigger.gameObject.layer = LayerMask.NameToLayer("Background"); _trigger.isTrigger = true; _detecter = _trigger.gameObject.AddComponent <Detecter>(); _playerShotter.enabled = false; }
private async void ScanObject() { while (true) { string[] fileArray = Directory.GetFiles(LocalSetting.m_strRecordSavePath, "*.mp4"); if (fileArray.Length == 0 || !IsScan) { Thread.Sleep(7000); } else { Detecter detecter = new Detecter(); for (int i = 0; i < fileArray.Length; i++) { var capture = new VideoCapture(fileArray[i]); try { var thamSo = CommonFunc.GetThamSoTuFileName(fileArray[i]); var totalFrames = capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameCount); double currentFrame = 0; double fps = capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.Fps); double nextFrames = fps / 2; double OneFPS = 1000 / fps; while (currentFrame <= totalFrames) { capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.PosFrames, currentFrame); if (currentFrame > totalFrames) { currentFrame = totalFrames; } else { currentFrame += nextFrames; } Mat m = new Mat(); capture.Read(m); if (!m.IsEmpty) { var inputImage = m.ToImage <Bgr, byte>(); int heightOfObject; if (detecter.DetectObject(inputImage, out heightOfObject)) { var thoiDiemLoi = thamSo.ThoiGianBatDauLuuVideo.AddSeconds(currentFrame * OneFPS / 1000); var viTriDiVatTrenAnh = Utilities.DoCao1KhungHinhThucTe * heightOfObject / inputImage.Height; var viTriLoi = (thoiDiemLoi - thamSo.ThoiGianBatDauCuon).TotalSeconds * Utilities.VanToc + viTriDiVatTrenAnh; if (viTriLoi - ViTriLoiMoiNhat >= Utilities.DoCao1KhungHinhThucTe) { ViTriLoiMoiNhat = viTriLoi; DSDiVat.Add(new DiVat() { Loi = DSDiVat.Count + 1, ThoiGianLoi = thoiDiemLoi, ViTriLoi = viTriLoi, Cuon = thamSo.TenCuon, Image = CommonFunc.ResizeImage(CommonFunc.ConvertImageToByte(inputImage.Bitmap), 500) }); this.Invoke(new Action(() => { bsDiVat.ResetBindings(false); DemLoi(); })); pictureBox1.Image = inputImage.Bitmap; } } else { inputImage.Dispose(); } await Task.Delay(100); } else { break; } } capture.Dispose(); //chuyển những file video đã được scan sang thư mục scanned string fileName = Path.GetFileName(fileArray[i]); File.Copy(fileArray[i], LocalSetting.m_strScannedPath + fileName); File.Delete(fileArray[i]); } catch (Exception ex) { throw ex; } } } } }