public override void Process() { Rectangle[] rectangles; FInput.Image.GetImage(TColorFormat.L8, FGrayScale); var grayImage = FGrayScale.GetImage() as Image <Gray, byte>; if (GpuInvoke.HasCuda && AllowGpu) { rectangles = ProcessOnGpu(grayImage); } else { rectangles = ProcessOnCpu(grayImage); } FTrackingObjects.Clear(); foreach (var rectangle in rectangles) { var trackingObject = new TrackingObject(); var center = new Vector2D(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height / 2); var maximumSourceXY = new Vector2D(FGrayScale.Width, FGrayScale.Height); trackingObject.Position = VMath.Map(center, FMinimumSourceXY, maximumSourceXY, FMinimumDestXY, FMaximumDestXY, TMapMode.Float); trackingObject.Scale = VMath.Map(new Vector2D(rectangle.Width, rectangle.Height), FMinimumSourceXY.x, maximumSourceXY.x, 0, 1, TMapMode.Float); FTrackingObjects.Add(trackingObject); } }
void UpdateImage() { if (!FInput.Allocated) { return; } FInput.GetImage(FImage); FImageBox.Image = FImage.GetImage(); }
public override void Process() { Rectangle[] rectangles; // load image FInput.Image.GetImage(TColorFormat.RGB8, FBgrImage); var tempImage = FBgrImage.GetImage() as Image <Rgb, byte>; var image = FBgrImage.GetImage(); // invoke detection if (GpuInvoke.HasCuda && AllowGpu) { var bgra = tempImage.Convert <Bgra, byte>(); rectangles = GPUDetectPedestrian(bgra); } else { var bgrImage = tempImage.Convert <Bgr, byte>(); rectangles = DetectPedestrian(bgrImage); } // parse detected objects FTrackingPedestrians.Clear(); foreach (var rectangle in rectangles) { var trackingPedestrian = new TrackingPedestrian(); var center = new Vector2D(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height / 2); var maximumSourceXY = new Vector2D(FBgrImage.Width, FBgrImage.Height); trackingPedestrian.Position = VMath.Map(center, FMinimumSourceXY, maximumSourceXY, FMinimumDestXY, FMaximumDestXY, TMapMode.Float); trackingPedestrian.Scale = VMath.Map(new Vector2D(rectangle.Width, rectangle.Height), FMinimumSourceXY.x, maximumSourceXY.x, 0, 1, TMapMode.Float); FTrackingPedestrians.Add(trackingPedestrian); } }
public override void Process() { lock (this.FeaturesSet.Lock) { FInput.GetImage(FGrayScale); var gray = FGrayScale.GetImage() as Image <Gray, Byte>; this.FeaturesSet.KeyPoints = this.Detector.DetectKeyPointsRaw(gray, null); this.FeaturesSet.Descriptors = this.Detector.ComputeDescriptorsRaw(gray, null, this.FeaturesSet.KeyPoints); this.FeaturesSet.Allocated = true; this.FeaturesSet.OnUpdate(); } }
public override void Process() { //Stopwatch sw = new Stopwatch(); //sw.Start(); //Status = ""; if (!FInput.LockForReading()) { return; } FInput.GetImage(FGrayScale); FInput.ReleaseForReading(); FGrayByte = FGrayScale.GetImage() as Image <Gray, byte>; FGrayInt = FGrayByte.Convert <Gray, int>(); //Status += "reading: " + sw.ElapsedMilliseconds.ToString(); //sw.Restart(); PixelWiseDither(); //Status += " dithering: " + sw.ElapsedMilliseconds.ToString(); //sw.Restart(); //try //{ // PixelWiseDither(); //} //catch (Exception e) //{ // Status = e.ToString(); // ImageUtils.Log(e); //} ImageUtils.CopyImage(FGrayInt.Convert <Gray, byte>() as IImage, FOutput.Image); //Status += " writing: " + sw.ElapsedMilliseconds.ToString(); FOutput.Send(); }
public override void Process() { CVImage swap = FPrevious; FPrevious = FCurrent; FCurrent = swap; FInput.Image.GetImage(TColorFormat.L8, FCurrent); Image <Gray, byte> p = FPrevious.GetImage() as Image <Gray, byte>; Image <Gray, byte> c = FCurrent.GetImage() as Image <Gray, byte>; Image <Gray, float> vx = FVelocityX.GetImage() as Image <Gray, float>; Image <Gray, float> vy = FVelocityY.GetImage() as Image <Gray, float>; OpticalFlow.LK(p, c, FWindowSize, vx, vy); CopyToRgb(); FOutput.Send(); }
public override void Process() { //TODO: Status = "Load Haar file" if (FHaarCascade == null) { return; } FInput.Image.GetImage(FGrayScale); var stride = (FGrayScale.Width * 3); var align = stride % 4; if (align != 0) { stride += 4 - align; } //Can not work, bcs src and dest are the same. CvInvoke.cvEqualizeHist(FGrayScale.CvMat, FGrayScale.CvMat); //MCvAvgComp[] objectsDetected = FHaarCascade.Detect(grayImage, 1.8, 1, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(grayImage.Width / 10, grayImage.Height / 10)); MCvAvgComp[] objectsDetected = FHaarCascade.Detect(FGrayScale.GetImage() as Image <Gray, byte>, FScaleFactor, FMinNeighbors, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(FMinWidth, FMinHeight)); FTrackingObjects.Clear(); foreach (MCvAvgComp f in objectsDetected) { TrackingObject trackingObject = new TrackingObject(); Vector2D objectCenterPosition = new Vector2D(f.rect.X + f.rect.Width / 2, f.rect.Y + f.rect.Height / 2); Vector2D maximumSourceXY = new Vector2D(FGrayScale.Width, FGrayScale.Height); trackingObject.Position = VMath.Map(objectCenterPosition, FMinimumSourceXY, maximumSourceXY, FMinimumDestXY, FMaximumDestXY, TMapMode.Float); trackingObject.Scale = VMath.Map(new Vector2D(f.rect.Width, f.rect.Height), FMinimumSourceXY.x, maximumSourceXY.x, 0, 1, TMapMode.Float); FTrackingObjects.Add(trackingObject); } }
public override void Process() { CVImage swap = FPrevious; FPrevious = FCurrent; FCurrent = swap; FInput.Image.GetImage(TColorFormat.L8, FCurrent); Image <Gray, byte> p = FPrevious.GetImage() as Image <Gray, byte>; Image <Gray, byte> c = FCurrent.GetImage() as Image <Gray, byte>; Image <Gray, float> vx = FVelocityX.GetImage() as Image <Gray, float>; Image <Gray, float> vy = FVelocityY.GetImage() as Image <Gray, float>; OpticalFlow.HS(p, c, UsePrevious, vx, vy, FLambda, new MCvTermCriteria(FIterations)); CopyToRgb(); FOutput.Send(); }
public void Evaluate(int SpreadMax) { for (int i = SpreadMax; i < FOutput.SliceCount; i++) { FOutput[i].Dispose(); } while (FOutput.SliceCount < SpreadMax) { FOutput.Add(new CVImageLink()); } FStatus.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { if (!FDo[i]) { continue; } var inputSpread = FInput[i]; var output = FOutput[i]; foreach (var image in inputSpread) { image.LockForReading(); } CVImage result = new CVImage(); try { int size = inputSpread.SliceCount; Image <Bgr, Byte>[] images = new Image <Bgr, byte> [size]; List <CVImage> ToDispose = new List <CVImage>(); for (int j = 0; j < size; j++) { if (inputSpread[j].FrontImage.ImageAttributes.ColourFormat == TColorFormat.RGB8) { images[j] = inputSpread[j].FrontImage.GetImage() as Image <Bgr, Byte>; } else { var image = new CVImage(); ToDispose.Add(image); image.Initialise(inputSpread[j].FrontImage.Size, TColorFormat.RGB8); inputSpread[j].FrontImage.GetImage(image); images[j] = image.GetImage() as Image <Bgr, Byte>; } } result.SetImage(FStitcher.Stitch(images)); foreach (var image in ToDispose) { image.Dispose(); } FStatus[i] = "OK"; } catch (Exception e) { FStatus[i] = e.Message; } finally { foreach (var image in inputSpread) { image.ReleaseForReading(); } } output.Send(result); } }
public void Evaluate(int SpreadMax) { for (int i = SpreadMax; i < FOutput.SliceCount; i++) FOutput[i].Dispose(); while (FOutput.SliceCount < SpreadMax) FOutput.Add(new CVImageLink()); FStatus.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { if (!FDo[i]) continue; var inputSpread = FInput[i]; var output = FOutput[i]; foreach(var image in inputSpread) { image.LockForReading(); } CVImage result = new CVImage(); try { int size = inputSpread.SliceCount; Image<Bgr, Byte>[] images = new Image<Bgr, byte>[size]; List<CVImage> ToDispose = new List<CVImage>(); for (int j = 0; j < size; j++) { if (inputSpread[j].FrontImage.ImageAttributes.ColourFormat == TColorFormat.RGB8) { images[j] = inputSpread[j].FrontImage.GetImage() as Image<Bgr, Byte>; } else { var image = new CVImage(); ToDispose.Add(image); image.Initialise(inputSpread[j].FrontImage.Size, TColorFormat.RGB8); inputSpread[j].FrontImage.GetImage(image); images[j] = image.GetImage() as Image<Bgr, Byte>; } } result.SetImage(FStitcher.Stitch(images)); foreach (var image in ToDispose) { image.Dispose(); } FStatus[i] = "OK"; } catch (Exception e) { FStatus[i] = e.Message; } finally { foreach(var image in inputSpread) { image.ReleaseForReading(); } } output.Send(result); } }
override public void Process() { if (!Enabled) { return; } FInput.Image.GetImage(TColorFormat.L8, FGrayscale); Image <Gray, byte> img = FGrayscale.GetImage() as Image <Gray, byte>; if (img != null) { //Seriously EmguCV? what the f**k is up with your syntax? //both ways of skinning this cat involve f*****g a moose List <ContourTempData> results = new List <ContourTempData>(); ContourTempData c; try { CHAIN_APPROX_METHOD cam; switch (Approximation) { case ContourApproximation.None: cam = CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE; break; case ContourApproximation.TehChinKCOS: cam = CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_TC89_KCOS; break; case ContourApproximation.TehChinL1: cam = CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_TC89_L1; break; case ContourApproximation.LinkRuns: cam = CHAIN_APPROX_METHOD.CV_LINK_RUNS; break; case ContourApproximation.Simple: case ContourApproximation.Poly: default: cam = CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE; break; } Contour <Point> contour = img.FindContours(cam, RETR_TYPE.CV_RETR_LIST); for (; contour != null; contour = contour.HNext) { c = new ContourTempData(); c.Area = contour.Area; c.Bounds = contour.BoundingRectangle; if (Approximation == ContourApproximation.Poly) { c.Perimeter = new ContourPerimeter(contour.ApproxPoly(FPolyAccuracy), img.Width, img.Height); } else { c.Perimeter = new ContourPerimeter(contour, img.Width, img.Height); } results.Add(c); } lock (FLockResults) FStatus = "OK"; } catch (Exception e) { lock (FLockResults) FStatus = e.Message; } lock (FLockResults) { FBoundingBox.SliceCount = results.Count; FArea.SliceCount = results.Count; FPerimeter.SliceCount = results.Count; for (int i = 0; i < results.Count; i++) { c = results[i]; FBoundingBox[i] = new Vector4D(((double)c.Bounds.X / (double)img.Width) * 2.0d - 1.0d, 1.0d - ((double)c.Bounds.Y / (double)img.Height) * 2.0d, (double)c.Bounds.Width * 2.0d / (double)img.Width, (double)c.Bounds.Height * 2.0d / (double)img.Height); FArea[i] = (double)c.Area * (4.0d / (double)(img.Width * img.Height)); FPerimeter[i] = c.Perimeter; } } } }
override public void Process() { if (!Enabled) { return; } if (!FGrayscale.Allocated || FGrayscale.Size != FInput.ImageAttributes.Size) { FGrayscale.Initialise(FInput.ImageAttributes.Size, TColorFormat.L8); } FInput.Image.GetImage(TColorFormat.L8, FGrayscale); Size SizeNow = BoardSize; PointF[] points = null; if (TestAtLowResolution) { if (!FLowResolution.Allocated) { FLowResolution.Initialise(new Size(1024, 1024), TColorFormat.L8); } CvInvoke.cvResize(FGrayscale.CvMat, FLowResolution.CvMat, INTER.CV_INTER_LINEAR); var lowResPoints = CameraCalibration.FindChessboardCorners(FLowResolution.GetImage() as Image <Gray, byte>, SizeNow, CALIB_CB_TYPE.ADAPTIVE_THRESH); if (lowResPoints != null) { int minX = FGrayscale.Width; int minY = FGrayscale.Height; int maxX = 0; int maxY = 0; foreach (var point in lowResPoints) { if ((int)point.X > maxX) { maxX = (int)point.X; } if ((int)point.Y > maxY) { maxY = (int)point.Y; } if ((int)point.X < minX) { minX = (int)point.X; } if ((int)point.Y < minY) { minY = (int)point.Y; } } minX = minX * FGrayscale.Width / 1024; maxX = maxX * FGrayscale.Width / 1024; minY = minY * FGrayscale.Height / 1024; maxY = maxY * FGrayscale.Height / 1024; int boardResolutionMin = Math.Min(SizeNow.Width, SizeNow.Height); int strideX = (maxX - minX) / boardResolutionMin; int strideY = (maxY - minY) / boardResolutionMin; minX -= strideX * 2; maxX += strideX * 2; minY -= strideY * 2; maxY += strideY * 2; if (minX < 0) { minX = 0; } if (minY < 0) { minY = 0; } if (maxX > FGrayscale.Width - 1) { maxX = FGrayscale.Width - 1; } if (maxY > FGrayscale.Height - 1) { maxY = FGrayscale.Height - 1; } Rectangle rect = new Rectangle(minX, minY, maxX - minX, maxY - minY); CvInvoke.cvSetImageROI(FGrayscale.CvMat, rect); FCropped.Initialise(new Size(rect.Width, rect.Height), TColorFormat.L8); CvInvoke.cvCopy(FGrayscale.CvMat, FCropped.CvMat, IntPtr.Zero); CvInvoke.cvResetImageROI(FGrayscale.CvMat); points = CameraCalibration.FindChessboardCorners(FCropped.GetImage() as Image <Gray, byte>, SizeNow, CALIB_CB_TYPE.ADAPTIVE_THRESH); if (points != null) { for (int iPoint = 0; iPoint < points.Length; iPoint++) { points[iPoint].X += minX; points[iPoint].Y += minY; } } } } else { points = CameraCalibration.FindChessboardCorners(FGrayscale.GetImage() as Image <Gray, byte>, SizeNow, CALIB_CB_TYPE.ADAPTIVE_THRESH); } lock (FFoundPointsLock) { if (points == null) { SearchFailed = true; FFoundPoints.SliceCount = 0; } else { SearchSuccessful = true; FFoundPoints.SliceCount = SizeNow.Width * SizeNow.Height; for (int i = 0; i < FFoundPoints.SliceCount; i++) { FFoundPoints[i] = new Vector2D(points[i].X, points[i].Y); } } } }