Skip to content

Simulation to generate synthetic data for computer vision.

Notifications You must be signed in to change notification settings

DukeRobotics/cv-simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CV Simulation

A Unity 3D underwater simulation to generate synthetic, labeled data for computer vision.

Simulation Overview

The simulation was built using Unity 2022 LTS. It uses the HDRP render pipeline and Unity Perception. See this tutorial to get started with Unity Perception.

The simulation is setup to generate synthetic images of the gate and buoy with automatically generated bounding boxes for RoboSub glyphs. The simulation occurs underwater, in a simulated swimming pool.

The camera captures the gate and buoy from a variety of different distances and angles. In addition to the camera movements, the sun's position, buoy and gate glyphs, and gate boxes are also randomized. This ensures that the camera captures the gate and buoy under a variety of different conditions leading to a more robust CV model.

Code Overview

The code is written in C# in the following files:

Dependencies

Once Miniconda is installed, create the cv-sim environment with:

conda env create -f environment.yml

Then, activate the cv-sim environment with:

conda activate cv-sim

Lastly, due to a backwards compatiability issue with opencv, downgrade opencv with:

pip install opencv-python==4.8.0.74

An error about dependency resolution may appear. This can be safely ignored.

In the future, only the conda activate cv-sim command needs to be executed to set up the Python environment for this repository.

Running the Simulation

Important

Before running the simulation for the first time, the dataset generation path needs to be specified. Open the Project Settings window by selecting the menu Edit > Project Settings... and switch to the Perception pane. Change the Base Path to the Datasets directory of this repository.

Use the play button at the top of the Unity editor to run the simulation. The following option controls whether the simulation saves generated images and their corresponding bounding boxes to disk:

  • Open the inspector for "Main Camera"
  • Scroll down in the inspector to "Perception Camera (Script)"
  • Check/uncheck "Save Camera RGB Output to Disk"

Warning

Generated datasets can occupy a lot of disk space.

Each time the simulation is run with the above option checked, a new folder is created inside the Datasets directory.

The new folder contains the generated images and bounding boxes in SOLO format, created by Unity.

Visualizing SOLO Datasets

To visualize a SOLO dataset, use Voxel51:

pysolotools-fiftyone "Datasets/<SOLO Dataset>"

Note

The viewer will initially open with a subset of frames visible. The data is still being imported in the background. Once all frames are imported, click the "FiftyOne" button in the top left to update the viewer.

Converting from SOLO

To convert from SOLO to COCO format, run:

solo2coco "Datasets/<SOLO Dataset>" <Output Path>

Important

solo2coco creates the real coco dataset inside an extraneous coco directory. In the following steps, either specify coco/coco instead of just coco or remove the unnecessary parent folder.

Many converters exist to convert COCO to other formats.

Image Filter

Navigate to <COCO dataset>/images and manually delete any poor quality images. Unity Perception usually outputs some bad images at the beginning of generation.

Bounding Box Filter

Use bbox_filter.py to filter out poor quality bounding boxes.

python Datasets/bbox_filter.py <COCO dataset path>

Uploading to Roboflow

Upload a COCO dataset to Roboflow to easily train a model or share the dataset with others.

python Datasets/roboflow_upload.py <COCO dataset path>

Images that are successfully uploaded are moved to the success directory. You may need to rerun roboflow_upload.py if any images fail to upload.

CV Workflow

For a complete guide on our CV workflow, visit Computer Vision Workflow on our wiki.

About

Simulation to generate synthetic data for computer vision.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published