示例#1
0
        private IEnumerator CaptureData()
        {
            while (state != StatusMode.Finished)
            {
                agent.isStopped = true;
                yield return(new WaitForEndOfFrame());

                string robotTransform = GetTransformString();
                if (captureRGB)
                {
                    logImgWriter.WriteLine(index.ToString() + "_rgb.jpg," +
                                           robotTransform + "," +
                                           smartCamera.GetTransformString() + "," +
                                           currentRoom);
                    File.WriteAllBytes(filePath + "/" + index.ToString() + "_rgb.jpg", smartCamera.CaptureImage(SmartCamera.ImageType.RGB).EncodeToJPG());
                }
                if (captureDepth)
                {
                    logImgWriter.WriteLine(index.ToString() + "_depth.png," +
                                           robotTransform + "," +
                                           smartCamera.GetTransformString() + "," +
                                           currentRoom);
                    File.WriteAllBytes(filePath + "/" + index.ToString() + "_depth.png", smartCamera.CaptureImage(SmartCamera.ImageType.Depth).EncodeToPNG());
                }
                if (captureSemanticMask)
                {
                    logImgWriter.WriteLine(index.ToString() + "_mask.jpg," +
                                           robotTransform + "," +
                                           smartCamera.GetTransformString() + "," +
                                           currentRoom);
                    File.WriteAllBytes(filePath + "/" + index.ToString() + "_mask.jpg", smartCamera.CaptureImage(SmartCamera.ImageType.InstanceMask).EncodeToJPG());
                }
                if (captureScan)
                {
                    string data = "";
                    foreach (float d in laserScan.Scan())
                    {
                        data += "," + d.ToString("F15", CultureInfo.InvariantCulture);
                    }
                    logScanWriter.WriteLine(index.ToString() +
                                            robotTransform + "," +
                                            laserScan.GetTransformString() + "," +
                                            currentRoom +
                                            data);
                }
                if (captureLidar)
                {
                    logLidarWriter.WriteLine(index.ToString() + "_lidar.png," +
                                             robotTransform + "," +
                                             lidar.GetTransformString() + "," +
                                             currentRoom);
                    File.WriteAllBytes(filePath + "/" + index.ToString() + "_lidar.png", lidar.Scan().EncodeToPNG());
                }

                agent.isStopped = false;
                index++;
                yield return(new WaitForSeconds(timeBetweenDataCapture));
            }
        }
示例#2
0
        private IEnumerator Capture()
        {
            transform.rotation = Quaternion.identity;
            yield return(new WaitForEndOfFrame());

            string robotTransform = GetTransformString();

            for (int i = 1; i <= photosPerNode; i++)
            {
                yield return(new WaitForEndOfFrame());

                if (captureRGB)
                {
                    logImgWriter.WriteLine(index.ToString() + "_" + i.ToString() + "_rgb.jpg," +
                                           robotTransform + "," +
                                           smartCamera.GetTransformString() + "," +
                                           currentRoom);
                    File.WriteAllBytes(filePath + "/" + index.ToString() + "_" + i.ToString() + "_rgb.jpg", smartCamera.CaptureImage(SmartCamera.ImageType.RGB).EncodeToJPG());
                }
                if (captureDepth)
                {
                    logImgWriter.WriteLine(index.ToString() + "_" + i.ToString() + "_depth.jpg," +
                                           robotTransform + "," +
                                           smartCamera.GetTransformString() + "," +
                                           currentRoom);
                    File.WriteAllBytes(filePath + "/" + index.ToString() + "_" + i.ToString() + "_depth.jpg", smartCamera.CaptureImage(SmartCamera.ImageType.Depth).EncodeToJPG());
                }
                if (captureSemanticMask)
                {
                    logImgWriter.WriteLine(index.ToString() + "_" + i.ToString() + "_mask.jpg," +
                                           robotTransform + "," +
                                           smartCamera.GetTransformString() + "," +
                                           currentRoom);
                    File.WriteAllBytes(filePath + "/" + index.ToString() + "_" + i.ToString() + "_mask.jpg", smartCamera.CaptureImage(SmartCamera.ImageType.InstanceMask).EncodeToJPG());
                }

                transform.rotation = Quaternion.Euler(0, i * (360 / photosPerNode), 0);
            }

            if (captureScan)
            {
                string data = "";
                foreach (float d in laserScan.Scan())
                {
                    data += "," + d.ToString("F15", CultureInfo.InvariantCulture);
                }
                logScanWriter.WriteLine(index.ToString() +
                                        robotTransform + "," +
                                        laserScan.GetTransformString() + "," +
                                        currentRoom +
                                        data);
            }
            if (captureLidar)
            {
                logLidarWriter.WriteLine(index.ToString() + "_lidar.png," +
                                         robotTransform + "," +
                                         lidar.GetTransformString() + "," +
                                         currentRoom);
                File.WriteAllBytes(filePath + "/" + index.ToString() + "_lidar.png", lidar.Scan().EncodeToPNG());
            }

            Log(index.ToString() + "/" + grid.Count + " - " + (index / (float)grid.Count) * 100 + "%", LogLevel.Normal);
            index++;
            if (index >= grid.Count)
            {
                state = StatusMode.Finished;
                Log("Finished", LogLevel.Normal);
                GetComponent <AudioSource>().Play();
            }
            else
            {
                agent.SetDestination(grid[index]);
                agent.isStopped = false;
                state           = StatusMode.Walking;
                Log(grid[index].ToString(), LogLevel.Normal);
            }

            yield return(null);
        }