static void ImageWriter() { sentImageFile = new MMF(); sentImageFile.CreateNewFile(mmfProcessedFileName, 10000000); sentImageFile.AddInformation(Convert.ToBase64String(processedImage.Bytes)); }
void Kursor3DTestThread() { // TODO: Implement actAsModelerModule ThreadHelperClass.SetText(this, lblStatusValue, "Thread started. Loading images from selected folder to memory..."); ThreadHelperClass.SetText(this, lblStatusValue, "Thread started. Loading images from selected folder to memory..."); #region Test image loader Bitmap[] sourceImage; string[] Files = Directory.GetFiles(cursor3DSourceImage, "*.png"); sourceImage = new Bitmap[Files.Length]; for (int fileNumber = 0; fileNumber < Files.Length; fileNumber++) { sourceImage[fileNumber] = new Bitmap(Files[fileNumber]); } #endregion Test image loader ThreadHelperClass.SetText(this, lblStatusValue, "Images loaded. " + Files.Length + " files were added to memory"); bool isExitRequested = false; MMF mappedFile = new MMF(); mappedFile.CreateNewFile("Kursor3DSourceImage", 10000000); int position = 0; do { Stopwatch overalPerformance = new Stopwatch(); overalPerformance.Start(); // Create preview of loaded image ThreadHelperClass.SetImage(this, picImagePreview, sourceImage[position]); ThreadHelperClass.SetText(this, lblStatusValue, "Now previewing image: " + Files[position]); position++; if (position == Files.Length) { position = 0; } #region Receiver threat receiverThread = new Thread(ResultReceiver); receiverThread.Start(); #endregion Receiver threat ThreadHelperClass.SetText(this, lblStatusValue, "Writing image to memory-mapped file"); // Convert image to array and save to tempImage Stopwatch imageConversionWatcher = new Stopwatch(); imageConversionWatcher.Start(); #region Image converter byte[] tempImage; using (var ms = new MemoryStream()) { sourceImage[position].Save(ms, sourceImage[position].RawFormat); tempImage = ms.ToArray(); } #endregion Image converter imageConversionWatcher.Stop(); ThreadHelperClass.SetText(this, lblImageConversionPerformaceValue, imageConversionWatcher.ElapsedMilliseconds.ToString() + "ms"); Stopwatch MMFWatcher = new Stopwatch(); MMFWatcher.Start(); // Write the image to memory-mapped file mappedFile.AddInformation(Convert.ToBase64String(tempImage)); MMFWatcher.Stop(); ThreadHelperClass.SetText(this, lblMMFPerformanceValue, MMFWatcher.ElapsedMilliseconds.ToString() + "ms"); ThreadHelperClass.SetText(this, lblStatusValue, "File writen. Sending notification to Cursor 3D"); // Notify Kursor3D Module about the image SendReport("Kursor3DImageNotifier"); ThreadHelperClass.SetText(this, lblStatusValue, "Module connected. Now waiting for the module to complete the process"); // Wait for receiver thread to complete if (receiverThread.IsAlive) { receiverThread.Join(); } receiverThread = null; #region UI setter ThreadHelperClass.SetText(this, lblStatusValue, "Module has finished the work. Writing the received values"); ThreadHelperClass.SetText(this, lblXPositionValue, x.ToString()); ThreadHelperClass.SetText(this, lblYPositionValue, y.ToString()); ThreadHelperClass.SetText(this, lblZPositionValue, z.ToString()); ThreadHelperClass.SetText(this, lblGestureTypeValue, gestureType); overalPerformance.Stop(); ThreadHelperClass.SetText(this, lblOveralPerformanceValue, overalPerformance.ElapsedMilliseconds.ToString() + "ms"); ThreadHelperClass.SetText(this, lblKursor3DOverallPerformanceValue, kursor3DOverallPerformance.ToString() + "ms"); ThreadHelperClass.SetText(this, lblKursor3DFindHandThreadPerformanceValue, kursor3DFindHandPerformance.ToString() + "ms"); ThreadHelperClass.SetText(this, lblKursor3DFindDepthThreadPerformanceValue, kursor3DFindDepthPerformance.ToString() + "ms"); ThreadHelperClass.SetText(this, lblKursor3DGestureRecognitionThreadPerformanceValue, kursor3DgestureRecognitionPerformance.ToString() + "ms"); #endregion UI setter } while (!isExitRequested); }
void MainFunction() { ThreadHelperClass.SetText(this, lblStatusValue, "Loading sample images to memory..."); SourceImagesLoader(txtSampleImagesFolderLocation.Text); if (isSampleImageFolderEmpty) { ThreadHelperClass.SetText(this, lblStatus, "The selected folder has no images or the images is not supported"); } else { ThreadHelperClass.SetText(this, lblStatusValue, "Loading finished. " + PTAMSourceImages.Length + " images were loaded into memory."); } Thread.Sleep(100); ThreadHelperClass.SetText(this, lblStatusValue, "Preparing for sending..."); MMF mappedFile = new MMF(); mappedFile.CreateNewFile(PTAMModuleSourceImageFileName, 10000000); int position = 0; do { Stopwatch overallPerformance = new Stopwatch(); overallPerformance.Start(); // Create preview of loaded image ThreadHelperClass.SetImage(this, imgImagePreview, PTAMSourceImages[position]); ThreadHelperClass.SetText(this, lblStatusValue, "Now previewing image: " + fileNames[position]); position++; if (position == fileNames.Length) { position = 0; } #region Receiver threat receiverThread = new Thread(ResultReceiver); receiverThread.Start(); #endregion Receiver threat ThreadHelperClass.SetText(this, lblStatusValue, "Writing image to memory-mapped file"); #region Image converter // Convert image to array and save to tempImage Stopwatch imageConversionWatcher = new Stopwatch(); imageConversionWatcher.Start(); byte[] tempImage; using (var ms = new MemoryStream()) { PTAMSourceImages[position].Save(ms, PTAMSourceImages[position].RawFormat); tempImage = ms.ToArray(); } imageConversionWatcher.Stop(); testerImageConversionPerformance = imageConversionWatcher.ElapsedMilliseconds; #endregion Image converter #region Memory-Mapped File writing Stopwatch MMFWatcher = new Stopwatch(); MMFWatcher.Start(); // Write the image to memory-mapped file mappedFile.AddInformation(Convert.ToBase64String(tempImage)); MMFWatcher.Stop(); testerMemoryMappedFilePerformance = MMFWatcher.ElapsedMilliseconds; #endregion Memory-Mapped File writing ThreadHelperClass.SetText(this, lblStatusValue, "File writen. Sending notification to PTAM Module"); // Notify Kursor3D Module about the image SendReport(PTAMModuleNamedPipeSendingChannel); ThreadHelperClass.SetText(this, lblStatusValue, "Module connected. Now waiting for the module to complete the process"); // Wait for receiver thread to complete if (receiverThread.IsAlive) { receiverThread.Join(); } receiverThread = null; ThreadHelperClass.SetText(this, lblStatusValue, "Module has finished the work. Writing the received values"); #region UI setter #region Pose #region Position ThreadHelperClass.SetText(this, lblPositionXValue, receivedXPosition.ToString()); ThreadHelperClass.SetText(this, lblPositionYValue, receivedYPosition.ToString()); ThreadHelperClass.SetText(this, lblPositionZValue, receivedZPosition.ToString()); #endregion Position #region Orientation ThreadHelperClass.SetText(this, lblOrientationXValue, receivedXOrientation.ToString()); ThreadHelperClass.SetText(this, lblOrientationYValue, receivedYOrientation.ToString()); ThreadHelperClass.SetText(this, lblOrientationZValue, receivedZOrientation.ToString()); #endregion Orientation #endregion Pose #region Points ThreadHelperClass.SetText(this, lblTotalPointCreatedValue, totalPointsCreated.ToString()); #endregion Points overallPerformance.Stop(); testerOverallPerformance = overallPerformance.ElapsedMilliseconds; ThreadHelperClass.SetText(this, lblOverallPerformanceValue, testerOverallPerformance.ToString() + "ms"); ThreadHelperClass.SetText(this, lblMemoryMappedFilePerformanceValue, testerMemoryMappedFilePerformance.ToString() + "ms"); ThreadHelperClass.SetText(this, lblImageConversionPerformanceValue, testerImageConversionPerformance.ToString() + "ms"); ThreadHelperClass.SetText(this, lblPTAMModuleOverallPerformanceValue, PTAMModuleOverallPerformance.ToString() + "ms"); ThreadHelperClass.SetText(this, lblPTAMModuleTrackingPerformanceValue, PTAMTrackingPerformance.ToString() + "ms"); ThreadHelperClass.SetText(this, lblPTAMModuleMappingPerformanceValue, PTAMMappingPerformance.ToString() + "ms"); ThreadHelperClass.SetText(this, lblPTAMModuleImageConversionPerformanceValue, PTAMImageConversionPerformance.ToString() + "ms"); ThreadHelperClass.SetText(this, lblPTAMModuleMemoryMappedFileReadingPerformanceValue, PTAMMemoryMappedFileReadingPerformance.ToString() + "ms"); #endregion UI setter } while (!isExitRequested); }