本文介绍了我的错是什么?我无法收集RGB和IR图像。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Kinect;
using System.Xaml;
using System.IO;
namespace camerashot
{
/// <summary>
/// Логика взаимодействия для MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
int check = 0;
int checkir = 0;
int number = 1;
KinectSensor sensor, sensor2;
public MainWindow()
{
sensor = KinectSensor.KinectSensors[0];
InitializeComponent();
sensor.Start();
if (check == 0)
{
sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
sensor.ColorFrameReady += colorframeReady;
sensor.ColorStream.Disable();
}
if (checkir == 0)
{
sensor.ColorStream.Enable(ColorImageFormat.InfraredResolution640x480Fps30);
sensor.ColorFrameReady += irframeReady;
sensor.ColorStream.Disable();
}
}
/////////////////////////////////////////////
public void irframeReady(object sender, ColorImageFrameReadyEventArgs e)
{
ColorImageFrame IR = e.OpenColorImageFrame();
if (IR == null) { return; }
byte[] IRpixels = new byte[IR.PixelDataLength];
IR.CopyPixelDataTo(IRpixels);
if (checkir == 0)
{
int strideir = IR.Width * IR.BytesPerPixel;
BitmapEncoder irencoder= new PngBitmapEncoder();
irencoder.Frames.Add(BitmapFrame.Create(BitmapSource.Create(
IR.Width, IR.Height, 96, 96, PixelFormats.Gray16, null, IRpixels, strideir)));
string irpath = System.IO.Path.Combine(@"C:\my3dclouds\calibration\","b"+ number.ToString() + ".png");
try
{
using (FileStream fs = new FileStream(irpath, FileMode.Create))
{
irencoder.Save(fs);
}
}
catch (IOException ioe)
{
Console.WriteLine(ioe.ToString());
}
checkir = 1;
}
}
public void colorframeReady(object sender, ColorImageFrameReadyEventArgs e)
{
ColorImageFrame DIF = e.OpenColorImageFrame();
if (DIF == null) { return; }
byte[] pixels = new byte[DIF.PixelDataLength];
DIF.CopyPixelDataTo(pixels);
if (check == 0)
{
int stride = DIF.Width * DIF.BytesPerPixel;
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(BitmapSource.Create(
DIF.Width, DIF.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride)));
string path = System.IO.Path.Combine( @"C:\my3dclouds\calibration\", "a"+number.ToString() + ".png");
try
{
using (FileStream fs = new FileStream(path, FileMode.Create))
{
encoder.Save(fs);
}
}
catch (IOException ioe)
{
Console.WriteLine(ioe.ToString());
}
check = 1;
}
}
public void shot_Click(object sender, RoutedEventArgs e)
{
number++;
check = 0;
sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
sensor.ColorFrameReady += colorframeReady;
sensor.ColorStream.Disable();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
checkir = 0;
sensor.ColorStream.Enable(ColorImageFormat.InfraredResolution640x480Fps30);
sensor.ColorFrameReady += irframeReady;
sensor.ColorStream.Disable();
}
////////////////////////////////////////
}
}
推荐答案
如果您使用的是v1传感器和SDK,这不是正确的论坛,您应该发布
。
In case you are working with v1 sensor and SDK this is not the proper forum, you should posthere.
无论如何它似乎您正在启用它后禁用ColorStream,这将无法正常工作。查看v1 Toolkit示例,了解如何使用ColorStream。
Anyway it seems you are disabling ColorStream just after enabling it and this won't work. Look at the v1 Toolkit samples to see how you should work with ColorStream.
这篇关于我的错是什么?我无法收集RGB和IR图像。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!