private async void Frame(ThreadPoolTimer timer) { if (cam.CameraStreamState != CameraStreamState.Streaming) { return; } if (!semaphore.Wait(0)) { return; } try { const BitmapPixelFormat InputPixelFormat = BitmapPixelFormat.Nv12; using (VideoFrame frame = new VideoFrame(InputPixelFormat, (int)properties.Width, (int)properties.Height)) { await cam.GetPreviewFrameAsync(frame); var faces = await tracker.ProcessNextFrameAsync(frame); var b = frame.SoftwareBitmap; Detected?.Invoke(this, Tuple.Create(faces, b.PixelWidth, b.PixelHeight)); } } finally { semaphore.Release(); } }
public int CompareDetected(Detected d1, Detected d2) { if (d1.IsValid() && d2.IsValid()) { if (d1.GetDistance() > d2.GetDistance()) { return(1); } else if (d1.GetDistance() < d2.GetDistance()) { return(-1); } else { return(0); } } else if (d1.IsValid() && !d2.IsValid()) { return(-1); } else if (!d1.IsValid() && d2.IsValid()) { return(1); } else { return(0); } }
public static bool IsActiveSuperAccount(string seller, string desc = null) { var isSuperAccount = false; string mainPart = TbNickHelper.GetMainPart(seller); if (seller == mainPart) { isSuperAccount = true; } else { var superAccounts = Auth.GetSuperAccounts(mainPart); var activeNicks = Detected.GetLatest5SecDetectedNicksNotNull(); foreach (var acc in superAccounts) { if (activeNicks.Contains(acc)) { isSuperAccount = true; break; } } } if (!isSuperAccount && !string.IsNullOrEmpty(desc)) { var msg = string.Format("【{0}】没有【{1}】的权限\r\n\r\n需要在电脑上登录【{2}】店铺的主账号或者特权子账号才能{1}!\r\n\r\n是否查看如何设置特权子账号?", seller, desc , mainPart); MsgBox.ShowTip(msg, showHelp => { if (showHelp) { } }, "提示"); } return(isSuperAccount); }
public void DidOutputMetadataObjects(AVCaptureMetadataOutput captureOutput, AVMetadataObject[] metadataObjects, AVCaptureConnection connection) { if (codeFrame is null || preview is null) { return; } if (metadataObjects.Length == 0) { codeFrame.Frame = CGRect.Empty; return; } var readableObject = metadataObjects[0] as AVMetadataMachineReadableCodeObject; if (readableObject.Type != AVMetadataObjectType.QRCode) { return; } var qrObject = preview.GetTransformedMetadataObject(readableObject); codeFrame.Frame = qrObject.Bounds; if (readableObject.StringValue is string value) { Detected?.Invoke(this, new BarcodeDetectedEventArgs(value)); } }
public void OnTriggerStay(Collider other) { if (!IsAnimalAi(other)) { return; } if (IsSelf(other)) { return; } var direction = other.transform.position - gameObject.transform.position; var angle = Vector3.Angle(direction, transform.forward); if (angle < 0.5 * FieldOfViewAngle) { RaycastHit ray; if (Physics.Raycast(transform.position, direction, out ray)) { var otherAnimal = other.GetComponentInParent <AiRig>(); var collidedAnimal = ray.collider.GetComponentInParent <AiRig>(); if (collidedAnimal == otherAnimal) { ReportDetection(other); return; } } } if (Detected.Contains(other)) { ReportUndetection(other); } }
private void RegisterEvent() { _eventDetectedCallback = (IntPtr trigger, IntPtr source, int streamId, IntPtr result, IntPtr _) => { Detected?.Invoke(this, CreateMovementDetectedEventArgs(result)); }; }
public void RevalidateDetected(GameObject detectedObject) { Detected detected = GetDetected(detectedObject); if (detected != null) { agent.GetComponent <Agent>().StartCoroutine(RevalidationTimer(detected, 5f)); } }
public void InvalidateDetected(GameObject detectedObject) { Detected detected = GetDetected(detectedObject); if (detected != null) { detected.status = false; } }
public void InvalidateDetected(GameObject detectedObject, float time) { Detected detected = GetDetected(detectedObject); if (detected != null) { detected.status = false; agent.GetComponent <Agent>().StartCoroutine(RevalidationTimer(detected, time)); } }
private static void OnTick(object state) { var lastInput = NativeUtils.GetLastInputTime(); var idleTime = Environment.TickCount - lastInput; if (idleTime >= _timeout && _lastTime < lastInput) { _lastTime = lastInput; Detected?.Invoke(null, EventArgs.Empty); } }
internal override void OnEventDetected(IntPtr trigger, IntPtr source, int streamId, IntPtr result, IntPtr _) { try { Detected?.Invoke(this, CreatePersonAppearanceChangedEventArgs(result)); } catch (Exception e) { MultimediaLog.Error(MediaVisionLog.Tag, "Failed to invoke Recognized event.", e); } }
/// <summary> /// Append a grid's Id to outputText /// </summary> /// <param name="whichOutput">which set of output panels to use</param> /// <param name="grid">detected grid to add</param> void addToOutput(string whichOutput, Detected grid) { StringBuilder addTo; if (!outputText.TryGetValue(whichOutput, out addTo)) { addTo = new StringBuilder('[' + blockName_fromProgram); outputText.Add(whichOutput, addTo); } addTo.Append(separator); addTo.Append(grid.entityId); }
public void RemoveDetected(GameObject detectedObject) { if (detectedObject != null) { Detected detected = GetDetected(detectedObject); detectables.Remove(detected); OnRemoved.Invoke(); } else { detectables.RemoveAll(detectable => detectable.detected == null); } }
public void Detected(bool disappearable = true) { Detected dt = Instantiate(detectObject, transform.position, Quaternion.identity).GetComponent <Detected>(); if (!disappearable) { dt.detectedColor = new Color(1f, 0f, 0f); dt.disappearable = false; } else { dt.detectedColor = new Color(1f, (maxSpeed - torpedoMoveSpeed) / (maxSpeed - minSpeed), 0f); } }
public void AddDetected(GameObject detected) { Detected detectable = new Detected(detected, detected.name, agent, comparator); if (!detectables.Contains(detectable)) { // Notify all listeners about detected OnDetected.Invoke(); // Listen when detected is destroyed / collected detected.GetComponent <IDestroyable>()?.RegisterOnDestroy(RemoveDetected); // Add detected to list of detectables detectables.Add(detectable); } }
// Return closes detected with valid status public GameObject GetSortedDetected() { if (IsAnyValidDetected()) { detectables.Sort(); Detected detected = detectables[0]; if (detected.detected != null) { return(detected.detected); } } return(null); }
public void OnTriggerExit(Collider other) { if (!IsAnimalAi(other)) { return; } if (IsSelf(other)) { return; } if (Detected.Contains(other)) { ReportUndetection(other); } }
private void TextAPIDetected() { try { if (WasDetected) { Log.Error("TextAPI sent the register event twice now! Please report to TextAPI author.", Log.PRINT_MESSAGE); return; } WasDetected = true; Detected?.Invoke(); } catch (Exception e) { Log.Error(e); } }
/// <summary> /// This function is called for every detected grid; put all your detected grid code here. /// </summary> /// <param name="grid">information about a grid</param> void handle_detectedGrid(Detected grid) { if (grid.relations == "Enemy") { addToOutput("Placeholder", grid); // this will add a grid to the output panels } // sound an alarm if an enemy is near if (useProximityAlarm && // proximity alarm is enabled !alarmIsSounding // have not found an enemy this run && grid.distance < 10000 && // closer than 10km grid.volume > 100 && // larger than 100m³ grid.seconds < 60 && // seen in the past minute (grid.relations == "Enemy")) // grid is enemy { soundProximityAlarm(); // sounds the alarm } }
public int CompareDetected(Detected d1, Detected d2) { if (d1.IsValid() && d2.IsValid()) { float d2Health = d2.GetAgent().Inventory.Health.Amount; float d1Health = d1.GetAgent().Inventory.Health.Amount; if (Mathf.Abs(d1Health - d2Health) > healthDifferenceThreshold) { return(d1Health < d2Health ? -1 : 1); } else { float d1Distance = d1.GetDistance(); float d2Distance = d2.GetDistance(); if (d1Distance < d2Distance) { return(-1); } else if (d1Distance > d2Distance) { return(1); } else { return(0); } } } else if (d1.IsValid() && !d2.IsValid()) { return(-1); } else if (!d1.IsValid() && d2.IsValid()) { return(1); } else { return(0); } }
private void Detect() { if (this.isDetecting) { return; } if (this.detectionTargetQueue.Count() == 0) { return; } var detectionTarget = this.detectionTargetQueue.Dequeue(); this.isDetecting = true; StartCoroutine( ProcessImage( this.objectDetector.IMAGE_SIZE, detectionTarget.CurrentTexture2D, picture => { StartCoroutine( this.objectDetector.Detect( picture, itemsDetected => { if (itemsDetected.Count > 0) { var detected = new Detected { HitPose = detectionTarget.HitPose, ItemsDetected = itemsDetected, }; this.detectedQueue.Enqueue(detected); } Resources.UnloadUnusedAssets(); this.isDetecting = false; } ) ); } ) ); }
// Update is called once per frame void Update() { RaycastHit hit; Vector3 forward = transform.TransformDirection(Vector3.forward) * 10; Debug.DrawRay(transform.position, forward, Color.green); /*if (Physics.Raycast(transform.position, forward, out hit)) * { * Detected d = hit.transform.GetComponent<Detected>(); * if (d) * { * d.detected(); * } * }else */if (Physics.SphereCast(transform.position, 0.5f, transform.forward, out hit, Mathf.Infinity)) { Detected d = hit.transform.GetComponent <Detected>(); if (d) { d.detected(); } } }
private Detected GetDetected(GameObject detectedObject) { Detected detected = detectables.FirstOrDefault(detectable => detectable.detected.Equals(detectedObject)); return(detected); }
/// <summary> /// Raises the <see cref="Detected"/> event. /// </summary> protected virtual void OnDetected() { Detected?.Invoke(this, EventArgs.Empty); }
void Slider(bool stop) { float leftZone = 2.274f; float rightZone = 2.5f; bar.SetActive(true); slider.SetActive(true); RectTransform rectT = bar.GetComponent <RectTransform> (); float leftBound = bar.transform.position.x - rectT.rect.width / 2; float rightBound = bar.transform.position.x + rectT.rect.width / 2; Vector3 start = bar.transform.position; Vector3 curPos = slider.transform.position; goalCounter(goal.goalCount); missCounter(missedCount); if (goal.goalCount < 5) { if (!stop) { if (slider.transform.position.x > leftBound && direction == Vector3.left) { curPos.x -= sliderSpeed * Time.deltaTime; slider.transform.position = curPos; } else if (slider.transform.position.x < leftBound) { direction = Vector3.right; slider.transform.position = new Vector3((leftBound + .003f), 0.3f, 0); } if (slider.transform.position.x < rightBound && direction == Vector3.right) { curPos.x += sliderSpeed * Time.deltaTime; slider.transform.position = curPos; } else if (slider.transform.position.x > rightBound) { direction = Vector3.left; slider.transform.position = new Vector3((rightBound - .003f), (.3f - .223103f), 0); } } else if (slider.GetComponent <RectTransform> ().position.x >= leftZone && slider.GetComponent <RectTransform> ().position.x <= rightZone) { if (Input.GetKeyDown(KeyCode.Space)) { successCount++; goal.goalCount++; Ding.Play(); /*if (successCount == 5) { * img4.SetActive (false); * img5.SetActive (true); * img6.SetActive (true); * }*/ //Time.timeScale = 0; sliderSpeed += .1f; gameMessage.text = "Steal the test answers: " + goal.goalCount.ToString() + "/" + successLimit.ToString(); } } else if (!(slider.GetComponent <RectTransform> ().position.x >= leftZone && slider.GetComponent <RectTransform> ().position.x <= rightZone)) { if (Input.GetKeyDown(KeyCode.Space)) { missedCount++; progressTimer.text = missedCount.ToString(); Error.Play(); } if (missedCount >= missedLimit) { ComputerController c = GameObject.Find("Prefect_0").GetComponent <ComputerController> (); c.isAlerted = true; goal.isAlerted = true; Detected.Play(); //activate GameObject for exclamation point over Smart Kid for (int i = 0; i < alerts.Length; i++) { SpriteRenderer sp = alerts [i].GetComponent <SpriteRenderer> (); sp.enabled = true; } } } } else { //goalCount = 0; miniEnable = false; bar.SetActive(false); slider.SetActive(false); Miss1.SetActive(false); Miss2.SetActive(false); Miss3.SetActive(false); } }
/// <summary> /// Append a grid's Id to outputText /// </summary> /// <param name="whichOutput">which set of output panels to use</param> /// <param name="grid">detected grid to add</param> void addToOutput(string whichOutput, Detected grid) { StringBuilder addTo; if (!outputText.TryGetValue(whichOutput, out addTo)) { addTo = new StringBuilder('[' + blockName_fromProgram); outputText.Add(whichOutput, addTo); } addTo.Append(separator); addTo.Append(grid.entityId); }
IEnumerator RevalidationTimer(Detected detectable, float revalidationTime) { yield return(new WaitForSeconds(revalidationTime)); detectable.status = true; }
/// <summary> /// This function is called for every detected grid; put all your detected grid code here. /// </summary> /// <param name="grid">information about a grid</param> void handle_detectedGrid(Detected grid) { if (grid.relations == "Enemy") addToOutput("Placeholder", grid); // this will add a grid to the output panels // sound an alarm if an enemy is near if (useProximityAlarm // proximity alarm is enabled && DateTime.UtcNow > nextAlarmTime // enough time has passed since last alarm && grid.distance < 10000 // closer than 10km && (grid.volume > 100 || grid.volume <= 0) // larger than 100m³ OR volume unknown && grid.seconds < 60 // seen in the past minute && grid.relations == "Enemy") // grid is enemy { soundProximityAlarm(); // sounds the alarm } }