Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/Bonsai.ML.Torch/OpenCVHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenCV.Net;
using TorchSharp;
using static TorchSharp.torch;

namespace Bonsai.ML.Torch
Expand Down Expand Up @@ -32,13 +33,15 @@ public static Tensor ToTensor(IplImage image, Device device)
if (image == null)
return empty([ 0, 0, 0 ]);

int height = image.Height;
int channels = image.Channels;
var width = image.WidthStep / channels;

var iplDepth = image.Depth;
var tensorType = bitDepthLookup.FirstOrDefault(x => x.Value.IplDepth == iplDepth).Key;

int height = image.Height;
int channels = image.Channels;
int elementSize = tensorType.ElementSize();
int stride = image.WidthStep / elementSize;
var width = stride / channels;

IntPtr data = image.ImageData;
ReadOnlySpan<long> dimensions = stackalloc long[] { height, width, channels };

Expand Down