//Takes image from Kinect //static void TakeImage() //{ // //Declares variables to take a color image // ImageGenerator image = context.FindExistingNode(NodeType.Image) as ImageGenerator; // ImageMetaData imageMD = new ImageMetaData(); // MapOutputMode mapMode = image.MapOutputMode; // context.WaitOneUpdateAll(image); // // Take current image // image.GetMetaData(imageMD); // byte[] RGB = new byte[imageMD.DataSize]; // int width = (int)mapMode.XRes; // int height = (int)mapMode.YRes; // image.GetRGB24ImageMap(); // //WriteableBitmap imageBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Rgb24, null); // //Bitmap imageBitmap1 = new Bitmap(width, height); // // width, height, 96, 96, PixelFormats.Rgb24, null); // //imageBitmap.Save( //} static void Main(string[] args) { //Calls Start() Kinect k = new Kinect(); TextReader tIn = Console.In; TextWriter tOut = Console.Out; string output = TakeData(); tOut.WriteLine(output); //Waits for input to take data //Console.WriteLine("Press enter to take data"); //Console.ReadLine(); ////Defines the string user as an empty string //string user = "******"; ////Repeats until the program breaks //while (true) //{ // if (user == "E" || user == "e") // break; // else if (user == "") // { // //Takes data // TakeData(); // //Asks for input and defines user as the input // Console.WriteLine("Press enter to take data or type E to exit"); // user = Console.ReadLine(); // } // else // { // //Takes data defining the name as the user input // TakeData(user); // //Asks for input and defines user as the input // Console.WriteLine("Press enter to take data or type E to exit"); // user = Console.ReadLine(); // } //} }
////Takes image from Kinect //static void TakeImage(string filename) //{ // //Declares variables to take a color image // ImageGenerator image = context.FindExistingNode(NodeType.Image) as ImageGenerator; // ImageMetaData imageMD = new ImageMetaData(); // MapOutputMode mapMode = image.MapOutputMode; // context.WaitOneUpdateAll(image); // // Take current image // image.GetMetaData(imageMD); // byte[] RGB = new byte[imageMD.DataSize]; // int width = (int)mapMode.XRes; // int height = (int)mapMode.YRes; // image.GetRGB24ImageMap(); // // WriteableBitmap imageBitmap1 = new WriteableBitmap(width, height, 96, 96, PixelFormats.Rgb24, null); // // Bitmap imageBitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); // unsafe // { // MapOutputMode mapImaMode = image.MapOutputMode; // Bitmap g_TexMap = new Bitmap((int)mapMode.XRes, (int)mapMode.YRes, System.Drawing.Imaging.PixelFormat.Format24bppRgb); // Bitmap imageBitmap = new Bitmap((int)mapImaMode.XRes, (int)mapImaMode.YRes, System.Drawing.Imaging.PixelFormat.Format24bppRgb); // Rectangle rectIma = new Rectangle(0, 0, imageBitmap.Width, imageBitmap.Height); // System.Drawing.Imaging.BitmapData dataIma = imageBitmap.LockBits(rectIma, ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); // byte* pIma = (byte*)image.ImageMapPtr; // // set pixels // for (int y = 0; y < imageMD.YRes; ++y) // { // byte* pDest = (byte*)dataIma.Scan0.ToPointer() + y * dataIma.Stride; // for (int x = 0; x < imageMD.XRes; ++x) // { // *(pDest++) = *(pIma++); // blue // *(pDest++) = *(pIma++); // green // *(pDest++) = *(pIma++); // red // } // } // // RGB24Pixel* pDepth = (RGB24Pixel*)this.img.ImageMapPtr.ToPointer(); // //RGB24Pixel* pDepth = (RGB24Pixel*)imageMD.ImageMapPtr.ToPointer(); // //Rectangle rectIma = new Rectangle(0, 0, imageBitmap.Width,imageBitmap.Height); // //System.Drawing.Imaging.BitmapData dataIma = imageBitmap.LockBits(rectIma, ImageLockMode.WriteOnly, // // System.Drawing.Imaging.PixelFormat.Format24bppRgb); // //imageBitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg); // //for (int y = 0; y < imageMD.YRes; ++y) // //{ // // byte* pDest = (byte*)data.Scan0.ToPointer() + y * data.Stride; // // for (int x = 0; x < imageMD.XRes; ++x, ++pDepth, pDest += 3) // // { // // byte pixel = (byte)histogram[*pDepth]; // // pDest[0] = 0; // // pDest[1] = pixel; // // pDest[2] = pixel; // // } // //} // imageBitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg); // } //} static void Main(string[] args) { //Calls Start() Kinect k = new Kinect(); ////Creates a text reader and writer to interact with the console //TextReader tIn = Console.In; //TextWriter tOut = Console.Out; ////Writes line //tOut.WriteLine("Data Collecting: Press any key to stop"); ////Creates an array list to store the depth data //ArrayList depths = new ArrayList(); ////Creates count to track how many times data is taken //int count = 0; ////Until a key is pressed, takes data after every update of depth information and adds it to the list //while (!Console.KeyAvailable) //{ // depths.Add(TakeData()); // count++; //} ////Displays the count and shows a waiting message //tOut.WriteLine(count); //tOut.WriteLine("Data Collection Stopped: Please Wait"); ////Creates a string of the current time and date in format Month Day Year Hour Minute Seconds //string filename = "b" + DateTime.Now.ToString("MMddyyHHmmss"); //int fcount = 1; ////Writes each set of to a text file //foreach (UInt16MapData d in depths) //{ // //Opens the text writer and creates a new file with the a and the time as the file name // TextWriter tw = new StreamWriter(@"D:\Users\CenSSIS\Documents\Kinect_Project\Test Files\Shaw XBS 8 1\" + filename + fcount.ToString() + ".txt"); // //Sets height and width to the X and Y resolutions // int height = mapMode.YRes; // int width = mapMode.XRes; // //For each pixel, writes a line of text: x y depth // for (int h = 0; h < height; ++h) // { // for (int w = 0; w < width; ++w) // { // tw.WriteLine(w + " " + h + " " + d[w, h]); // } // } // //Closes the text writer // tw.Close(); // fcount++; //} //Creates a text reader and writer to interact with the console TextReader tIn = Console.In; TextWriter tOut = Console.Out; //Gets the filenmae from the console string filename = tIn.ReadLine(); //filename = "D:\\Users\\CenSSIS\\Documents\\Kinect_Project\\Test files\\" + filename; //Takes data with the filename if(filename == "run") { while (true) { TakeData(); } } else { TakeData(filename); } string output = TakeData(filename); }