【发布时间】:2015-06-09 14:19:07
【问题描述】:
我使用 Kinect v2 录制了深度视频,当我使用 MATLAB 提取图像时,每个 image 是 3 通道。通常我看到的图像只有 1 个通道。请任何人告诉我如何将这个 3 通道图像转换为 1 通道?
这里是深度部分的代码:
IplImage depth = new IplImage(512, 424, BitDepth.U16, 1);
CvVideoWriter DepthWriter;
Width = sensor.DepthFrameSource.FrameDescription.Width;
DHeight = sensor.DepthFrameSource.FrameDescription.Height;
WbDepth = new WriteableBitmap(DWidth, DHeight, 96, 96, PixelFormats.Gray16, null);
int depthshft = (int)SliderDepth.Value;
using (DepthFrame depthframe = frame.DepthFrameReference.AcquireFrame())
ushort* depthdata = (ushort*)depth.ImageData;
if (depthframe != null)
{
Depthdata = new ushort[DWidth * DHeight];
ushort[] Depthloc = new ushort[DWidth * DHeight];
depthframe.CopyFrameDataToArray(Depthdata);
for (int i = 0; i < DWidth * DHeight; i++)
{
Depthloc[i] = 0x1000;
}
colorspacePoint = new ColorSpacePoint[DWidth * DHeight];
depthspacePoint = new DepthSpacePoint[CWidth * CHeight];
sensor.CoordinateMapper.MapDepthFrameToColorSpace(Depthloc, colorspacePoint);
for (int y = 0; y < DHeight; y++)
{
for (int x = 0; x < DWidth; x++)
{
if (depthshft != 0)
{
Depthdata[y * DWidth + x] = (ushort)((Depthdata[y * DWidth + x]) << depthshft);
}
}
}
depth.CopyPixelData(Depthdata);
}
WbDepth.WritePixels(new Int32Rect(0, 0, DWidth, DHeight), Depthdata, strideDep, 0);
ImageDepth.Source = WbDepth;
if (depth != null && DepthWriter.FileName != null) Cv.WriteFrame(DepthWriter, depth);
Cv.ReleaseVideoWriter(DepthWriter);
if (CheckBox_saveD.IsChecked == true)
DepthWriter = new CvVideoWriter(string.Format("{1}\\Scene{0}_DepthRecord.avi", scene, TextBlock_saveloca.Text.ToString()), FourCC.Default, 30.0f, new CvSize(512, 424));
CheckBox_saveD.IsEnabled = false;
if (CheckBox_saveD.IsChecked == true) Cv.ReleaseVideoWriter(DepthWriter);
谢谢
【问题讨论】:
-
将其转换为灰度:mathworks.com/help/matlab/ref/rgb2gray.html。但是,如果图像无论如何都显示为灰色,那么每个通道都有相同的值,实际上你最好放弃其他两个通道。
-
将3通道深度图像转换为灰度图像改变深度值?
-
如果每个元素的值在每个通道中都相同,则不会。如果它们不同,那么你不能这样做。不过我的猜测是,您用来在 Matlab 中加载图像的任何函数默认转换为 3 个通道(例如
imshow所做的)。在这种情况下,转换为灰度不会改变值 -
每个频道的每个元素都不相同......那么知道我该怎么做吗?
-
然后你需要发布你如何捕获数据并将其加载到matlab中的代码
标签: matlab opencv image-processing kinect