public static void Blob_Ipp() { Glb.DrawMatAndHist0(Glb.matSrc); var matThr = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY).Threshold(128, 255, ThresholdTypes.Otsu); MyBlobs blobs = new MyBlobs(); Stopwatch sw = Stopwatch.StartNew(); blobs.LabelIpp(matThr.Data, matThr.Width, matThr.Height, (int)matThr.Step()); sw.Stop(); Console.WriteLine("=> Label Time: {0}ms", sw.ElapsedMilliseconds); var matDst = new Mat(Glb.matSrc.Rows, Glb.matSrc.Cols, MatType.CV_8UC3); matDst.SetTo(Scalar.Black); Glb.TimerStart(); MyBlobRenderer.RenderBlobs(blobs, matDst); Console.WriteLine("=> Render Time: {0}ms", Glb.TimerStop()); Console.WriteLine("=> Blob Count: {0}", blobs.Blobs.Count); Glb.DrawMatAndHist1(matThr); Glb.DrawMatAndHist2(matDst); matThr.Dispose(); matDst.Dispose(); }
public static void RenderBlobs(MyBlobs blobs, Mat matDst) { int colorCount = 0; int dstPitch = matDst.ElemSize(); foreach (var blob in blobs.Blobs.Values) { double r, g, b; Glb.Hsv2Rgb((colorCount * 77) % 360, 0.5, 1.0, out r, out g, out b); colorCount++; byte bb = (byte)b; byte bg = (byte)g; byte br = (byte)r; int label = blob.label; for (int y = blob.MinY; y <= blob.MaxY; y++) { int * plabel = (int *)blobs.Labels.Ptr(y, blob.MinX); byte *pdst = (byte *)matDst.Ptr(y, blob.MinX); for (int x = blob.MinX; x <= blob.MaxX; x++, plabel++, pdst += dstPitch) { if (*plabel == label) { pdst[0] = bb; pdst[1] = bg; pdst[2] = br; } } } } }
public static void RenderBlobs(MyBlobs blobs, Mat matDst) { byte *pdst = matDst.DataPointer; int bw = matDst.Width; int bh = matDst.Height; int stride = (int)matDst.Step(); int colorCount = 0; foreach (var blob in blobs.Blobs.Values) { double r, g, b; Glb.Hsv2Rgb((colorCount * 77) % 360, 0.5, 1.0, out r, out g, out b); colorCount++; byte bb = (byte)b; byte bg = (byte)g; byte br = (byte)r; int label = blob.label; for (int y = blob.MinY; y <= blob.MaxY; y++) { for (int x = blob.MinX; x <= blob.MaxX; x++) { if (blobs.Labels[y * bw + x] == label) { byte *ppdst = pdst + stride * y + x * 3; ppdst[0] = bb; ppdst[1] = bg; ppdst[2] = br; } } } } }