Skip to content

Commit

Permalink
Implement Metrilus.Util changes (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
sisiplac authored and jangernert committed Aug 2, 2019
1 parent 72128c0 commit 3328fc0
Show file tree
Hide file tree
Showing 34 changed files with 328 additions and 343 deletions.
4 changes: 2 additions & 2 deletions BetaCameras/BaslerACE/BaslerACE.cs
Expand Up @@ -150,12 +150,12 @@ protected override void UpdateImpl()
}
}

protected override CameraImage CalcChannelImpl(string channelName)
protected override ImageBase CalcChannelImpl(string channelName)
{
switch (channelName)
{
case ChannelNames.Color:
return new ColorCameraImage(_bitmap);
return new ColorImage(_bitmap);
}

log.Error($"{Name}: Unexpected ChannelName in CalcChannel().");
Expand Down
24 changes: 12 additions & 12 deletions BetaCameras/BaslerToF/BaslerToF.cs
Expand Up @@ -18,10 +18,10 @@ public class BaslerToF : Camera
private Coord3D[] bufferPoint3f;
private AutoResetEvent dataAvailable = new AutoResetEvent(false);

private FloatCameraImage distanceImage;
private UShortCameraImage intensityImage;
private UShortCameraImage confidenceImage;
private Point3fCameraImage point3fImage;
private FloatImage distanceImage;
private UShortImage intensityImage;
private UShortImage confidenceImage;
private Point3fImage point3fImage;

private Object dataLock = new Object();

Expand Down Expand Up @@ -445,7 +445,7 @@ protected override void UpdateImpl()
{
if (IsChannelActive(ChannelNames.Point3DImage))
{
point3fImage = new Point3fCameraImage(width, height);
point3fImage = new Point3fImage(width, height);
for (int y = 0, i = 0; y < height; y++)
{
for (int x = 0; x < width; x++, i++)
Expand All @@ -458,7 +458,7 @@ protected override void UpdateImpl()

if (IsChannelActive(ChannelNames.Distance))
{
distanceImage = new FloatCameraImage(width, height);
distanceImage = new FloatImage(width, height);
for (int y = 0, i = 0; y < height; y++)
{
for (int x = 0; x < width; x++, i++)
Expand All @@ -471,7 +471,7 @@ protected override void UpdateImpl()

if (IsChannelActive(ChannelNames.Intensity))
{
intensityImage = new UShortCameraImage(width, height);
intensityImage = new UShortImage(width, height);

for (int y = 0, i = 0; y < height; y++)
{
Expand All @@ -484,7 +484,7 @@ protected override void UpdateImpl()

if (IsChannelActive(ChannelNames.ConfidenceMap))
{
confidenceImage = new UShortCameraImage(width, height);
confidenceImage = new UShortImage(width, height);

for (int y = 0, i = 0; y < height; y++)
{
Expand All @@ -504,7 +504,7 @@ protected override void UpdateImpl()
/// <param name="channelName">Channel name.</param>
/// <returns>(Image) Data.</returns>
/// <seealso cref="Camera.CalcChannel"/>
protected override CameraImage CalcChannelImpl(string channelName)
protected override ImageBase CalcChannelImpl(string channelName)
{
switch (channelName)
{
Expand All @@ -513,7 +513,7 @@ protected override CameraImage CalcChannelImpl(string channelName)
case ChannelNames.Distance:
return distanceImage;
case ChannelNames.Intensity:
return intensityImage.ToFloatCameraImage();
return intensityImage.ToFloatImage();
case ChannelNames.Point3DImage:
return point3fImage;
}
Expand All @@ -528,13 +528,13 @@ protected override CameraImage CalcChannelImpl(string channelName)
/// </summary>
/// <param name="rawConfidenceMap">16-bit unsigned int raw confidence map as provided by camera</param>
/// <returns>Confidence map as float image with intensities between 0 and 1</returns>
private FloatCameraImage CalcConfidenceMap(UShortCameraImage rawConfidenceMap)
private FloatImage CalcConfidenceMap(UShortImage rawConfidenceMap)
{
int width = rawConfidenceMap.Width;
int height = rawConfidenceMap.Height;
float scaling = 1.0f / ushort.MaxValue;

FloatCameraImage confidenceMap = new FloatCameraImage(width, height);
FloatImage confidenceMap = new FloatImage(width, height);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
Expand Down
9 changes: 5 additions & 4 deletions BetaCameras/CameraTemplate/CameraTemplate.cs
Expand Up @@ -3,6 +3,7 @@

using Metrilus.Util;
using System;
using System.Drawing;

namespace MetriCam2.Cameras
{
Expand Down Expand Up @@ -414,7 +415,7 @@ protected override void LoadAllAvailableChannels()

log.Warn(Name + ": TODO: Implement LoadAllAvailableChannels().");
Channels.Add(cr.RegisterChannel(ChannelNames.Intensity));
Channels.Add(cr.RegisterCustomChannel(CustomChannelNames.DummyNoiseChannel, typeof(FloatCameraImage)));
Channels.Add(cr.RegisterCustomChannel(CustomChannelNames.DummyNoiseChannel, typeof(FloatImage)));
}

/// <summary>
Expand Down Expand Up @@ -455,7 +456,7 @@ protected override void UpdateImpl()
/// <param name="channelName">Channel name.</param>
/// <returns>(Image) Data.</returns>
/// <seealso cref="Camera.CalcChannel"/>
protected override CameraImage CalcChannelImpl(string channelName)
protected override ImageBase CalcChannelImpl(string channelName)
{
log.Warn(Name + ": TODO: Implement CalcChannel().");
switch (channelName)
Expand All @@ -472,9 +473,9 @@ protected override CameraImage CalcChannelImpl(string channelName)
/// <summary>Computes (image) data for the fake Noise channel.</summary>
/// <returns>Noisy image data.</returns>
/// <seealso cref="Camera.CalcChannel"/>
private FloatCameraImage CalcDummyNoiseChannel()
private FloatImage CalcDummyNoiseChannel()
{
FloatCameraImage dummyNoiseImage = new FloatCameraImage(__noiseImageWidth, __noiseImageHeight);
FloatImage dummyNoiseImage = new FloatImage(__noiseImageWidth, __noiseImageHeight);
// TODO: Add channel data (here: noise)
return dummyNoiseImage;
}
Expand Down
3 changes: 2 additions & 1 deletion BetaCameras/CameraTemplate/CameraTemplate.csproj
Expand Up @@ -60,6 +60,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -92,4 +93,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
36 changes: 18 additions & 18 deletions BetaCameras/Kinect2/Kinect2.cs
Expand Up @@ -168,8 +168,8 @@ protected override void LoadAllAvailableChannels()
Channels.Add(cr.RegisterChannel(ChannelNames.Distance));
Channels.Add(cr.RegisterChannel(ChannelNames.Color));
Channels.Add(cr.RegisterChannel(ChannelNames.Point3DImage));
Channels.Add(cr.RegisterCustomChannel(CustomChannelNames.LongExposureIR, typeof(FloatCameraImage)));
Channels.Add(cr.RegisterCustomChannel(CustomChannelNames.BodyIndex, typeof(FloatCameraImage)));
Channels.Add(cr.RegisterCustomChannel(CustomChannelNames.LongExposureIR, typeof(FloatImage)));
Channels.Add(cr.RegisterCustomChannel(CustomChannelNames.BodyIndex, typeof(FloatImage)));
}

/// <summary>
Expand Down Expand Up @@ -553,7 +553,7 @@ protected override void UpdateImpl()
/// <param name="channelName">Channel name.</param>
/// <returns>(Image) Data.</returns>
/// <seealso cref="Camera.CalcChannel"/>
protected override CameraImage CalcChannelImpl(string channelName)
protected override ImageBase CalcChannelImpl(string channelName)
{
switch (channelName)
{
Expand All @@ -580,9 +580,9 @@ protected override CameraImage CalcChannelImpl(string channelName)
/// <param name="channelName">The channel name.</param>
/// <returns>The ProjectiveTransformationRational</returns>
/// <remarks>The method first searches for a pt file on disk. If this fails it is able to provide internal intrinsics for amplitude / depth channel.</remarks>
public override IProjectiveTransformation GetIntrinsics(string channelName)
public override ProjectiveTransformation GetIntrinsics(string channelName)
{
IProjectiveTransformation result = null;
ProjectiveTransformation result = null;

log.Info("Trying to load projective transformation from file.");
try
Expand Down Expand Up @@ -616,7 +616,7 @@ public override IProjectiveTransformation GetIntrinsics(string channelName)
/// Read out the factory intrinsics for the IR/Depth channel. The principal point in x-direction depends on the prperty <see cref="FlipX"/.>
/// </summary>
/// <returns>Factory IR intrinsics.</returns>
public IProjectiveTransformation GetFactoryIRIntrinsics()
public ProjectiveTransformation GetFactoryIRIntrinsics()
{
CameraIntrinsics intrinsics = Coordinates.GetDepthCameraIntrinsics();
for (int i = 0; i < 100 && intrinsics.FocalLengthX == 0; i++)
Expand Down Expand Up @@ -703,11 +703,11 @@ protected void CalcDistanceMap()
/// Calculates the distance data for the current frame.
/// </summary>
/// <returns>Distance map with dimensions Width and Height.</returns>
protected virtual FloatCameraImage CalcDistances()
protected virtual FloatImage CalcDistances()
{
CalcDistanceMap();

FloatCameraImage img = new FloatCameraImage(depthWidth, depthHeight);
FloatImage img = new FloatImage(depthWidth, depthHeight);

lock (this.depthFrameData)
{
Expand All @@ -728,7 +728,7 @@ protected virtual FloatCameraImage CalcDistances()
/// Calculates the color image for the current frame.
/// </summary>
/// <returns>Color image.</returns>
protected virtual unsafe ColorCameraImage CalcColor()
protected virtual unsafe ColorImage CalcColor()
{
lock (this.colorFrameData)
{
Expand All @@ -741,13 +741,13 @@ protected virtual unsafe ColorCameraImage CalcColor()
bmp.UnlockBits(bData);
bmp.RotateFlip(RotateFlipType.RotateNoneFlipX); //Kinect images are flipped in x-direction

return new ColorCameraImage(bmp);
return new ColorImage(bmp);
}
}

protected virtual FloatCameraImage CalcAmplitudes()
protected virtual FloatImage CalcAmplitudes()
{
FloatCameraImage img = new FloatCameraImage(depthWidth, depthHeight);
FloatImage img = new FloatImage(depthWidth, depthHeight);

lock (this.irFrameData)
{
Expand Down Expand Up @@ -844,10 +844,10 @@ private void OpenMultiReader()
/// </summary>
/// <returns>3-D point coordinates in meters.</returns>
/// <remarks>Format is [height, width, coordinate] with coordinate in {0,1,2} for x, y and z.</remarks>
private Point3fCameraImage Calc3DCoordinates()
private Point3fImage Calc3DCoordinates()
{
CameraSpacePoint[] worldPoints = new CameraSpacePoint[depthHeight * depthWidth];
Point3fCameraImage img = new Point3fCameraImage(depthWidth, depthHeight);
Point3fImage img = new Point3fImage(depthWidth, depthHeight);

lock (this.depthFrameData)
{
Expand All @@ -866,9 +866,9 @@ private Point3fCameraImage Calc3DCoordinates()
return img;
}

private FloatCameraImage CalcBodyIndex()
private FloatImage CalcBodyIndex()
{
FloatCameraImage result = new FloatCameraImage(depthWidth, depthHeight);
FloatImage result = new FloatImage(depthWidth, depthHeight);

for (int y = 0; y < this.depthHeight; y++)
{
Expand All @@ -883,9 +883,9 @@ private FloatCameraImage CalcBodyIndex()
return result;
}

private FloatCameraImage CalcLongExposureIR()
private FloatImage CalcLongExposureIR()
{
FloatCameraImage result = new FloatCameraImage(depthWidth, depthHeight);
FloatImage result = new FloatImage(depthWidth, depthHeight);

for (int y = 0; y < this.depthHeight; y++)
{
Expand Down
28 changes: 14 additions & 14 deletions BetaCameras/Kinect4Azure/Kinect4Azure.cs
Expand Up @@ -21,7 +21,7 @@ public class Kinect4Azure : Camera, IDisposable
private object _lock = new object();

private Dictionary<string, RigidBodyTransformation> _extrinsicsCache = new Dictionary<string, RigidBodyTransformation>();
private Dictionary<string, IProjectiveTransformation> _intrinsicsCache = new Dictionary<string, IProjectiveTransformation>();
private Dictionary<string, ProjectiveTransformation> _intrinsicsCache = new Dictionary<string, ProjectiveTransformation>();
private K4AColorResolution _lastValidColorResolution = K4AColorResolution.r720p; //Last valid mode != off
private K4ADepthMode _lastValidDepthMode = K4ADepthMode.WFOV_Unbinned; //Last valid mode != off

Expand Down Expand Up @@ -315,7 +315,7 @@ protected override void UpdateImpl()
}
}

protected override CameraImage CalcChannelImpl(string channelName)
protected override ImageBase CalcChannelImpl(string channelName)
{
if (null == _capture)
{
Expand All @@ -340,7 +340,7 @@ protected override CameraImage CalcChannelImpl(string channelName)
throw new ImageAcquisitionFailedException($"Channel {channelName} not supported!");
}

unsafe private ColorCameraImage CalcColor()
unsafe private ColorImage CalcColor()
{
if (_capture.Color == null)
{
Expand Down Expand Up @@ -375,10 +375,10 @@ unsafe private ColorCameraImage CalcColor()
}

bitmap.UnlockBits(bmpData);
return new ColorCameraImage(bitmap);
return new ColorImage(bitmap);
}

unsafe private FloatCameraImage CalcZImage()
unsafe private FloatImage CalcZImage()
{
if (_capture.Depth == null)
{
Expand All @@ -393,7 +393,7 @@ unsafe private FloatCameraImage CalcZImage()
throw new ImageAcquisitionFailedException($"Expected format Depth16, found format {_capture.Depth.Format.ToString()}");
}

FloatCameraImage depthData = new FloatCameraImage(width, height);
FloatImage depthData = new FloatImage(width, height);
short* source = (short*)_capture.Depth.Buffer;

for (int i = 0; i < depthData.Length; i++)
Expand All @@ -404,7 +404,7 @@ unsafe private FloatCameraImage CalcZImage()
return depthData;
}

unsafe private FloatCameraImage CalcIntensityImage()
unsafe private FloatImage CalcIntensityImage()
{
int height = _capture.IR.HeightPixels;
int width = _capture.IR.WidthPixels;
Expand All @@ -414,7 +414,7 @@ unsafe private FloatCameraImage CalcIntensityImage()
throw new ImageAcquisitionFailedException($"Expected format IR16, found format {_capture.IR.Format.ToString()}");
}

FloatCameraImage irData = new FloatCameraImage(width, height);
FloatImage irData = new FloatImage(width, height);
short* source = (short*)_capture.IR.Buffer;

for (int i = 0; i < irData.Length; i++)
Expand All @@ -425,15 +425,15 @@ unsafe private FloatCameraImage CalcIntensityImage()
return irData;
}

private FloatCameraImage CalcDistanceImage()
private FloatImage CalcDistanceImage()
{
FloatCameraImage zImage = CalcZImage();
FloatImage zImage = CalcZImage();
ProjectiveTransformationRational projTrans = GetIntrinsics(ChannelNames.ZImage) as ProjectiveTransformationRational;
Point3fCameraImage p3fImage = projTrans.ZImageToWorld(zImage);
return p3fImage.ToFloatCameraImage();
Point3fImage p3fImage = projTrans.ZImageToWorld(zImage);
return p3fImage.ToFloatImage();
}

public override IProjectiveTransformation GetIntrinsics(string channelName)
public override ProjectiveTransformation GetIntrinsics(string channelName)
{
string keyName = channelName == ChannelNames.Color ? $"{channelName}_{ColorResolution.ToString()}" : $"{channelName}_{DepthMode.ToString()}";
if (_intrinsicsCache.ContainsKey(keyName) && _intrinsicsCache[keyName] != null)
Expand Down Expand Up @@ -471,7 +471,7 @@ public override IProjectiveTransformation GetIntrinsics(string channelName)
throw new System.Exception(msg);
}

IProjectiveTransformation projTrans = new ProjectiveTransformationRational(
ProjectiveTransformation projTrans = new ProjectiveTransformationRational(
width,
height,
intrinsics.parameters[(int)Intrinsics.Fx],
Expand Down

0 comments on commit 3328fc0

Please sign in to comment.