示例#1
0
        public void save(int dataIndex, string carModelName, int index, ref List <int> trackIdx)
        {
            string dataString = dataIndex + "," + carModelName + "," + index + "," + trackIdx.Count;

            for (int i = 0; i < trackIdx.Count; i++)
            {
                dataString += "," + trackIdx[i];
            }
            dataCapturer.Capture(dataString);
        }
示例#2
0
        // Update is called once per frame
        void FixedUpdate()
        {
            if (isCapturing)
            {
                if (imageCapturer && dataCapturer && !isReady)
                {
                    fileName     = createFolderWithName() + ".csv";
                    fileSavePath = basePath + folderName;
                    createFolder(fileSavePath);
                    imageCapturer.initialize(fileSavePath);
                    dataCapturer.initialize(fileSavePath, fileName);
                    imageCapturer.isCapturing = true;
                    dataCapturer.isCapturing  = true;
                    isReady = true;
                    writingCompleteIndex = carPool.dataIndex;
                }
                //Debug.Log("FrameCapturer - ready");
                string timeText = System.DateTime.Now.ToString("yyyyMMddhhmmssfff");

                if (dataCapturer && dataCapturer.isReady)
                {
                    List <DataLabel> labels        = new List <DataLabel>();
                    List <DataLabel> nonOccluded   = new List <DataLabel>();
                    List <DataLabel> nonOverlapped = new List <DataLabel>();
                    for (int i = 0; i < carPool.cars.Count; i++)
                    {
                        Vector3 _relativePosition = carPool.cars[i].transform.position - pCamera.transform.position;
                        // check whether the 2D region of car overlaps screen area or not
                        Rect carRegion = regionCapturer.getScreenRect(pCamera.GetComponent <Camera>(), carPool.cars[i].GetComponent <Collider>(), imageCapturer.captureHeight);
                        if (screenRect.Overlaps(carRegion) && _relativePosition.z < 0)
                        {
                            float croppedX      = Mathf.Max(carRegion.xMin, 0);
                            float croppedY      = Mathf.Max(carRegion.yMin, 0);
                            Rect  croppedRegion = new Rect(croppedX, croppedY, Mathf.Min(carRegion.xMax, imageCapturer.captureWidth - 1) - croppedX, Mathf.Min(carRegion.yMax, imageCapturer.captureHeight - 1) - croppedY);
                            if (croppedRegion.width >= 800 && croppedRegion.height >= 500)
                            {
                                continue;
                            }
                            // 1. image resolution : 40x40
                            if (croppedRegion.width >= 40 && croppedRegion.height >= 40)
                            {
                                labels.Add(new DataLabel(carPool.cars[i].GetComponent <SCPAR.SIM.PVATestbed.Car>().getID(), _relativePosition, croppedRegion, Vector3.Distance(carPool.cars[i].transform.position, pCamera.transform.position), 0));
                            }
                        }
                    }

                    // sort by distance
                    if (labels.Count > 0)
                    {
                        labels.Sort(delegate(DataLabel a, DataLabel b)
                        {
                            return(a.distance.CompareTo(b.distance));
                        });

                        // 2. check occlusions
                        RaycastHit hitInfo;

                        for (int i = 0; i < labels.Count; i++)
                        {
                            Vector3 dir = labels[i].relativeDistance;
                            if (Physics.Raycast(pCamera.transform.position, dir, out hitInfo, 1000))
                            {
                                //Debug.Log(hitInfo.collider.name + ", " + hitInfo.collider.tag);
                                if (hitInfo.collider.tag == "Car")
                                {
                                    nonOccluded.Add(labels[i]);
                                }
                            }
                        }


                        if (ensureNonOverlapped)
                        {
                            // 3. check whether the region ovelaps or not
                            for (int i = 0; i < nonOccluded.Count; i++)
                            {
                                bool overlapped = false;
                                for (int k = 0; k < nonOverlapped.Count; k++)
                                {
                                    if (nonOverlapped[k].region.Overlaps(nonOccluded[i].region))
                                    {
                                        overlapped = true;
                                        break;
                                    }
                                }
                                if (!overlapped)
                                {
                                    nonOverlapped.Add(nonOccluded[i]);
                                }
                            }
                        }
                    }

                    List <DataLabel> resultLabel;

                    if (ensureNonOverlapped)
                    {
                        resultLabel = nonOverlapped;
                    }
                    else
                    {
                        resultLabel = nonOccluded;
                    }

                    if (resultLabel.Count == 0 || (prvCarNumbers >= 0 && resultLabel.Count != prvCarNumbers))
                    {
                        complete(false);
                        //Debug.Log(fileSavePath);
                        string[] filePaths = Directory.GetFiles(fileSavePath);
                        foreach (string filePath in filePaths)
                        {
                            File.Delete(filePath);
                        }
                        Directory.Delete(fileSavePath, true);
                        //if (Directory.Exists(fileSavePath)) { Directory.Delete(fileSavePath, true); }
                        count = 0;
                        return;
                    }

                    dataCapturer.Capture(timeText, pCamera.GetComponent <Camera>(), resultLabel, 0);
                    prvCarNumbers = resultLabel.Count;

                    //Debug.Log("DataCapturer - capture complete!");
                    //dataCapturer.Capture(timeText, pCamera.relativePosition, pCamera.carObject.transform.rotation.eulerAngles, pCamera.carObject.speed, pCamera.transform.rotation.eulerAngles, 1, 0);
                }

                if (imageCapturer && imageCapturer.isReady)
                {
                    imageCapturer.Capture(timeText, pCamera.GetComponent <Camera>());
                    //Debug.Log("ImageCapturer - capture complete!");
                }

                if (count % interval == interval - 1)
                {
                    complete(true);
                }
                count++;
            }
        }