Skip to content
Permalink
Browse files

Use util version with managed arrays in image classes (#179)

* * Use util version with managed arrays in image classes
* Removed NetStandard suffix in DLL names.

* Increment version to v.13.0 (#180)

* Updated log4net (.NET 4.5 version) and Metrilus.Util references (v14.0, .NET 4.5).
  • Loading branch information...
sisiplac authored and mischastik committed Feb 12, 2019
1 parent 8c38676 commit fcc48bc1a3bc07d59a7be900df4c441e14551019
@@ -195,13 +195,19 @@ protected override unsafe void UpdateImpl()
PXCMImage.ImageData depthData;
sample.depth.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_DEPTH_F32, out depthData);
depthImage = new FloatCameraImage(sample.depth.info.width, sample.depth.info.height);
memcpy(new IntPtr(depthImage.Data), depthData.planes[0], new UIntPtr((uint)sample.depth.info.width * (uint)sample.depth.info.height * (uint)sizeof(float)));
fixed (float* depthImageData = depthImage.Data)
{
memcpy(new IntPtr(depthImageData), depthData.planes[0], new UIntPtr((uint)sample.depth.info.width * (uint)sample.depth.info.height * (uint)sizeof(float)));
}
sample.depth.ReleaseAccess(depthData);

PXCMImage.ImageData irData;
sample.ir.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_Y8, out irData);
irImage = new ByteCameraImage(sample.ir.info.width, sample.ir.info.height);
memcpy(new IntPtr(irImage.Data), irData.planes[0], new UIntPtr((uint)sample.ir.info.width * (uint)sample.ir.info.height * (uint)sizeof(byte)));
fixed (byte* irImageData = irImage.Data)
{
memcpy(new IntPtr(irImageData), irData.planes[0], new UIntPtr((uint)sample.ir.info.width * (uint)sample.ir.info.height * (uint)sizeof(byte)));
}
sample.ir.ReleaseAccess(irData);

pp.ReleaseFrame();
@@ -272,7 +272,10 @@ protected override unsafe void UpdateImpl()
{
sample.depth.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_DEPTH_F32, out depthData);
depthImage = new FloatCameraImage(sample.depth.info.width, sample.depth.info.height);
CopyImageWithStride(sample.depth.info.width, sample.depth.info.height, 4, depthData, new IntPtr(depthImage.Data));
fixed (float* depthImageData = depthImage.Data)
{
CopyImageWithStride(sample.depth.info.width, sample.depth.info.height, 4, depthData, new IntPtr(depthImageData));
}
sample.depth.ReleaseAccess(depthData);
}

@@ -6,7 +6,7 @@
<Company>Metrilus GmbH</Company>
<Authors>Metrilus GmbH</Authors>
<Product>MetriCam2</Product>
<AssemblyName>MetriCam2.Cameras.RealSense2.NetStandard</AssemblyName>
<AssemblyName>MetriCam2.Cameras.RealSense2</AssemblyName>
<RootNamespace>MetriCam2.Cameras</RootNamespace>
</PropertyGroup>

@@ -50,8 +50,8 @@
<Reference Include="Intel.RealSense">
<HintPath>Z:\external-libraries\Intel\libRealSense2\2.12.0\AnyCPU\Release\netstandard2.0\Intel.RealSense.dll</HintPath>
</Reference>
<Reference Include="Metrilus.Util.NetStandard">
<HintPath>$(LibrariesPath)Metrilus.Util.NetStandard.dll</HintPath>
<Reference Include="Metrilus.Util">
<HintPath>$(LibrariesPathNetStandard)Metrilus.Util.dll</HintPath>
</Reference>
</ItemGroup>

