Ok so I started writing an app following the how-to-kinect series from Microsoft and everything was going well until I wrote this:
using (InfraredFrame IRFrame = args.FrameReference.AcquiredFrame())
{
}
For some reason it keeps saying args does not exist in the current context and I have no idea why..here is my full code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Media.Imaging;
using WindowsPreview.Kinect;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace KinectApp1
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}
/*Getting the Kinect Sensor*/
KinectSensor Sensor;
/*Getting the Infared Reader*/
InfraredFrameReader IRReader;
/*This is IR Data Form*/
ushort[] IRData;
/*Converting the Data (Buffer) */
byte[] IRDataConverted;
/*Writing the Bitmap Image Described in XAML*/
WriteableBitmap IRBitmap;
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
/*Get the sensor in the loaded frame*/
Sensor = KinectSensor.GetDefault();
/*Get the reader from the Source on the Sensor*/
IRReader = Sensor.InfraredFrameSource.OpenReader();
/*Frame Description for the Infrared and see how big they are*/
FrameDescription FD = Sensor.InfraredFrameSource.FrameDescription;
IRData = new ushort[FD.LengthInPixels];
IRDataConverted = new byte[FD.LengthInPixels * 4];
IRBitmap = new WriteableBitmap(FD.Width, FD.Height);
Image.Source = IRBitmap;
/*Start Sensor*/
Sensor.Open();
/*Subscribe to the event off the Reader*/
IRReader.FrameArrived += IRReader_FrameArrived;
}
void IRReader_FrameArrived(InfraredFrameReader sender, InfraredFrameArrivedEventArgs e)
{
using (InfraredFrame IRFrame = args.FrameReference.AcquiredFrame())
{
if (IRFrame != null)
{
IRFrame.CopyFrameDataToArray(IRData);
for (int i = 0; i < IRData.Length; i++)
{
byte intensity = (byte)(IRData[i]>>8);
IRDataConverted[i*4] = intensity;
IRDataConverted[i*4 + 1] = intensity;
IRDataConverted[i*4 + 2] = intensity;
IRDataConverted[i*4 + 3] = 255;
}
IRDataConverted.CopyTo(IRBitmap.PixelBuffer);
IRBitmap.Invalidate();
}
}
}
}
}
Can anyone kindly explain why this has happened? I am pretty confused,
Thanks in Advance.
P.S this is the video I was following:
http://www.microsoft.com/en-us/kinectforwindows/develop/how-to-videos.aspx
Well it's been answered so I'm not sure what else to do apart from answer it:
As Preston Guillot said in the comments:
"There is no variable named args in scope in the IRReader_FrameArrived method. You have a parameter of type InfraredFrameArrivedEventArgs named e that I'm guessing you meant to use"
Related
I'm learning wpf and at the same time developing an app with it. I'm having a hard time figuring out how i can run something when a doubleanimation (Or other sorts) is done. For instance:
DoubleAnimation myanim = new DoubleAnimation();
myanim.From = 10;
myanim.To = 100;
myanim.Duration = new Duration(TimeSpan.FromSeconds(3));
myview.BeginAnimation(Button.OpacityPropert, myanim);
//Code to do something when animation ends
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 System.Windows.Media.Animation;
namespace app
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
DoubleAnimation widthbutton = new DoubleAnimation();
widthbutton.From = 55;
widthbutton.To = 100;
widthbutton.Duration = new Duration(TimeSpan.FromSeconds(1.5));
button1.BeginAnimation(Button.HeightProperty, widthbutton);
DoubleAnimation widthbutton1 = new DoubleAnimation();
widthbutton1.From = 155;
widthbutton1.To = 200;
widthbutton1.Duration = new Duration(TimeSpan.FromSeconds(1.5));
button1.BeginAnimation(Button.WidthProperty, widthbutton1);
widthbutton.Completed += new EventHandler(myanim_Completed);
}
private void myanim_Completed(object sender, EventArgs e)
{
//your completed action here
MessageBox.Show("Animation done!");
}
}
}
How is this accomplishable? I have read quite a few other posts about this, but they all explain it using xaml, however i would like to do it using c# code. Thanks!
You can attach an event handler to the DoubleAnimation's Completed event.
myanim.Completed += new EventHandler(myanim_Completed);
private void myanim_Completed(object sender, EventArgs e)
{
//your completed action here
}
Or, if you prefer it inline, you can do
myanim.Completed += (s,e) =>
{
//your completed action here
};
Remember to attach the handler before starting the animation otherwise it won't fire.
When I Run the Warning
RDotNet.NativeLibrary.UnmanagedDll.SetDllDirectory(string) is obsolete Set environment variable 'PATH' instead.
I don't know how to do that. how to set variable path please help quickly please.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RDotNet;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
string dlldir = #"C:\Program Files\R\R-3.1.1\bin\x64";
REngine.SetDllDirectory(dlldir);
REngine.CreateInstance("RDotNet");
}
private void button1_Click(object sender, EventArgs e)
{
REngine engine = REngine.GetInstanceFromID("RDotNet");
try
{
// import csv file
engine.Evaluate("dataset<-read.table(file.choose(), header=TRUE, sep = ',')");
// retrieve the data frame
DataFrame dataset = engine.Evaluate("dataset").AsDataFrame();
for (int i = 0; i < dataset.ColumnCount; ++i)
{
dataGridView1.ColumnCount++;
dataGridView1.Columns[i].Name = dataset.ColumnNames[i];
}
for (int i = 0; i < dataset.RowCount; ++i)
{
dataGridView1.RowCount++;
dataGridView1.Rows[i].HeaderCell.Value = dataset.RowNames[i];
for (int k = 0; k < dataset.ColumnCount; ++k)
{
dataGridView1[k, i].Value = dataset[i,k];
}
}
}
catch
{
MessageBox.Show(#"Equation error.");
}
}
}
}
If you want to know how can you set or edit environment variables in windows, you can use this link:
Set Environment Variable
PATH includes several addresses, and maybe you should add your dlldir address to this variable.
You are using an outdated version of R.NET; see the online documentation for instruction and sample code on how to install and use the current API (version 1.5.15 or above)
I have created a sample app in which there are two pages.
1st page contains button, on tapping it takes to second page. In second page there is a list of 100 elements.
In this sample I have navigated to and fro from this second page.
So why is this memory increasing and why is not going down completely on going back to first page and why page destructor never gets called?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Media.Imaging;
using System.IO;
using System.Diagnostics;
namespace PhoneApp1
{
public partial class Page1 : PhoneApplicationPage
{
public Page1()
{
InitializeComponent();
for (int i = 0; i < 100; i++)
{
listBitmapImage.Add(new Test(i));
}
}
List<Test> listBitmapImage = new List<Test>();
protected override void OnRemovedFromJournal(JournalEntryRemovedEventArgs e)
{
base.OnRemovedFromJournal(e);
}
~Page1()
{
Debug.WriteLine("IN DESTRUCTOR");
}
}
public class Test
{
int _a;
string img = "iVBORw0KGgoAAAANSUhEUgAAALEAAACzCAMAAADxPw38AAADAFBMVEXCwsI9P0DGxsYiIVQiIVUjIlje39/W1tbQ0NDPz8+Wl5jLy8tQUVWPkJEiIVeCg4Pf4ODW1tYkI1kkI1mJiouDhYW5urri4uLY2dnX19ckJFEwMjKen5+6u7uoqKiCg4O+v7/b3NwrLEeur6+xsbKcnZ2+v784OUDj4+PY2Njg4eHf4ODGx8c0NEmoqanR0dLMzMw5OkNhYmK6u7vc3d3T09TQ0NHc3d0MDg8GCQkjIlfh4eF9fn/BwsKQkZLi4uJcXl7V1dUSFBQGCQkFBwgFCAkHCQkEBwcFBwgGCAkGCAkFCAoGCAoGCAgEBwcGCAoQEhIGCAkFCAk9PkAAAAC+tq4qKkKDa1T6xL2KZkSae3H70875vLXTtZbCzM76/P37ysTJnmwTDwq2gUrSr4f5sqmXVCOuuLrYupq+i07w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ZnppQm7odAlpnDnV8PgGPz61NxGPmiBQjHCsmglTbghNh75ysmKppez4W3Ic7WqHwCIuacqWpMKat73R6M1y6FoNPEQpGOB7L+HNKSa+1OdOQAKpNpfGhGntcVw3/h2MtZGPbEMK09aQaIvDuuBs0gxQjnqUlU+fdprVPjCFvU5QhoiCypwBcHtNSZigDzXZPW/L04nmvvtDNpKdWbK9sMUQlRRlaituUq1b4CHEzaESJaa3p5zVx1XLCnJZkeXc06GSuJ7Sp4AzD0hdgnzEKHyXLSb8OH+TFV9ivqxhZYvpdf36+Hou6SZC4Xm+y/JrbOggFE8TQphII5H6uy8Hf7u4DRNS33SZIyFeCjDgxe8pC7OcxZdEMy5CsnDGRL8dcdHf3RXNwfm3KBOrfB0XMfgmkj7fHnIXzVj09fcmo6asWjfGAk4IK9htcPBcufmnVXLdXvE3fovfgv7nSH86ziCVwHIjng82PL+JeeDihw/fj+fGFYvzXD75fwTnPIpDJsclkAoW1dmQyGd2AfeDfXDnC9r8dks5B15XK3QAAAABJRU5ErkJggg==";
string img_1, img_2, img3, img4;
public Test(int a)
{
_a = a;
img = a + img;
img_1 = a + "1" + img;
img_2 = a + "2" + img;
img3 = a + "3" + img;
img4 = a + "4" + img;
Debug.WriteLine("CONSTRUCTOR:{0}", _a);
}
~Test()
{
Debug.WriteLine("DESTRUCTOR:{0}", _a);
}
}
}
Here's a link to download sample project.
If yo are using BitmapImage, It had memory issue in windows phone 8 already. That may be the reason you are getting memory issue. Please find a similar issue here
Also this link give you more idea about the issue
I am working on a project which involves extracting features from color and depth frames from Kinect Camera. The problem I am facing is that whenever I try displaying 2 Images, the UI hangs. When I tried debugging, the depthFrame and colorFrame were coming as null. If enable only the color steam then both colorImage and featureImage1 are displayed properly and if I enable only the depth stream, it works as it should. But when I enable them both, the UI hangs. I have no idea what is causing the problem. I have the following the following code for my Kinect Application. What is the cause of this problem and how can I fix it?
Config: Windows 8 Pro 64bit, 2Ghz Core2Duo, VisualStudio 2012 Ultimate, EmguCV 2.4.0.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
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 Emgu.CV;
using Emgu.CV.WPF;
using Emgu.CV.Structure;
using Emgu.Util;
namespace features
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private Image<Bgra, Byte> cvColorImage;
private Image<Gray, Int16> cvDepthImage;
private int colorWidth = 640;
private int colorHeight = 480;
private int depthWidth = 640;
private int depthHeight = 480;
private static readonly int Bgr32BytesPerPixel = (PixelFormats.Bgr32.BitsPerPixel + 7) / 8;
private byte[] colorPixels;
private byte[] depthPixels;
private short[] rawDepthData;
private bool first = true;
private bool firstDepth = true;
Image<Bgra, byte> image2;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
kinectSensorChooser.KinectSensorChanged += new DependencyPropertyChangedEventHandler(kinectSensorChooser_KinectSensorChanged);
}
void kinectSensorChooser_KinectSensorChanged(object sender, DependencyPropertyChangedEventArgs e)
{
KinectSensor oldSensor = (KinectSensor)e.OldValue;
KinectStop(oldSensor);
KinectSensor _sensor = (KinectSensor)e.NewValue;
_sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
_sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
_sensor.DepthFrameReady += new EventHandler<DepthImageFrameReadyEventArgs>(_sensor_DepthFrameReady);
_sensor.ColorFrameReady += new EventHandler<ColorImageFrameReadyEventArgs>(_sensor_ColorFrameReady);
_sensor.DepthStream.FrameHeight);
try
{
_sensor.Start();
}
catch
{
kinectSensorChooser.AppConflictOccurred();
}
}
void KinectStop(KinectSensor sensor)
{
if (sensor != null)
{
sensor.Stop();
}
}
private void Window_Closed(object sender, EventArgs e)
{
KinectStop(kinectSensorChooser.Kinect);
}
void _sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
{
using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
{
if (colorFrame == null) return;
if (first)
{
this.colorPixels = new Byte[colorFrame.PixelDataLength];
first = false;
}
colorFrame.CopyPixelDataTo(this.colorPixels); //raw data in bgrx format
processColor();
}
}
void _sensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
{
if (depthFrame == null) return;
if (firstDepth)
{
this.rawDepthData = new short[depthFrame.PixelDataLength];
firstDepth = false;
}
depthFrame.CopyPixelDataTo(rawDepthData);
processDepth();
}
}
private void processColor(){...}
private void processDepth(){...}
}
}
The processDepth function is as follows. I am just making an Image from the RAW depth data.
private void processDepth() {
GCHandle pinnedArray = GCHandle.Alloc(this.rawDepthData, GCHandleType.Pinned);
IntPtr pointer = pinnedArray.AddrOfPinnedObject();
cvDepthImage = new Image<Gray, Int16>(depthWidth, depthHeight, depthWidth << 1, pointer);
pinnedArray.Free();
depthImage.Source = BitmapSourceConvert.ToBitmapSource(cvDepthImage.Not().Bitmap);
}
The processColor function is as follows. Here just for the sake of it, I am trying to display the cloned image instead of extracting features, just to check the lag. When both streams are enabled (color and depth) the following function displays the colorImage properly, but as soon as I uncomment the commented lines, the UI hangs.
private void processColor() {
GCHandle handle = GCHandle.Alloc(this.colorPixels, GCHandleType.Pinned);
Bitmap image = new Bitmap(colorWidth, colorHeight, colorWidth<<2, System.Drawing.Imaging.PixelFormat.Format32bppRgb, handle.AddrOfPinnedObject());
handle.Free();
cvColorImage = new Image<Bgra, byte>(image);
image.Dispose();
BitmapSource src = BitmapSourceConvert.ToBitmapSource(cvColorImage.Bitmap);
colorImage.Source = src;
//image2 = new Image<Bgra, byte>(cvColorImage.ToBitmap()); //uncomment and it hangs
//featureImage1.Source = BitmapSourceConvert.ToBitmapSource(image2.Bitmap); //uncomment and it hangs
}
I see code that do a lot of work in event handlers. I almost certain that handlers is called in GUI thread. I suggest you to extract your code to the background thread routine. Don't forget that updating of the Form's controls (depthImage and controlImage) should be done using BeginInvoke method of the parent form,
I've been searching the internet and I haven't had any luck. I'm using an Xbox Kinect with the Kinect SDK v1.0. I want to take the raw depth data and convert it into a text document so I can use the depth data. I found something on this site but it was for the Beta2 and I need to use v1.0. Any help is appreciated but I am new to coding so sample code would be best.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Diagnostics;
using System.IO;
namespace DepthTextStream
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
const float MaxDepthDistance = 4095; // max value returned
const float MinDepthDistance = 850; // min value returned
const float MaxDepthDistanceOffset = MaxDepthDistance - MinDepthDistance;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
kinectSensorChooser1.KinectSensorChanged += new DependencyPropertyChangedEventHandler(kinectSensorChooser1_KinectSensorChanged);
}
void kinectSensorChooser1_KinectSensorChanged(object sender, DependencyPropertyChangedEventArgs e)
{
var oldSensor = (KinectSensor)e.OldValue;
//stop the old sensor
if (oldSensor != null)
{
oldSensor.Stop();
oldSensor.AudioSource.Stop();
}
//get the new sensor
var newSensor = (KinectSensor)e.NewValue;
if (newSensor == null)
{
return;
}
//turn on features that you need
newSensor.DepthStream.Enable(DepthImageFormat.Resolution320x240Fps30);
newSensor.SkeletonStream.Enable();
//sign up for events if you want to get at API directly
newSensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(newSensor_AllFramesReady);
try
{
newSensor.Start();
}
catch (System.IO.IOException)
{
//this happens if another app is using the Kinect
kinectSensorChooser1.AppConflictOccurred();
}
}
void newSensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
{
short[] depthData;
using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) //create a new frame every time one is ready
{
//assign a value to depthData
depthData = new short[depthFrame.PixelDataLength];
}
}
private void SaveDepthData(short[] depthData)
{
//initialize a StreamWriter
StreamWriter sw = new StreamWriter(#"C:/Example.txt");
//search the depth data and add it to the file
for (int i = 0; i < depthData.Length; i++)
{
sw.WriteLine(depthData[i] + "\n"); //\n for a new line
}
//dispose of sw
sw.Close();
SaveDepthData(depthData);
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
StopKinect(kinectSensorChooser1.Kinect);
}
private void StopKinect(KinectSensor sensor)
{
if (sensor != null)
{
if (sensor.IsRunning)
{
//stop sensor
sensor.Stop();
//stop audio if not null
if (sensor.AudioSource != null)
{
sensor.AudioSource.Stop();
}
}
}
}
}
}
This is pretty simple using version 1.5.0.1, which is practically the same as version 1.0 and will work on it. All you need to complete this is A)a short[] to hold the depth data B)a DepthImageFrame to move the data to the array, and C)A StreamWriter to save the data.
Add a short[] to store your depth data, and inside of your DepthFrameReadyEventArgs (or AllFramesReadyEventArgs) you "use" a DepthImageFrame by doing:
short[] depthData;
...
using (DepthImageFrame depthFrame = e.OpenDepthImageFrame(()) //create a new frame every time one is ready
{
//assign a value to depthData
depthData = new short[depthFrame.PixelDataLength];
}
Then you can add the depth from each frame to depthData using DepthImageFrame.CopyPixelDataTo
using (DepthImageFrame depthFrame = e.OpenDepthImageFrame(()) //create a new frame every time one is ready
{
//assign a value to depthData
depthData = new short[depthFrame.PixelDataLength];
//add raw depth data to depthData
depthFrame.CopyPixelDataTo(depthData);
}
Then we can write a method to save our data using a StreamWriter.
private void SaveDepthData(short[] depthData)
{
//initialize a StreamWriter
StreamWriter sw = new StreamWriter(#"C:/Example.txt");
//search the depth data and add it to the file
for (int i = 0; i < depthData.Length; i++)
{
sw.WriteLine(depthData[i] + "\n"); //\n for a new line
}
//dispose of sw
sw.Close();
}
...
SaveDepthData(depthData);
Hope this helps!