private void ProcessAHM() { lock (mutex) { if (cameraMouseAssist == null) { return; } double ccMinProjSqdDist = 0.0; double ccTanSqdDist = 0.0; try { if (cameraMouseAssist != null && cameraMouseAssist.isReady()) { if (_AHMWeights == null || _AHMWeights.Length != this.numTemplates) { _AHMWeights = new double[numTemplates]; } float relX = 0.0f; float relY = 0.0f; if ((imagePoint.X >= obsSize / 2 + 10) && (imagePoint.Y >= obsSize / 2 + 10) && ((imagePoint.X + imagePoint.Y / 2 + 10) < imageSize.Width) && ((imagePoint.Y + obsSize / 2 + 10) < imageSize.Height)) { if (this._AHMRealtimeObs == null) { this._AHMRealtimeObs = CvImageWrapper.CreateImage(new CvSize(obsSize + 20, obsSize + 20), 8, 3); } if (this._AHMBackFeature == null) { this._AHMBackFeature = CvImageWrapper.CreateImage(new CvSize(obsSize, obsSize), 8, 3); } if (this._AHMCurFeature == null) { this._AHMCurFeature = CvImageWrapper.CreateImage(new CvSize(obsSize, obsSize), 8, 3); } _AHMRect.x = (int)imagePoint.X - obsSize / 2 - 10; _AHMRect.y = (int)imagePoint.Y - obsSize / 2 - 10;; _AHMRect.height = obsSize + 20; _AHMRect.width = obsSize + 20; _curFrame.cropSubImage(_AHMRect, this._AHMRealtimeObs); unsafe { int dx = 0, dy = 0; IntPtr pMinProjSqdDist = new IntPtr(&ccMinProjSqdDist); IntPtr pTanSqdDist = new IntPtr(&ccTanSqdDist); IntPtr pDx = new IntPtr(&dx); IntPtr pDy = new IntPtr(&dy); long newTicks = Environment.TickCount; if (newTicks - ticks > updateFrequency || updateFrequency == 0) { cameraMouseAssist.computeRelativePos(pMinProjSqdDist, pTanSqdDist, this._AHMRealtimeObs._rawPtr, pDx, pDy, _AHMWeights); if (CMSLogger.CanCreateLogEvent(true, false, false, "AHMLogRealtimeEvent")) { AHMLogRealtimeEvent lEvent = new AHMLogRealtimeEvent(); if (lEvent != null) { lEvent.ProjSqrdDist = (float)ccMinProjSqdDist; lEvent.TanSqrdDist = (float)ccTanSqdDist; CMSLogger.SendLogEvent(lEvent); } } imagePoint.X = imagePoint.X + dx; imagePoint.Y = imagePoint.Y + dy; _current_track_points[0].x = imagePoint.X; _current_track_points[0].y = imagePoint.Y; ticks = newTicks; AHMLogRealtimeFeatureImagesEvent realtimeEvent = null; if (CMSLogger.CanCreateLogEvent(true, true, false, "AHMLogRealtimeFeatureImagesEvent")) { realtimeEvent = new AHMLogRealtimeFeatureImagesEvent(); } if (this.extraDisplay || realtimeEvent != null) { prevExtraDisplay = true; cameraMouseAssist.retrieveBackFeature(this._AHMBackFeature._rawPtr); cameraMouseAssist.retrieveCurFeature(this._AHMCurFeature._rawPtr); extraImages[0] = _AHMBackFeature.GetBitMap().Clone() as Bitmap; extraImages[1] = _AHMCurFeature.GetBitMap().Clone() as Bitmap; extraImages[0].RotateFlip(RotateFlipType.RotateNoneFlipX); extraImages[1].RotateFlip(RotateFlipType.RotateNoneFlipX); if (realtimeEvent != null) { realtimeEvent.SetImages(extraImages[0], extraImages[1]); CMSLogger.SendLogEvent(realtimeEvent); } if (extraDisplay) { trackingSuiteAdapter.SendMessages(extraImages, new string[] { "Background", "Reconstruction" }); } //trackingSuiteAdapter.SendMessages(new Bitmap[]{}, new string[] { "Current Feature", "Background Feature" }); } else if (!extraDisplay && prevExtraDisplay) { prevExtraDisplay = false; trackingSuiteAdapter.SendMessages(null, null); } } } } } } catch (Exception e) { } } }
private void ProcessAHM() { lock (mutex) { if (cameraMouseAssists == null) { return; } double ccMinProjSqdDist = 0.0; double ccTanSqdDist = 0.0; try { List <Bitmap> images = null; if (showMessages) { images = new List <Bitmap>(); } long newTicks = Environment.TickCount; if (newTicks - ticks > updateFrequency || updateFrequency == 0) { ticks = newTicks; for (int i = 0; i < NumberOfTrackingPoints; i++) { AHMCameraMouseAssist cameraMouseAssist = cameraMouseAssists[i]; if (cameraMouseAssist == null) { continue; } if (cameraMouseAssist != null && cameraMouseAssist.isReady()) { if (_AHMWeights == null || _AHMWeights.Length != this.numTemplates) { _AHMWeights = new double[numTemplates]; } float relX = 0.0f; float relY = 0.0f; if ((this._current_track_points[i].x >= obsSize / 2 + 10) && (_current_track_points[i].y >= obsSize / 2 + 10) && ((_current_track_points[i].x + obsSize / 2 + 10) < imageSize.Width) && ((_current_track_points[i].y + obsSize / 2 + 10) < imageSize.Height)) { if (this._AHMRealtimeObs == null) { this._AHMRealtimeObs = CvImageWrapper.CreateImage(new CvSize(obsSize + 20, obsSize + 20), 8, 3); } if (this._AHMBackFeature == null) { this._AHMBackFeature = CvImageWrapper.CreateImage(new CvSize(obsSize, obsSize), 8, 3); } if (this._AHMCurFeature == null) { this._AHMCurFeature = CvImageWrapper.CreateImage(new CvSize(obsSize, obsSize), 8, 3); } _AHMRect.x = (int)_current_track_points[i].x - obsSize / 2 - 10; _AHMRect.y = (int)_current_track_points[i].y - obsSize / 2 - 10;; _AHMRect.height = obsSize + 20; _AHMRect.width = obsSize + 20; _curFrame.cropSubImage(_AHMRect, this._AHMRealtimeObs); unsafe { int dx = 0, dy = 0; IntPtr pMinProjSqdDist = new IntPtr(&ccMinProjSqdDist); IntPtr pTanSqdDist = new IntPtr(&ccTanSqdDist); IntPtr pDx = new IntPtr(&dx); IntPtr pDy = new IntPtr(&dy); cameraMouseAssist.computeRelativePos(pMinProjSqdDist, pTanSqdDist, this._AHMRealtimeObs._rawPtr, pDx, pDy, _AHMWeights); /* * if (CMSLogger.CanCreateLogEvent(true, false, false, "AHMLogRealtimeEvent")) * { * AHMLogRealtimeEvent lEvent = new AHMLogRealtimeEvent(); * if (lEvent != null) * { * lEvent.ProjSqrdDist = (float)ccMinProjSqdDist; * lEvent.TanSqrdDist = (float)ccTanSqdDist; * CMSLogger.SendLogEvent(lEvent); * } * }*/ _current_track_points[i].x = _current_track_points[i].x + dx; _current_track_points[i].y = _current_track_points[i].y + dy; if (i == 0) { imagePoint.X = _current_track_points[0].x; imagePoint.Y = _current_track_points[0].y; } else { eyeImagePoints[i - 1].X = (int)_current_track_points[i].x; eyeImagePoints[i - 1].Y = (int)_current_track_points[i].y; } if (showMessages) { cameraMouseAssist.retrieveBackFeature(this._AHMBackFeature._rawPtr); cameraMouseAssist.retrieveCurFeature(this._AHMCurFeature._rawPtr); images.Add(_AHMBackFeature.GetBitMap().Clone() as Bitmap); images.Add(_AHMCurFeature.GetBitMap().Clone() as Bitmap); } /* * AHMLogRealtimeFeatureImagesEvent realtimeEvent = null; * if (CMSLogger.CanCreateLogEvent(true, true, false, "AHMLogRealtimeFeatureImagesEvent")) * { * realtimeEvent = new AHMLogRealtimeFeatureImagesEvent(); * } * if (realtimeEvent != null) * { * cameraMouseAssist.retrieveBackFeature(this._AHMBackFeature._rawPtr); * cameraMouseAssist.retrieveCurFeature(this._AHMCurFeature._rawPtr); * * extraImages[0] = _AHMBackFeature.GetBitMap().Clone() as Bitmap; * extraImages[1] = _AHMCurFeature.GetBitMap().Clone() as Bitmap; * * extraImages[0].RotateFlip(RotateFlipType.RotateNoneFlipX); * extraImages[1].RotateFlip(RotateFlipType.RotateNoneFlipX); * * realtimeEvent.SetImages(extraImages[0], extraImages[1]); * CMSLogger.SendLogEvent(realtimeEvent); * }*/ } } } } } if (showMessages && images.Count > 0) { trackingSuiteAdapter.SendMessages(images.ToArray(), new string[] { "Left Back", "Left Cur", "Right Back", "Right Cur", "Mouth Back", "Mouth Cur" }); } } catch (Exception e) { } } }