@@ -504,50 +504,45 @@ CameraImage^ TIVoxel::CalcChannelImpl(String^ channelName)
CameraImage^ TIVoxel::CalcAmplitude()
{
FloatCameraImage^ result = gcnew FloatCameraImage(m_width, m_height);
float* resultPtr = result->Data;
ByteCameraImage^ localAmplitudes = currentAmplitudes;

unsigned short int *rawConfidence = (unsigned short int*)localAmplitudes->Data;
pin_ptr<Byte> localAmplitudesData = &(localAmplitudes->Data)[0];
unsigned short int *rawConfidence = (unsigned short int*)localAmplitudesData;

for (int i = 0; i < m_width*m_height; i++)
{
//covert data
*resultPtr++ = (float)*rawConfidence++;
result[i] = (float)*rawConfidence++;
}
GC::KeepAlive(localAmplitudes);

return result;
}

CameraImage^ TIVoxel::CalcAmbient()
{
FloatCameraImage^ result = gcnew FloatCameraImage(m_width, m_height);
float* resultPtr = result->Data;
ByteCameraImage^ localAmbient = currentAmbient;

byte* rawAmbient = (byte*)localAmbient->Data;
for (int i = 0; i < m_width*m_height; i++)
{
//convert data
*resultPtr++ = *rawAmbient++;
result[i] = localAmbient[i];
}
GC::KeepAlive(localAmbient);

return result;
}

CameraImage^ TIVoxel::CalcPhase()
{
UShortCameraImage^ result = gcnew UShortCameraImage(m_width, m_height);
unsigned short int* resultPtr = result->Data;
ByteCameraImage^ localPhases = currentPhases;
pin_ptr<Byte> localPhasesData = &(localPhases->Data)[0];
unsigned short int *rawPhases = (unsigned short int*)localPhasesData;

unsigned short int *rawPhases = (unsigned short int*)localPhases->Data;
for (int i = 0; i < m_width*m_height; i++)
{
//covert data
*resultPtr++ = *rawPhases++;
result[i] = *rawPhases++;
}
GC::KeepAlive(localPhases);

return result;
}
@@ -559,16 +554,15 @@ CameraImage^ TIVoxel::CalcDistance()
const float scaling = range / 4096.0f; // 12-bit phase data

FloatCameraImage^ result = gcnew FloatCameraImage(m_width, m_height);
float* resultPtr = result->Data;
ByteCameraImage^ localPhases = currentPhases;
pin_ptr<Byte> localPhasesData = &(localPhases->Data)[0];
unsigned short int *rawPhases = (unsigned short int*)localPhasesData;

unsigned short int *rawPhases = (unsigned short int*)localPhases->Data;
for (int i = 0; i < m_width*m_height; i++)
{
//covert data
*resultPtr++ = *rawPhases++ * scaling;
result[i] = *rawPhases++ * scaling;
}
GC::KeepAlive(localPhases);

