public static void DistanceTransformMy(bool negative = false) { Glb.DrawMatAndHist0(Glb.matSrc); var matThr = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY).Threshold(128, 255, ThresholdTypes.Otsu); if (negative) { Cv2.BitwiseNot(matThr, matThr); } Glb.DrawMatAndHist1(matThr); var matDist = new Mat <float>(matThr.Size()); IpUnsafe.DistanceTransform(matThr.Data, matThr.Width, matThr.Height, matDist.Data); var x1 = matDist.Min(); var x2 = matDist.Max(); float y1 = 0; float y2 = 255; double scale = (y2 - y1) / (x2 - x1); double offset = (x2 * y1 - x1 * y2) / (x2 - x1); var matDistColor = new Mat(); matDist.ConvertTo(matDistColor, MatType.CV_8UC1, scale, offset); Glb.DrawMatAndHist2(matDistColor); matThr.Dispose(); matDist.Dispose(); matDistColor.Dispose(); }
public static void ErodeUnsafe(int iteration, bool useParallel) { Glb.DrawMatAndHist0(Glb.matSrc); var matGray = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY); Glb.DrawMatAndHist1(matGray); Glb.TimerStart(); var matDst = new Mat(matGray.Size(), matGray.Type()); for (int i = 0; i < iteration; i++) { if (i % 2 == 0) { IpUnsafe.Erode(matGray.Data, matDst.Data, matGray.Width, matGray.Height, (int)matGray.Step(), useParallel); } else { IpUnsafe.Erode(matDst.Data, matGray.Data, matGray.Width, matGray.Height, (int)matGray.Step(), useParallel); } } if (iteration != 0 && iteration % 2 == 0) { matGray.CopyTo(matDst); } Console.WriteLine("=> Method Time: {0}ms", Glb.TimerStop()); Glb.DrawMatAndHist2(matDst); matGray.Dispose(); matDst.Dispose(); }
public static void ImageCopyMarshal1() { Mat matDst = new Mat(Glb.matSrc[0].Size(), Glb.matSrc[0].Type()); int nbytes = (int)Glb.matSrc[0].Step() * Glb.matSrc[0].Height; IpUnsafe.MemcpyMarshal1(matDst.Data, Glb.matSrc[0].Data, nbytes); Glb.DrawMatAndHist(Glb.matSrc[0]); Glb.DrawMatAndHist(matDst); }
public static Mat ErodeUnsafe(Mat matGray, int iteration, bool useParallel) { var mat0 = matGray.Clone(); var mat1 = new Mat(mat0.Size(), mat0.Type()); for (int i = 0; i < iteration; i++) { var matSrc = (i % 2 == 0) ? mat0 : mat1; var matDst = (i % 2 == 0) ? mat1 : mat0; IpUnsafe.Erode(matSrc.Data, matDst.Data, matGray.Width, matGray.Height, (int)matGray.Step(), useParallel); } return((iteration % 2 == 0) ? mat0 : mat1); }
public static void ImageCopyMarshal1() { Mat matDst = new Mat(Glb.matSrc.Size(), Glb.matSrc.Type()); int nbytes = (int)Glb.matSrc.Step() * Glb.matSrc.Height; Glb.TimerStart(); IpUnsafe.MemcpyMarshal1(matDst.Data, Glb.matSrc.Data, nbytes); Console.WriteLine("=> Method Time: {0}ms", Glb.TimerStop()); Glb.DrawMatAndHist0(Glb.matSrc); Glb.DrawMatAndHist1(matDst); Glb.DrawMatAndHist2(null); matDst.Dispose(); }
public static double InverseUnsafe() { Glb.DrawMatAndHist(Glb.matSrc[0]); var matDst = Glb.matSrc[0].CvtColor(ColorConversionCodes.BGR2GRAY); Glb.DrawMatAndHist(matDst); var st = Util.GetTimeMs(); IpUnsafe.Inverse(matDst.Data, matDst.Width, matDst.Height, (int)matDst.Step()); var dt = Util.GetTimeMs() - st; Glb.DrawMatAndHist(matDst); return(dt); }
public static double InverseParallelFor() { Glb.DrawMatAndHist0(Glb.matSrc); var matDst = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY); Glb.DrawMatAndHist1(matDst); var st = GetTimeMs(); IpUnsafe.InverseParallelFor(matDst.Data, matDst.Width, matDst.Height, (int)matDst.Step()); var dt = GetTimeMs() - st; Glb.DrawMatAndHist2(matDst); matDst.Dispose(); return(dt); }