public void AddObject(PhysicsObj obj) { readerWriterLockSlim.EnterWriteLock(); try { // check for existing obj? ObjectList.Add(obj); NumObjects++; if (obj.ID == 0 || obj.Parent != null || obj.State.HasFlag(PhysicsState.Hidden) || VoyeurTable == null) { return; } foreach (var voyeur_id in VoyeurTable) { if (voyeur_id != obj.ID && voyeur_id != 0) { var voyeur = obj.GetObjectA(voyeur_id); if (voyeur == null) { continue; } var info = new DetectionInfo(obj.ID, DetectionType.EnteredDetection); voyeur.receive_detection_update(info); } } } finally { readerWriterLockSlim.ExitWriteLock(); } }
public void update_all_voyeur(PhysicsObj obj, DetectionType type, bool checkDetection = true) { if (obj.ID == 0 || obj.Parent != null || VoyeurTable == null) { return; } if (obj.State.HasFlag(PhysicsState.Hidden) && (checkDetection ? type == DetectionType.EnteredDetection : true)) { return; } foreach (var voyeur_id in VoyeurTable) { if (voyeur_id != obj.ID && voyeur_id != 0) { var voyeur = obj.GetObjectA(voyeur_id); if (voyeur == null) { continue; } var info = new DetectionInfo(obj.ID, type); voyeur.receive_detection_update(info); } } }
private void timerFaceDetectionProcess_tick(object sender, EventArgs e) { if (SettingsViewModel.IsShowDetectionFacePreview && _videoCaptureManager.IsCaptureInProgress && _timerFaceDetectionProcess.IsEnabled) { DetectFace(); } else { DetectionInfo = new DetectionInfo(); Dispatcher.CurrentDispatcher.Invoke(() => FaceDetectionImageSource = null); } }
public void LoadDetectionInfo(DetectionInfo detectionInfo) { info = detectionInfo; AddDialect(); AddSmb2TransportSupport(); resultItemMapList.Add(dialectsItems); resultItemMapList.Add(smbdItems); ResultMapList.ItemsSource = resultItemMapList; }
private void StartOrStopFaceDetection() { DetectionInfo = new DetectionInfo(); if (_timerFaceDetectionProcess.IsEnabled) { _timerFaceDetectionProcess.Stop(); Dispatcher.CurrentDispatcher.Invoke(() => FaceDetectionImageSource = null); } else { _timerFaceDetectionProcess.Start(); } }
private void StartOrStopCapture() { DetectionInfo = new DetectionInfo(); if (_videoCaptureManager.IsCaptureInProgress) { _videoCaptureManager.StopCapture(); Dispatcher.CurrentDispatcher.Invoke(() => GrabImageSource = null); } else { _videoCaptureManager.StartCapture(); } }
private static void Apply(Chain chain, DetectionInfo detection) { int index = detection.index; // Undo relative rotation chain.GetBone(index).Rotate(detection.relative); // Rotate back but only by detection.angle degrees Vector3 axis = Quat.GetAxis(detection.relative); chain.GetBone(index).Rotate(Quaternion.AngleAxis(detection.angle, axis)); // Keep the chain linked for (int i = index + 1; i < chain.BoneCount; i++) { chain.GetBone(i).MoveTo(chain.GetBone(i - 1).Tip.Position); } }
/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public HomeViewModel(ICustomDialogService dialogService, SettingsViewModel settingsViewModel) { _dialogService = dialogService; _videoCaptureManager = new VideoCaptureManager(CameraId); _videoCaptureManager.NewImageComplete += videoCaptureManager_OnNewImageComplete; _iotHubPublisher = new IotHubPublisher(IotHubHostName, DeviceId, SharedAccessKey); _faceDetectionConfigFilePath = Path.Combine(_configFileDirectory, _faceDetectionConfig); _eyeDetectionConfigFilePath = Path.Combine(_configFileDirectory, _eyeDetectionConfig); _timerFaceDetectionProcess = new DispatcherTimer(); _timerFaceDetectionProcess.Tick += new EventHandler(timerFaceDetectionProcess_tick); _timerFaceDetectionProcess.Interval = new TimeSpan(0, 0, 0, Properties.Settings.Default.FaceDetectionProcessInSeconds, 0); SettingsViewModel = settingsViewModel; DetectionMode = DetectionModeEnum.OpenCV; DetectionInfo = new DetectionInfo(); }
private static DetectionInfo Detect(Chain chain, int startingJoint = 0) { IList <Joint> joints = chain.GetJoints(); for (int i = startingJoint; i < joints.Count; i++) { if (!joints[i].HasConstraint) { continue; } Quaternion relative = i > 0 ? Quat.Relative(joints[i].Orientation, joints[i - 1].Orientation) : Quat.Relative(joints[i].Orientation, joints[i].RestOrientation); float angle = Quat.GetAngle(relative); // [-180, 180) float min = -Mathf.Abs(joints[i].MaxAngleCW); // (-180, 0] float max = Mathf.Abs(joints[i].MaxAngleCCW); // [0, 180) //Debug.Log("ANGLE: " + angle + " MIN: " + min + " MAX: " + max); DetectionInfo di = new DetectionInfo() { index = i, relative = relative }; if (angle < min) { //Debug.Log("Angle BELOW the minimum"); di.angle = min; return(di); } else if (angle > max) { //Debug.Log("Angle ABOVE the maximum"); di.angle = max; return(di); } } return(null); }
private void vtButton_Click(object sender, EventArgs e) { string key = vtKeyTextBox.Text; if (string.IsNullOrEmpty(key) || key.Length != 64) { MessageBox.Show("Please insert correct Virus Total API key"); return; } DetectionInfo dt = new DetectionInfo(lastFilePath); VirusTotal vt = new VirusTotal(key); JsonParser jp = new JsonParser(); string report = vt.GetFileReport(dt.getMD5()); string comments = vt.GetFileComments(dt.getMD5()); vtResult = jp.ParseResults(JObject.Parse(report)); vtComments = jp.ParseComments(JObject.Parse(comments)); var name = Path.GetTempFileName(); File.WriteAllText(name + ".txt", vtResult + "\n\n" + vtComments); System.Diagnostics.Process.Start(name + ".txt"); }
public DetectionInfo DetectOpponents(float currentDirectionX) { float observeAroundDistance = (detectionInfo.isAware ? observerDistanceFar : observerDistanceNear); DetectionInfo currentDetection = ObserveAround(observeAroundDistance); if (currentDetection.distance < 0) { // Player near around not detected currentDetection = ObserveDirection(observerDistanceFar, currentDirectionX, 0); } if (currentDetection.distance < 0) { // Player not be found. Aware is false again detectionInfo.isAware = false; } else { detectionInfo.isAware = true; } return(currentDetection); }
protected override void ReadEntitiesInRange() { m_entitiesInRange.Clear(); m_hits.Clear(); MyPhysics.CastRay(m_origin, FrontPoint, m_hits, MyPhysics.ObjectDetectionCollisionLayer); DetectionInfo value = new DetectionInfo(); foreach (var hit in m_hits) { var hitInfo = hit.HkHitInfo; if (hitInfo.Body == null) continue; var entity = hitInfo.GetHitEntity(); if (entity == null) continue; var rootEntity = entity.GetTopMostParent(); if (!IgnoredEntities.Contains(rootEntity)) { Vector3D detectionPoint = hit.Position; MyCubeGrid grid = rootEntity as MyCubeGrid; if (grid != null) { if (!GetShapeCenter(hitInfo.Body.GetShape(), hitInfo.GetShapeKey(0), grid, ref detectionPoint)) { if (grid.GridSizeEnum == Common.ObjectBuilders.MyCubeSize.Large) detectionPoint += hit.HkHitInfo.Normal * -0.08f; else detectionPoint += hit.HkHitInfo.Normal * -0.02f; } } if (m_entitiesInRange.TryGetValue(rootEntity.EntityId, out value)) { var oldDistance = Vector3.DistanceSquared(value.DetectionPoint, m_origin); var newDistance = Vector3.DistanceSquared(detectionPoint, m_origin); if (oldDistance > newDistance) m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity as MyEntity, detectionPoint); } else { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity as MyEntity, detectionPoint); } } } LineD line = new LineD(m_origin, FrontPoint); using (m_raycastResults.GetClearToken()) { MyGamePruningStructure.GetAllEntitiesInRay(ref line, m_raycastResults); foreach (var segment in m_raycastResults) { if (segment.Element == null) continue; var rootEntity = segment.Element.GetTopMostParent(); if (!IgnoredEntities.Contains(rootEntity)) { if (!(segment.Element is MyCubeBlock)) continue; Vector3D point = new Vector3D(); MyCubeBlock block = segment.Element as MyCubeBlock; if (block.SlimBlock.HasPhysics == false) { Vector3D localOrigin = Vector3D.Transform(m_origin, block.PositionComp.WorldMatrixNormalizedInv); Vector3D localFront = Vector3D.Transform(FrontPoint, block.PositionComp.WorldMatrixNormalizedInv); Ray ray = new Ray(localOrigin, Vector3.Normalize(localFront - localOrigin)); //MyRenderProxy.DebugDrawAABB(block.WorldAABB, Color.Red.ToVector3(), 1.0f, 1.0f, false); float? dist = ray.Intersects(block.PositionComp.LocalAABB); dist += 0.01f; if (dist.HasValue && dist <= m_rayLength) point = m_origin + Vector3D.Normalize(FrontPoint - m_origin) * dist.Value; else continue; } else { // This entity was caught by Havok raycast continue; } if (m_entitiesInRange.TryGetValue(rootEntity.EntityId, out value)) { if (Vector3.DistanceSquared(value.DetectionPoint, m_origin) > Vector3.DistanceSquared(point, m_origin)) m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity, point); } else { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity, point); } } } } }
public SMBDValueDetector() { detectionInfo = new DetectionInfo(); }
private async void DetectFace() { try { if (!_videoCaptureManager.IsCaptureInProgress) { return; } var snaphsot = _videoCaptureManager.TakeSnapshot(); if (snaphsot == null) { return; } DetectionInfo detectionInfo = null; switch (DetectionMode) { case DetectionModeEnum.OpenCV: detectionInfo = DetectFacesOpenCV(snaphsot); break; case DetectionModeEnum.Bing: detectionInfo = await DetectFacesBing(snaphsot); break; } if (detectionInfo != null) { DetectionInfo = detectionInfo; if (SettingsViewModel.IsShowDetectionFacePreview) { var detectionImage = detectionInfo.Image; foreach (var faceRectangle in detectionInfo.Rectangles) { detectionImage.Draw(faceRectangle, new Bgr(0, double.MaxValue, 0), 3); } Dispatcher.CurrentDispatcher.Invoke(() => FaceDetectionImageSource = BitmapSourceConverter.ToBitmapSource(detectionImage)); } else { Dispatcher.CurrentDispatcher.Invoke(() => FaceDetectionImageSource = null); } if (SettingsViewModel.IsSendToIoTHub) { DeviceNotification facesAnalysis = new DeviceNotification(DeviceId, detectionInfo.Rectangles.Count, detectionInfo.MaleCount, detectionInfo.FemaleCount, detectionInfo.SmileCount, detectionInfo.SunGlassesCount, detectionInfo.ReadingGlassesCount, detectionInfo.AgeAverage, detectionInfo.EmotionHappyCount, detectionInfo.EmotionNeutralCount, detectionInfo.EmotionDisgustCount, detectionInfo.EmotionAngerCount, detectionInfo.HappyRatio, detectionInfo.HearyCount); _iotHubPublisher.SendDataAsync(facesAnalysis); } } else { DetectionInfo = new DetectionInfo(); } } catch (Exception ex) { App.Log.Error(ex.FlattenException()); } }
protected override void ReadEntitiesInRange() { m_entitiesInRange.Clear(); m_hits.Clear(); MyPhysics.CastRay(m_origin, FrontPoint, m_hits, MyPhysics.CollisionLayers.ObjectDetectionCollisionLayer); DetectionInfo value = new DetectionInfo(); bool encounteredModel = false; foreach (var hit in m_hits) { var hitInfo = hit.HkHitInfo; if (hitInfo.Body == null) continue; var entity = hitInfo.GetHitEntity(); if (entity == null) continue; var rootEntity = entity.GetTopMostParent(); if (!IgnoredEntities.Contains(rootEntity)) { Vector3D detectionPoint = hit.Position; MyCubeGrid grid = rootEntity as MyCubeGrid; if (grid != null) { var shape = hitInfo.Body.GetShape(); int shapeIdx = 0; if(grid.Physics.IsWelded || grid.GetPhysicsBody().WeldInfo.Children.Count != 0) { if (shape.IsContainer()) { shape = shape.GetContainer().GetShape(hitInfo.GetShapeKey(0)); shapeIdx = 1; } } if (!GetShapeCenter(shape, hitInfo.GetShapeKey(shapeIdx), grid, ref detectionPoint)) { if (grid.GridSizeEnum == MyCubeSize.Large) detectionPoint += hit.HkHitInfo.Normal * -0.08f; else detectionPoint += hit.HkHitInfo.Normal * -0.02f; } } if (m_entitiesInRange.TryGetValue(rootEntity.EntityId, out value)) { var oldDistance = Vector3.DistanceSquared(value.DetectionPoint, m_origin); var newDistance = Vector3.DistanceSquared(detectionPoint, m_origin); if (oldDistance > newDistance) m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity as MyEntity, detectionPoint); } else { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity as MyEntity, detectionPoint); } if (entity is MyEnvironmentSector && !encounteredModel) { var sector = entity as MyEnvironmentSector; var shapekey = hitInfo.GetShapeKey(0); var itemId = sector.GetItemFromShapeKey(shapekey); if (sector.DataView.Items[itemId].ModelIndex < 0) continue; encounteredModel = true; m_entitiesInRange[entity.EntityId] = new DetectionInfo(sector, detectionPoint, itemId); } } } LineD line = new LineD(m_origin, FrontPoint); using (m_raycastResults.GetClearToken()) { MyGamePruningStructure.GetAllEntitiesInRay(ref line, m_raycastResults); foreach (var segment in m_raycastResults) { if (segment.Element == null) continue; var rootEntity = segment.Element.GetTopMostParent(); if (!IgnoredEntities.Contains(rootEntity)) { MyCubeBlock block = segment.Element as MyCubeBlock; if (block == null) continue; Vector3D point = new Vector3D(); if (block.SlimBlock.HasPhysics == false) { MatrixD blockWorldMatrixNormalizedInv = block.PositionComp.WorldMatrixNormalizedInv; Vector3D localOrigin = Vector3D.Transform(m_origin, ref blockWorldMatrixNormalizedInv); Vector3D localFront = Vector3D.Transform(FrontPoint, ref blockWorldMatrixNormalizedInv); Ray ray = new Ray(localOrigin, Vector3.Normalize(localFront - localOrigin)); //MyRenderProxy.DebugDrawAABB(block.WorldAABB, Color.Red.ToVector3(), 1.0f, 1.0f, false); float? dist = ray.Intersects(block.PositionComp.LocalAABB); dist += 0.01f; if (dist.HasValue && dist <= m_rayLength) point = m_origin + Vector3D.Normalize(FrontPoint - m_origin) * dist.Value; else continue; } else { // This entity was caught by Havok raycast continue; } if (m_entitiesInRange.TryGetValue(rootEntity.EntityId, out value)) { if (Vector3.DistanceSquared(value.DetectionPoint, m_origin) > Vector3.DistanceSquared(point, m_origin)) m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity, point); } else { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity, point); } } } } }
/// <summary> /// generally manage input and do all the stuff /// </summary> private void button1_Click(object sender, EventArgs e) { lastFilePath = ""; vtResult = "none"; OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { var fi = new FileInfo(ofd.FileName); if (fi.Length < MINIMUM_FILE_SIZE) { MessageBox.Show($"File is too small! Minimum size of a file is {MINIMUM_FILE_SIZE} bytes!"); return; } else if (fi.Length > MAXIMUM_FILE_SIZE) { MessageBox.Show($"File is too big! Maximum size of a file is {MAXIMUM_FILE_SIZE} bytes!"); return; } lastFilePath = ofd.FileName; saveButton.Enabled = true; vtButton.Enabled = true; List <double> entropy; var fileName = ofd.FileName; bool res = int.TryParse(textBox1.Text, out int temp); if (!res) { MessageBox.Show("Incorrect number or no sample number included, using default value of 256.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } int samples = res ? temp : 256; if (samples < 64) { samples = 64; } if (samples > fi.Length) { samples = 256; } var ent = new EntropyCounter(fileName, samples); entropy = ent.GetFileEntropy(); var charter = new Charting(entropy); pictureBox1.Image = charter.GetBitmap(); DetectionInfo detectionInfo = new DetectionInfo(ofd.FileName); md5label.Text = detectionInfo.getMD5(); sha1label.Text = detectionInfo.getSHA1(); sha256label.Text = detectionInfo.getSHA256(); sha512label.Text = detectionInfo.getSHA512(); locationLabel.Text = ofd.FileName; double sum = 0; entropy.ForEach(x => sum += x); avgEntLabel.Text = (sum / samples).ToString(); fileSizeLabel.Text = new FileInfo(ofd.FileName).Length.ToString(); fileTypesLabel.Text = detectionInfo.Detect(); } else { MessageBox.Show("No file chosen!"); vtButton.Enabled = false; saveButton.Enabled = false; } }
protected override void ReadEntitiesInRange() { m_entitiesInRange.Clear(); m_hits.Clear(); MyPhysics.CastRay(m_origin, FrontPoint, m_hits, MyPhysics.ObjectDetectionCollisionLayer); DetectionInfo value = new DetectionInfo(); foreach (var hit in m_hits) { var hitInfo = hit.HkHitInfo; if (hitInfo.Body == null) { continue; } var entity = hitInfo.GetHitEntity(); if (entity == null) { continue; } var rootEntity = entity.GetTopMostParent(); if (!IgnoredEntities.Contains(rootEntity)) { Vector3D detectionPoint = hit.Position; MyCubeGrid grid = rootEntity as MyCubeGrid; if (grid != null) { var shape = hitInfo.Body.GetShape(); int shapeIdx = 0; if (grid.Physics.IsWelded || grid.Physics.WeldInfo.Children.Count != 0) { if (shape.IsContainer()) { shape = shape.GetContainer().GetShape(hitInfo.GetShapeKey(0)); shapeIdx = 1; } } if (!GetShapeCenter(shape, hitInfo.GetShapeKey(shapeIdx), grid, ref detectionPoint)) { if (grid.GridSizeEnum == Common.ObjectBuilders.MyCubeSize.Large) { detectionPoint += hit.HkHitInfo.Normal * -0.08f; } else { detectionPoint += hit.HkHitInfo.Normal * -0.02f; } } } if (m_entitiesInRange.TryGetValue(rootEntity.EntityId, out value)) { var oldDistance = Vector3.DistanceSquared(value.DetectionPoint, m_origin); var newDistance = Vector3.DistanceSquared(detectionPoint, m_origin); if (oldDistance > newDistance) { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity as MyEntity, detectionPoint); } } else { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity as MyEntity, detectionPoint); } } } LineD line = new LineD(m_origin, FrontPoint); using (m_raycastResults.GetClearToken()) { MyGamePruningStructure.GetAllEntitiesInRay(ref line, m_raycastResults); foreach (var segment in m_raycastResults) { if (segment.Element == null) { continue; } var rootEntity = segment.Element.GetTopMostParent(); if (!IgnoredEntities.Contains(rootEntity)) { MyCubeBlock block = segment.Element as MyCubeBlock; if (block == null) { continue; } Vector3D point = new Vector3D(); if (block.SlimBlock.HasPhysics == false) { MatrixD blockWorldMatrixNormalizedInv = block.PositionComp.WorldMatrixNormalizedInv; Vector3D localOrigin = Vector3D.Transform(m_origin, ref blockWorldMatrixNormalizedInv); Vector3D localFront = Vector3D.Transform(FrontPoint, ref blockWorldMatrixNormalizedInv); Ray ray = new Ray(localOrigin, Vector3.Normalize(localFront - localOrigin)); //MyRenderProxy.DebugDrawAABB(block.WorldAABB, Color.Red.ToVector3(), 1.0f, 1.0f, false); float?dist = ray.Intersects(block.PositionComp.LocalAABB); dist += 0.01f; if (dist.HasValue && dist <= m_rayLength) { point = m_origin + Vector3D.Normalize(FrontPoint - m_origin) * dist.Value; } else { continue; } } else { // This entity was caught by Havok raycast continue; } if (m_entitiesInRange.TryGetValue(rootEntity.EntityId, out value)) { if (Vector3.DistanceSquared(value.DetectionPoint, m_origin) > Vector3.DistanceSquared(point, m_origin)) { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity, point); } } else { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity, point); } } } } }
private void ProcessFrame(byte[] pData, int lWidth, int lHeight, int bTopDown, int lBitCount) { try { _threading = true; Frame frame = new Frame(); frame.Width = lWidth; frame.Height = lHeight; frame.Orientation = FrameOrientation.LandscapeLeft; frame.ImageFormat = lBitCount == 24 ? ImageFormat.BGR888 : ImageFormat.BGR8888; frame.ImageData = pData; if (bTopDown != 1) { frame.Height *= -1; } DetectionInfo detectionInfo = _scanner.ScanFrame(frame); if (detectionInfo.Status == ScanFrameStatus.NumbersFound) { CreditCard creditCard = new CreditCard(detectionInfo); StringBuilder sb = new StringBuilder(); switch (creditCard.CardType) { case (CardType.AmericanExpress): sb.Append("Amex Card#: "); break; case (CardType.DinersClub): sb.Append("DinersClub Card#: "); break; case (CardType.Discover): sb.Append("Discover Card#: "); break; case (CardType.JCB): sb.Append("JCB Card#: "); break; case (CardType.MasterCard): sb.Append("MasterCard Card#: "); break; case (CardType.Visa): sb.Append("VISA Card#: "); break; case (CardType.Maestro): sb.Append("Discover Card#: "); break; default: sb.Append("Unknown Card#: "); break; } for (int i = 0; i < creditCard.CardNumber.Length; i++) { if (creditCard.CardNumber.Length == 16) { if ((i % 4) == 0) { sb.Append(" "); } } else { // American Express cards have 15 digits in the following format: // XXXX XXXXXX XXXXX if (i == 4) { sb.Append(" "); } else if (i == 10) { sb.Append(" "); } } sb.Append(creditCard.CardNumber[i]); } _scanner.Reset(); _recognizedCardNumber = sb.ToString(); _isRecognized = true; } else { _isRecognized = false; } _threading = false; } catch (Exception ex) { Console.WriteLine(ex.Message); } }