return result;
}
@@ -1276,11 +1270,20 @@ uint TIVoxel::GetSubFrames()
void TIVoxel::AdoptCameraData(byte* amplitudes, byte* phases, byte* ambient, int amplitudesWidth, int phasesWidth, int ambientWidth)
{
ByteCameraImage^ localPhases = gcnew ByteCameraImage(phasesWidth * this->Width * this->Height, 1);
memcpy(localPhases->Data, phases, localPhases->Width);
pin_ptr<Byte> localPhasesData = &(localPhases->Data)[0];
unsigned char * localPhasesPtr = localPhasesData;
memcpy(localPhasesPtr, phases, localPhases->Width);

ByteCameraImage^ localAmplitudes = gcnew ByteCameraImage(amplitudesWidth * this->Width * this->Height, 1);
memcpy(localAmplitudes->Data, amplitudes, localAmplitudes->Width);
pin_ptr<Byte> localAmplitudesData = &(localAmplitudes->Data)[0];
unsigned char * localAmplitudesPtr = localAmplitudesData;
memcpy(localAmplitudesPtr, amplitudes, localAmplitudes->Width);

ByteCameraImage^ localAmbient = gcnew ByteCameraImage(ambientWidth * this->Width * this->Height, 1);
memcpy(localAmbient->Data, ambient, localAmbient->Width);
pin_ptr<Byte> localAmbientData = &(localAmbient->Data)[0];
unsigned char * localAmbientPtr = localAmbientData;
memcpy(localAmbientPtr, ambient, localAmbient->Width);

this->phaseData = localPhases;
this->amplitudeData = localAmplitudes;
this->ambientData = localAmbient;
@@ -1289,7 +1292,9 @@ void TIVoxel::AdoptCameraData(byte* amplitudes, byte* phases, byte* ambient, int
void TIVoxel::AdoptFlagData(byte* flags, int flagsWidth)
{
ByteCameraImage^ localFlags = gcnew ByteCameraImage(flagsWidth * this->Width * this->Height, 1);
memcpy(localFlags->Data, flags, localFlags->Width);
pin_ptr<Byte> localFlagsData = &(localFlags->Data)[0];
unsigned char * localFlagsPtr = localFlagsData;
memcpy(localFlagsPtr, flags, localFlags->Width);

byte flag0 = localFlags->Data[0] >> 2;
// TODO somehow make this information available in MC2.
@@ -2,6 +2,8 @@
<Import Project="$(SolutionDir)MetrilusReferencesVersions.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>MetriCam2</AssemblyName>
<RootNamespace>MetriCam2</RootNamespace>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@@ -39,8 +41,8 @@
</ItemGroup>

<ItemGroup>
<Reference Include="Metrilus.Util.NetStandard">
<HintPath>$(LibrariesPath)Metrilus.Util.NetStandard.dll</HintPath>
<Reference Include="Metrilus.Util">
<HintPath>$(LibrariesPathNetStandard)Metrilus.Util.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>Z:\external-libraries\Newtonsoft.Json\v11.0.2\Bin\netstandard2.0\Newtonsoft.Json.dll</HintPath>
@@ -7,12 +7,19 @@
<PropertyGroup Label="UserMacros" Condition="'$(Configuration)'=='DebugStrongName' Or '$(Configuration)'=='ReleaseStrongName'">
<LibrariesPath>$(SolutionDir)lib_strongname\</LibrariesPath>
</PropertyGroup>
<PropertyGroup Label="UserMacros">
<LibrariesPathNetStandard>$(SolutionDir)lib_netstandard2.0\</LibrariesPathNetStandard>
</PropertyGroup>
<PropertyGroup />
<ItemDefinitionGroup />
<ItemGroup>
<BuildMacro Include="LibrariesPath">
<Value>$(LibrariesPath)</Value>
<EnvironmentVariable>true</EnvironmentVariable>
</BuildMacro>
<BuildMacro Include="LibrariesPathNetStandard">
<Value>$(LibrariesPathNetStandard)</Value>
<EnvironmentVariable>true</EnvironmentVariable>
</BuildMacro>
</ItemGroup>
</Project>
@@ -190,60 +190,62 @@ private unsafe static Bitmap ToBitmap(FloatCameraImage img)
float maxVal = float.MinValue;
float minVal = float.MaxValue;

for (int y = 0; y < img.Height; y++)
fixed (float* imgData = img.Data)
{
float* dataPtr = img.Data + y * img.Stride;
for (int x = 0; x < img.Width; x++)
for (int y = 0; y < img.Height; y++)
{
float val = *dataPtr++;
if (val > maxVal)
float* dataPtr = imgData + y * img.Stride;
for (int x = 0; x < img.Width; x++)
{
maxVal = val;
}
if (val < minVal)
{
minVal = val;
float val = *dataPtr++;
if (val > maxVal)
{
maxVal = val;
}
if (val < minVal)
{
minVal = val;
}
}
}
}

maxVal = 0.9f * maxVal;
for (int y = 0; y < img.Height; y++)
{
float* dataPtr = img.Data + y * img.Stride;
for (int x = 0; x < img.Width; x++)
maxVal = 0.9f * maxVal;
for (int y = 0; y < img.Height; y++)
{
if (*dataPtr > maxVal)
float* dataPtr = imgData + y * img.Stride;
for (int x = 0; x < img.Width; x++)
{
*dataPtr = maxVal;
if (*dataPtr > maxVal)
{
*dataPtr = maxVal;
}
dataPtr++;
}
dataPtr++;
}
}
Bitmap bitmap = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);
if (maxVal == minVal)
{
// avoid division by zero.
return bitmap;
}
Rectangle rect = new Rectangle(0, 0, img.Width, img.Height);
BitmapData bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
byte* bmpPtr = (byte*)bitmapData.Scan0;
for (int y = 0; y < img.Height; y++)
{
byte* linePtr = bmpPtr + bitmapData.Stride * y;
float* dataPtr = img.Data + y * img.Stride;
for (int x = 0; x < img.Width; x++)
Bitmap bitmap = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);
if (maxVal == minVal)
{
byte value = (byte)(byte.MaxValue * (*dataPtr++ - minVal) / (maxVal - minVal));
*linePtr++ = value;
*linePtr++ = value;
*linePtr++ = value;
// avoid division by zero.
return bitmap;
}
}
bitmap.UnlockBits(bitmapData);
GC.KeepAlive(img);
return bitmap;
Rectangle rect = new Rectangle(0, 0, img.Width, img.Height);
BitmapData bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
byte* bmpPtr = (byte*)bitmapData.Scan0;
for (int y = 0; y < img.Height; y++)
{
byte* linePtr = bmpPtr + bitmapData.Stride * y;
float* dataPtr = imgData + y * img.Stride;
for (int x = 0; x < img.Width; x++)
{
byte value = (byte)(byte.MaxValue * (*dataPtr++ - minVal) / (maxVal - minVal));
*linePtr++ = value;
*linePtr++ = value;
*linePtr++ = value;
}
}
bitmap.UnlockBits(bitmapData);
return bitmap;
}
}

