12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Emgu.CV;
- using Emgu.CV.Structure;
- using System.Diagnostics;
- namespace bbiwarg.Images
- {
- class DepthImage
- {
- public Image<Gray, Int16> Image { get; private set; }
- public int Width { get; private set; }
- public int Height { get; private set; }
- public Int16 MinDepth { get; private set; }
- public Int16 MaxDepth { get; private set; }
- public DepthImage(Image<Gray, Int16> image)
- {
- this.Image = image;
- Width = image.Width;
- Height = image.Height;
- //smooth
- this.Image = image.SmoothMedian(3);
-
- //threshold min&maxDepth
- MinDepth = (Int16)findMinDepth();
- MaxDepth = (Int16)(MinDepth + 200);
- thresholdDepth(MaxDepth);
- }
- public Int16 getDepthAt(Point point)
- {
- return getDepthAt(point.X, point.Y);
- }
- public Int16 getDepthAt(int x, int y)
- {
- return Image.Data[y, x, 0];
- }
- public void setDepthAt(Point point, Int16 depth)
- {
- setDepthAt(point.X, point.Y, depth);
- }
- public void setDepthAt(int x, int y, Int16 depth)
- {
- Image.Data[y, x, 0] = depth;
- }
- public float getRelativeDepthAt(Point point)
- {
- return getRelativeDepthAt(point.X, point.Y);
- }
- public float getRelativeDepthAt(int x, int y)
- {
- float minMaxInterval = Math.Max(MaxDepth - MinDepth, 1);
- return (getDepthAt(x, y) - MinDepth) / minMaxInterval;
- }
- public Int16 getMinDepth()
- {
- return MinDepth;
- }
- public Int16 getMaxDepth()
- {
- return MaxDepth;
- }
- private Int16 findMinDepth()
- {
- // min and max values
- double[] min, max;
- // min and max locations
- Point[] minLoc, maxLoc;
- Image.MinMax(out min, out max, out minLoc, out maxLoc);
-
- return (Int16) min[0];
- }
- private void thresholdDepth(Int16 max)
- {
- // newDepth = (depth > max) ? max : depth;
- Image = Image.ThresholdTrunc(new Gray(max));
- }
- }
- }
|