We have developed a solution for UE4 marketplace. Check out the video on our YouTube channel.
This project contains several blueprints and python scripts designed to streamline capturing of images in UE4 with instance segmented images, exporting data from the scene and processing it into COCO dataset format in JSON file, to be ready for artificial neural network training.
Everything is built in Blueprints, no C++ necessary. There are several blueprints that allow you to spawn desired static meshes, add tags to them and have the camera and objects move randomly and automatically while capturing the image of the scene and the segmented image pair. Included python scripts use OpenCV 2 python library to detect polygons (and bounding boxes) in the masked segmented images which are then exported to COCO dataset format (JSON file).
See the solution on Unreal Engine Marketplace.