public override void Init(Size[] imageSizes) { Clean(); _flowflags |= CMSConstants.CV_LKFLOW_PYR_A_READY; validTrackPoints = false; _pwinsz = new CvSize(10, 10); _status = new byte[NumberOfTrackingPoints]; imageSize.Width = imageSizes[0].Width; imageSize.Height = imageSizes[0].Height; _last_track_points = new CvPoint2D32f[NumberOfTrackingPoints]; _current_track_points = new CvPoint2D32f[NumberOfTrackingPoints]; _criteria = new CvTermCriteria(CMSConstants.CV_TERMCRIT_ITER | CMSConstants.CV_TERMCRIT_EPS, 20, 0.03); _curFrame = CvImageWrapper.CreateImage(imageSize, PixelDepth, PixelColorChannels); _grey = CvImageWrapper.CreateImage(imageSize, PixelDepth, PixelChannels); _prev_grey = CvImageWrapper.CreateImage(imageSize, PixelDepth, PixelChannels); _pyramid = CvImageWrapper.CreateImage(imageSize, PixelDepth, PixelChannels); _prev_pyramid = CvImageWrapper.CreateImage(imageSize, PixelDepth, PixelChannels); _swap_temp = CvImageWrapper.CreateImage(imageSize, PixelDepth, PixelChannels); eyeLocator = new EyeLocator(EyeLocationImageCount); eyeLocator.Reset(); eyeImagePoints = new PointF[2]; CMSTrackingSuiteAdapter.SendMessage(InitMessage); }
private void InitStandard(int imageWidth, int imageHeight) { lock (mutex) { _flowflags |= CMSConstants.CV_LKFLOW_PYR_A_READY; //validTrackPoint = false; _pwinsz = new CvSize(10, 10); _status = new byte[1]; imageSize.Width = imageWidth; imageSize.Height = imageHeight; _last_track_points = new CvPoint2D32f[1]; _current_track_points = new CvPoint2D32f[1]; _criteria = new CvTermCriteria(CMSConstants.CV_TERMCRIT_ITER | CMSConstants.CV_TERMCRIT_EPS, 20, 0.03); _curFrame = CvImageWrapper.CreateImage(imageSize, PIXEL_DEPTH, PIXEL_COLOR_CHANNELS); _grey = CvImageWrapper.CreateImage(imageSize, PIXEL_DEPTH, PIXEL_CHANNELS); _prev_grey = CvImageWrapper.CreateImage(imageSize, PIXEL_DEPTH, PIXEL_CHANNELS); _pyramid = CvImageWrapper.CreateImage(imageSize, PIXEL_DEPTH, PIXEL_CHANNELS); _prev_pyramid = CvImageWrapper.CreateImage(imageSize, PIXEL_DEPTH, PIXEL_CHANNELS); _swap_temp = CvImageWrapper.CreateImage(imageSize, PIXEL_DEPTH, PIXEL_CHANNELS); } }
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) { } } }