本文整理汇总了C#中IDataContainer.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# IDataContainer.OfType方法的具体用法?C# IDataContainer.OfType怎么用?C# IDataContainer.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataContainer
的用法示例。
在下文中一共展示了IDataContainer.OfType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PreProcess
public override IDataContainer PreProcess(IDataContainer dataContainer)
{
if (dataContainer.OfType<BlobData>().Any())
{
if (StagedData.OfType<BlobData>().Any())
Push();
foreach (var data in dataContainer)
Stage(data);
}
else if (dataContainer.OfType<Marker>().Any())
{
if (StagedData.OfType<Marker>().Any())
Push();
foreach (var data in dataContainer)
Stage(data);
}
else if (dataContainer.OfType<Hand>().Any())
{
if (StagedData.OfType<Hand>().Any())
Push();
foreach (var data in dataContainer)
Stage(data);
}
return null;
}
示例2: PreProcess
/// <summary>
///
/// </summary>
/// <param name="dataContainer"></param>
/// <returns></returns>
public override IDataContainer PreProcess(IDataContainer dataContainer)
{
var rgbImages = dataContainer.OfType<RgbImageData>().ToArray();
if (rgbImages.Any())
{
if (_rgbImageData != null)
_rgbImageData.Dispose();
_rgbImageData = rgbImages.First().Copy() as RgbImageData;
return null;
}
if (_rgbImageData != null)
{
dataContainer.Add(_rgbImageData.Copy());
_rgbImageData.Dispose();
_rgbImageData = null;
}
return dataContainer;
}
示例3: PreProcess
public override IDataContainer PreProcess(IDataContainer dataContainer)
{
const int width = 1280;
const int height = 720;
var image = new Image<Rgb, byte>(width, height);
foreach (var blob in dataContainer.OfType<BlobData>())
{
var polyline = new List<Point>();
foreach (var point in blob.Polygon.Points)
{
var x = point.X * width;
var y = point.Y * height;
polyline.Add(new Point((int)x, (int)y));
}
var color = Rgbs.White;
if (typeof(RectangleTracker) == blob.Source.GetType())
color = Rgbs.Red;
else if (typeof(RectangleTrackerColor) == blob.Source.GetType())
color = Rgbs.Yellow;
var centerX = (int)(blob.Center.X * width);
var centerY = (int)(blob.Center.Y * height);
image.DrawPolyline(polyline.ToArray(), true, color, 5);
image.Draw(string.Format("Id {0}", blob.Id), ref EmguFontBig, new Point(centerX, centerY), Rgbs.White);
}
Stage(new RgbImageData(this, "BlobRenderer", image.Copy()));
Push();
image.Dispose();
return null;
}
示例4: PreProcess
public override IDataContainer PreProcess(IDataContainer dataContainer)
{
if (_lastFrame == null) return base.PreProcess(dataContainer);
var devices = dataContainer.OfType<Device>().ToArray();
var unknownDevices = devices.Where(d => !d.IsIdentified).ToArray();
if (!devices.Any() || !unknownDevices.Any())
{
return base.PreProcess(dataContainer);
}
var outputImage = _lastFrame.Copy();
var binaryThreshold = BinaryThreshold;
if (unknownDevices.Any())
//if (devices.Any())
{
var grayImage = _lastFrame.Copy().Convert<Gray, byte>();
grayImage = grayImage.ThresholdBinary(new Gray(binaryThreshold), new Gray(255));
var width = _lastFrame.Width;
var height = _lastFrame.Height;
foreach (var device in unknownDevices)
//foreach (var device in devices)
{
var area = device.Area;
var roiExpandFactor = RoiExpandFactor;
var indentX = width * roiExpandFactor;
var indentY = height * roiExpandFactor;
var offsetX = (int)(area.X * width);
var offsetY = (int)(area.Y * height);
var roiX = (int)Math.Max(0, offsetX - indentX);
var roiY = (int)Math.Max(0, offsetY - indentY);
var roiWidth = (int)Math.Min(width - roiX, area.Width * width + 2 * indentX);
var roiHeight = (int)Math.Min(height - roiY, area.Height * height + 2 * indentY);
var roi = new Rectangle(
roiX,
roiY,
roiWidth,
roiHeight
);
if (IsRenderContent)
{
outputImage.Draw(roi, Rgbs.Red, 2);
}
var imageWithROI = _lastFrame.Copy(roi);
//FindMarker(imageWithROI, offsetX, offsetY, width, height, ref outputImage);
grayImage.ROI = roi;
Contour<Point> largestContour = null;
using (var storage = new MemStorage())
{
for (var contours = grayImage.FindContours(CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, RETR_TYPE.CV_RETR_EXTERNAL); contours != null; contours = contours.HNext)
{
var contour = contours.ApproxPoly(contours.Perimeter * 0.05, storage);
var roiArea = roi.Size.Width * roi.Size.Height;
var contourArea = contour.Area;
if (contour.Total != 4) continue;
if (contourArea < roiArea * 0.98 && contourArea > 10)
{
if (largestContour == null)
{
largestContour = contour;
continue;
}
if (contour.Area > largestContour.Area)
{
largestContour = contour;
}
}
}
if (largestContour != null)
{
var edges = DetermineLongestEdge(largestContour);
if (IsRenderContent)
{
var oldROI = outputImage.ROI;
outputImage.ROI = roi;
outputImage.Draw(largestContour.GetMinAreaRect(storage), Rgbs.Cyan, 2);
outputImage.Draw(edges[0], Rgbs.Red, 3);
outputImage.Draw(edges[1], Rgbs.Green, 3);
//.........这里部分代码省略.........
示例5: PreProcess
public override IDataContainer PreProcess(IDataContainer dataContainer)
{
var disconnected = dataContainer.OfType<Disconnected>().ToList();
if (disconnected.Count > 0)
{
// Remove all devices that are disconnected.
Devices.RemoveAll(device => disconnected.All(d => d.Value == device.DeviceId));
return null;
}
// Update last update timer that will be used by timeout handling
_lastUpdateTime = DateTime.Now;
var blobs = dataContainer.OfType<BlobData>().ToList();
var markers = dataContainer.OfType<Marker>().ToList();
var hands = dataContainer.OfType<Hand>().ToList();
// Remove all devices that are not present by a blob anymore
Devices.RemoveAll(device => blobs.All(b => b.Id != device.BlobId));
// TODO optimize for each loop -> use parallel for each loop?
//Parallel.ForEach(blobs, blob =>
foreach (var blob in blobs)
{
if (!DeviceExists(blob))
CreateDevice(blob);
// Find matching QrCode for current blob
double distance;
var marker = GetClosestMarker(markers, blob, out distance);
if (marker != null && distance < Distance)
{
UpdateDevice(blob, marker);
}
else
{
UpdateDevice(blob);
}
}
//});
return dataContainer;
}
示例6: PostProcess
public override IDataContainer PostProcess(IDataContainer dataContainer)
{
var devices = Devices.ToArray();
var identifiedDevices = devices.Where(d => d.IsIdentified).ToArray();
foreach (var device1 in identifiedDevices)
{
var p1 = new Point(device1.SmoothedCenter.X, device1.SmoothedCenter.Y);
var location = new Point3D(p1.X, p1.Y, 0);
var orientation = device1.SmoothedAngle;
var proximity = CreateProximity("Display", device1, location, orientation);
#region Calculate Proximities
// TODO optimize for each loop -> parallel for each loop?
foreach (var device2 in identifiedDevices)
{
if (Equals(device1, device2)) continue;
var x = device2.SmoothedCenter.X - device1.SmoothedCenter.X;
var y = device2.SmoothedCenter.Y - device1.SmoothedCenter.Y;
var distance = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
// device2 to device1 angle
var globalAngle = Math.Atan(y / x).RadiansToDegree();
if (x >= 0 && y < 0)
globalAngle = 90 + globalAngle;
else if (x >= 0 && y >= 0)
globalAngle = 90 + globalAngle;
else if (x < 0 && y >= 0)
globalAngle = 270 + globalAngle;
else if (x < 0 && y < 0)
globalAngle = 270 + globalAngle;
// subtract own angle
var localAngle = globalAngle + (360 - device1.SmoothedAngle); // angle -= (device1.Angle % 180);
localAngle %= 360;
// Log device locations only if processor view is visible
if (IsRenderContent)
{
var log = new StringBuilder();
if (localAngle >= 225 && localAngle < 315)
log.AppendFormat("Device {0} is right of device {1}", device1.Key, device2.Key);
else if (localAngle >= 45 && localAngle < 135)
log.AppendFormat("Device {0} is left of device {1}", device1.Key, device2.Key);
else if (localAngle >= 135 && localAngle < 225)
log.AppendFormat("Device {0} is top of device {1}", device1.Key, device2.Key);
else //
log.AppendFormat("Device {0} is bottom of device {1}", device1.Key, device2.Key);
log.AppendFormat(" in a distance of {0}", distance);
log.AppendFormat(" and its local angle is {0} (Global Angle {1})", localAngle, globalAngle);
LogFormat(log.ToString());
}
var p2 = new Point(device2.SmoothedCenter.X, device2.SmoothedCenter.Y);
var location2 = new Point3D(p2.X, p2.Y, 0);
var distance2 = (p2 - p1).Length;
proximity.Presences.Add(CreateProximity("Display", device2, location2, localAngle, distance2));
}
#endregion
// TODO optimize -> the hand calculation below uses absolute values
foreach (var hand in dataContainer.OfType<Hand>().ToArray())
{
var x = hand.SmoothedCenter.X * 320 - device1.SmoothedCenter.X;
var y = hand.SmoothedCenter.Y * 240 - device1.SmoothedCenter.Y;
var distance = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
// Log only if processor view is visible
if (IsRenderContent)
{
if (distance < 30 && hand.Depth < 80)
{
LogFormat("Hand {0} close to {1}", hand.Id, device1.DeviceId);
}
}
proximity.Presences.Add(new Proximity(this, "Hand", hand.Key)
{
Identity = "" + hand.Id,
Distance = distance,
Location = new Point3D(hand.SmoothedCenter.X, hand.SmoothedCenter.Y, hand.SlidingDepth),
});
}
Stage(proximity);
}
foreach (var device in devices.ToArray<IData>())
//.........这里部分代码省略.........
示例7: PreProcess
public override IDataContainer PreProcess(IDataContainer dataContainer)
{
_debugOutputImage = new Image<Rgb, byte>(Width, Height);
var rgbImage = dataContainer.OfType<RgbImageData>().ToArray();
if (!rgbImage.Any()) return null;
_debugOutputImage += rgbImage.First().Image.Copy();
var devices = dataContainer.OfType<Device>().ToArray();
//var unknownDevices = dataContainer.OfType<Device>().Where(d => !d.IsIdentified).ToArray();
var hands = dataContainer.OfType<Hand>().ToArray();
foreach (var device in devices)
{
var polyline = new List<Point>();
foreach (var point in device.Shape.Points)
{
var x = point.X * Width;
var y = point.Y * Height;
polyline.Add(new Point((int)x, (int)y));
}
var centerX = (int)(device.SmoothedCenter.X / 320 * Width);
var centerY = (int)(device.SmoothedCenter.Y / 240 * Height);
_debugOutputImage.DrawPolyline(polyline.ToArray(), true, device.IsIdentified ? Rgbs.Red : Rgbs.White, 5);
if (device.IsIdentified)
_debugOutputImage.Draw(string.Format("Id {0}", device.DeviceId), ref EmguFontBig, new Point(centerX, centerY), Rgbs.Red);
}
foreach (var hand in hands)
{
var resizedHandSegment = hand.Segment.Resize(_debugOutputImage.Width, _debugOutputImage.Height, INTER.CV_INTER_CUBIC).Mul(255);
//_debugOutputImage = _debugOutputImage.Copy(resizedHandSegment.Not());
_debugOutputImage = _debugOutputImage.AddWeighted(resizedHandSegment.Convert<Rgb, byte>(), 1.0, 0.5, 0.0);
resizedHandSegment.Dispose();
var point = new Point((int)(hand.RelativeCenter.X * Width), (int)(hand.RelativeCenter.Y * Height));
var labelPoint = new Point((int)(hand.RelativeCenter.X * Width + 30), (int)(hand.RelativeCenter.Y * Height));
_debugOutputImage.Draw(new CircleF(point, 10), Rgbs.Red, 6);
_debugOutputImage.Draw(string.Format("Id {0} (d={1:F0})", hand.Id, hand.Depth), ref EmguFontBig, labelPoint, Rgbs.Red);
}
var debugOutputImageCopy = _debugOutputImage.Copy();
Task.Factory.StartNew(() =>
{
var bitmapSource = debugOutputImageCopy.ToBitmapSource(true);
debugOutputImageCopy.Dispose();
return bitmapSource;
}).ContinueWith(t => DebugOutputBitmapSource = t.Result);
Stage(new RgbImageData(this, "DataRenderer", _debugOutputImage.Copy()));
if (_videoWriter != null)
_videoWriter.WriteFrame(_debugOutputImage.Convert<Bgr, byte>());
_debugOutputImage.Dispose();
Push();
return base.PreProcess(dataContainer);
}
示例8: PreProcess
public override IDataContainer PreProcess(IDataContainer dataContainer)
{
var devices = dataContainer.OfType<Device>().ToArray();
var unknownDevices = devices.Where(d => !d.IsIdentified).ToArray();
if (!devices.Any())
return base.PreProcess(dataContainer);
// For debugging the flag IsFindDisplayContinuously can be set 'true' -> 'false' is recommended however
var devicesToFind = IsFindDisplayContiuously ? devices : unknownDevices;
if (!devicesToFind.Any()) return null;
var rgbImages = dataContainer.OfType<RgbImageData>().ToArray();
// Do only process if RGB image is set
if (!rgbImages.Any())
return null;
var rgbImage = rgbImages.First().Image.Copy();
var debugImage = rgbImage.Copy();
if (IsRenderContent)
{
var lastRgbImageCopy = rgbImage.Copy();
Task.Factory.StartNew(() =>
{
var bitmapSource = lastRgbImageCopy.ToBitmapSource(true);
lastRgbImageCopy.Dispose();
return bitmapSource;
}).ContinueWith(t => InputImageBitmapSource = t.Result);
}
var colorImage = rgbImage.Copy();
// TODO: is the copy required or does convert already create a copy? _lastRgbImage.Copy()
var grayscaleImage = rgbImage.Copy().Convert<Gray, byte>();
var width = rgbImage.Width;
var height = rgbImage.Height;
foreach (var device in devicesToFind)
{
ProcessDevice(device, colorImage, grayscaleImage, width, height, ref debugImage);
}
colorImage.Dispose();
grayscaleImage.Dispose();
Push();
if (IsRenderContent)
{
// draw debug output
var debugImageCopy = debugImage.Copy();
Task.Factory.StartNew(() =>
{
var bitmapSource = debugImageCopy.ToBitmapSource(true);
debugImageCopy.Dispose();
return bitmapSource;
}).ContinueWith(t => DebugImageBitmapSource = t.Result);
}
debugImage.Dispose();
return null;
}