private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
@@ -11,7 +11,7 @@ pipeline {

def dllsToDeployX64 = 'CookComputing.XmlRpcV2 MetriCam2.Cameras.BaslerACE MetriCam2.Cameras.BaslerToF MetriCam2.Cameras.ifm MetriCam2.Cameras.Kinect2 MetriCam2.Cameras.MatrixVision MetriCam2.Cameras.OrbbecOpenNI MetriCam2.Cameras.Sick.TiM561 MetriCam2.Cameras.Sick.VisionaryT MetriCam2.Cameras.SVS MetriCam2.Cameras.TIVoxel MetriCam2.Cameras.UEye MetriCam2.Cameras.WebCam MetriCam2.Cameras.Pico'
def dllsToDeployAnyCPU = 'Intel.RealSense log4net MathNet.Numerics MetriCam2 MetriCam2.Cameras.RealSense2 MetriCam2.Controls Metrilus.Util Newtonsoft.Json'
def dllsToDeployNetStandard = 'MetriCam2.NetStandard MetriCam2.Cameras.RealSense2.NetStandard Metrilus.Util.NetStandard'
def dllsToDeployNetStandard = 'MetriCam2 MetriCam2.Cameras.RealSense2 Metrilus.Util'
def dllsToDeployX64StrongName = 'MetriCam2.Cameras.Kinect2 MetriCam2.Cameras.OrbbecOpenNI'
def dllsToDeployAnyCPUStrongName = 'log4net MathNet.Numerics MetriCam2 MetriCam2.Controls Metrilus.Util Newtonsoft.Json'

Binary file not shown.
BIN -1.5 KB (99%) lib/Metrilus.Util.dll
Binary file not shown.
BIN +512 Bytes (100%) lib/log4net.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN +512 Bytes (100%) lib_strongname/log4net.dll
Binary file not shown.

0 comments on commit fcc48bc

Please sign in to comment.
You can’t perform that action at this time.