2 using System.Collections.Generic;
7 using AForge.Imaging.Filters;
29 Bitmap filteredImage = (Bitmap) image.Clone();
33 HSLFiltering hslFilter =
new HSLFiltering
39 hslFilter.ApplyInPlace(filteredImage);
44 ColorFiltering colorFilter =
new ColorFiltering
51 colorFilter.ApplyInPlace(filteredImage);
60 grayFilter = Grayscale.CommonAlgorithms.BT709;
63 grayFilter = Grayscale.CommonAlgorithms.RMY;
66 grayFilter = Grayscale.CommonAlgorithms.Y;
70 grayFilter = Grayscale.CommonAlgorithms.BT709;
74 Bitmap grayImage = grayFilter.Apply(filteredImage);
78 Threshold thresholdFilter =
new Threshold(filter.
Threshold);
79 thresholdFilter.ApplyInPlace(grayImage);
85 Erosion3x3 errossionFilter =
new Erosion3x3();
86 errossionFilter.ApplyInPlace(grayImage);
92 Dilatation3x3 dilatationFilter =
new Dilatation3x3();
93 dilatationFilter.ApplyInPlace(grayImage);
153 BlobCounter blobCounter =
new BlobCounter { ObjectsOrder = ObjectsOrder.YX };
154 blobCounter.ProcessImage(bitmap);
155 Blob[] blobs = blobCounter.GetObjectsInformation();
169 Blob maxObject =
new Blob(0,
new Rectangle(0, 0, 0, 0));
170 foreach (Blob blob
in blobs)
172 int blobSize = blob.Rectangle.Width * blob.Rectangle.Height;
173 if (blobSize <= maxSize)
223 List<Blob> blobList =
225 blob => blob.CenterOfGravity.Y < 100)
227 if (blobList.Count < 1)
230 blob => blob.Rectangle.Y < 100)
232 return blobList.Sum(blob => blob.CenterOfGravity.X) / blobList.Count;
249 internal static List<Blob>
ClearBlobs(Blob[] blobs,
float laserLineX)
251 const float safetyFrame = 10f;
256 blob.CenterOfGravity.X > laserLineX + safetyFrame &&
258 blob.CenterOfGravity.Y > 100 && blob.CenterOfGravity.Y < 860)
271 SimpleSkeletonization filter =
new SimpleSkeletonization();
272 return ReturnFilteredImage(bitmap, filter);
284 CannyEdgeDetector filter =
new CannyEdgeDetector();
285 return ReturnFilteredImage(bitmap, filter);
297 HomogenityEdgeDetector filter =
new HomogenityEdgeDetector();
298 return ReturnFilteredImage(bitmap, filter);
310 SobelEdgeDetector filter =
new SobelEdgeDetector();
311 return ReturnFilteredImage(bitmap, filter);
315 private static Bitmap ReturnFilteredImage(Bitmap bitmap, IInPlaceFilter filter)
317 Bitmap returnImage = (Bitmap)bitmap.Clone();
318 filter.ApplyInPlace(returnImage);
336 List<ColorPoint3D> points =
new List<ColorPoint3D>();
350 Line laserline =
new Line(worldLaserSourcePosition, worldLaserLinePosition);
353 List<Blob> relevantBlobs =
ClearBlobs(blobs, laserLineX);
355 foreach (Blob blob
in relevantBlobs)
357 ColorPoint3D worldPoint = ComputeDepthByIntersection(blob, worldCameraSourcePosition, laserline, configuration);
358 worldPoint.
Y = ScaleY(worldPoint, worldCameraSourcePosition);
360 if (!AdjustPointToTurnTable(step, ref worldPoint, microSteps, configuration))
362 worldPoint.Color = colorImage != null
363 ? ((Bitmap) colorImage).GetPixel((
int)blob.CenterOfGravity.X, (
int)blob.CenterOfGravity.Y)
365 points.Add(worldPoint);
414 Line viewLine =
new Line(worldCameraSourcePosition, worldPoint2D);
416 ColorPoint3D worldPoint = viewLine.Intersection(laserline);
417 worldPoint.
Y = worldPoint2D.
Y;
424 double y = worldPoint.
Y - worldCameraSourcePosition.
Y;
425 y *= (worldCameraSourcePosition.
Z - worldPoint.
Z) / worldCameraSourcePosition.
Z;
426 y += worldCameraSourcePosition.
Y;
431 private static bool AdjustPointToTurnTable(
int step, ref
ColorPoint3D worldPoint,
bool microSteps,
Information configuration)
433 double turntableDegree = GetTurntableDegree(step, microSteps, configuration);
437 double alpha = Math.Atan(worldPoint.Z/worldPoint.X) + turntableDegree*(Math.PI/180.0f);
438 double hypo = Math.Sqrt(worldPoint.X*worldPoint.X + worldPoint.Z*worldPoint.Z);
440 if (worldPoint.X < 0)
441 if (worldPoint.Z < 0)
446 worldPoint.Z = Math.Sin(alpha) * hypo;
447 worldPoint.X = Math.Cos(alpha) * hypo;
450 double tablePos = Math.Sqrt(worldPoint.Z*worldPoint.Z + worldPoint.X*worldPoint.X);
452 return worldPoint.Y > 0.5 && hypo < 7 && tablePos < turntableSize;
456 private static double GetTurntableDegree(
int step,
bool microSteps,
Information configuration)
458 int numberOfTotalSteps = microSteps
463 double turntableDegree = 360.0f - (double)step * 360.0f / (
double)numberOfTotalSteps;
464 return turntableDegree;
float WorldHeight
Gets the height of the world.
int FilterGreenMax
Gets or sets the filter green maximum.
Coordinates WorldCoordinates
Gets or sets the world coordinates.
float LuminanceMin
Gets or sets the luminance minimum.
float Y
Gets or sets the y.
GrayFilter GrayFilter
Gets or sets the gray filter.
int Threshold
Gets or sets the threshold.
double Z
Gets or sets the z.
bool UseHslFilter
Gets or sets a value indicating whether [use HSL filter].
bool UseThresholdFilter
Gets or sets a value indicating whether [use threshold filter].
double Y
Gets or sets the y.
int SafetyDistance
Gets or sets the safety distance.
int FilterGreenMin
Gets or sets the filter green minimum.
float WorldWidth
Gets or sets the width of the world.
int FilterRedMin
Gets or sets the filter red minimum.
double PercentFromTop
Gets or sets the percent from top.
double X
Gets or sets the x.
int FilterBlueMax
Gets or sets the filter blue maximum.
int Height
Gets or sets the height of the frame.
float Z
Gets or sets the z.
float LuminanceMax
Gets or sets the luminance maximum.
float X
Gets or sets the x.
int FilterRedMax
Gets or sets the filter red maximum.
int MicroSteps
Gets or sets the number of micro steps.
Coordinates WorldCoordinates
Gets or sets the world coordinates.
int HueMax
Gets or sets the hue maximum.
bool UseDiletationFilter
Gets or sets a value indicating whether [use diletation filter].
Coordinates WorldCoordinates
Gets or sets the world coordinates.
bool UseColorFilter
Gets or sets a value indicating whether [use color filter].
int FilterBlueMin
Gets or sets the filter blue minimum.
int Width
Gets or sets the width.
int HueMin
Gets or sets the hue minimum.
float SaturationMax
Gets or sets the saturation maximum.
float SaturationMin
Gets or sets the saturation minimum.
int Steps
Gets or sets the number of steps.
double Radius
Gets or sets the radius.
bool UseErosionFilter
Gets or sets a value indicating whether [use erosion filter].