Commit 0930c53c authored by jBruneau's avatar jBruneau
Browse files

+ refactor xml config code for recorded data

+ Add parameters to the depth filter
parent 7c14abe0
......@@ -3,7 +3,7 @@ using UnityEngine.Rendering;
using System.Collections;
using System.IO;
public class Filter
public abstract class Filter
{
// configuration
public string name;
......@@ -14,6 +14,8 @@ public class Filter
public Shader filter;
public Camera camera;
public abstract void initParams();
protected void createCam(Camera mainCam)
{
GameObject go = new GameObject(name, typeof(Camera));
......@@ -46,6 +48,7 @@ public class Filter
}
}
public class FilterSegmentation : Filter
{
public FilterSegmentation(Camera mainCam)
......@@ -61,6 +64,11 @@ public class FilterSegmentation : Filter
createCam(mainCam);
}
public override void initParams()
{
}
public override void OnSceneChange(Renderer r, ref MaterialPropertyBlock mpb)
{
var id = r.gameObject.GetInstanceID();
......@@ -83,6 +91,11 @@ public class FilterCategory : Filter
createCam(mainCam);
}
public override void initParams()
{
}
public override void OnSceneChange(Renderer r, ref MaterialPropertyBlock mpb)
{
var layer = r.gameObject.layer;
......@@ -93,18 +106,36 @@ public class FilterCategory : Filter
public class FilterDepth : Filter
{
public FilterDepth(Camera mainCam)
public float maxDist = 50;
public float minDist = 0;
public FilterDepth(Camera mainCam, float maxRepresentedDist=50f)
{
// configuration
name = "Depth";
supportsAntialiasing = true;
needsRescale = false;
maxDist = maxRepresentedDist;
// impl
filter = Shader.Find("Filter/Filter_Depth");
createCam(mainCam);
}
public override void initParams()
{
maxDist = ConfigReader.imgDepth.MaxDepth;
minDist = ConfigReader.imgDepth.MinDepth;
}
public override void OnSceneChange(Renderer r, ref MaterialPropertyBlock mpb)
{
var layer = r.gameObject.layer;
//var tag = r.gameObject.tag;
mpb.SetFloat("_maxDist", maxDist);
mpb.SetFloat("_minDist", minDist);
}
}
public class FilterNormal : Filter
......@@ -121,6 +152,11 @@ public class FilterNormal : Filter
createCam(mainCam);
}
public override void initParams()
{
}
}
public class FilterOpticalFlow : Filter
......@@ -204,4 +240,8 @@ public class FilterOpticalFlow : Filter
for (i = 0; i < BM; i++) setcols(255 * i / BM, 0, 255, k++);
for (i = 0; i < MR; i++) setcols(255, 0, 255 - 255 * i / MR, k++);
}
public override void initParams()
{
}
}
......@@ -27,8 +27,19 @@
return o;
}
uniform float _maxDist;
uniform float _minDist;
fixed4 frag(v2f i) : SV_Target {
return i.nz / 40;
float depth = i.nz - _minDist;
if (depth < 0)
depth = 0;
float ratio = _maxDist - _minDist;
if (ratio <= 0)
ratio = 1;
depth = depth / ratio;
return float4(depth, depth, depth, 1);
}
ENDCG
}
......
......@@ -53,6 +53,35 @@ public class FiltersControl : MonoBehaviour
OnSceneChange();
}
public void init()
{
// Image
saveImage = ConfigReader.imgOriginal.Record;
// Segmentation
saveIdSegmentation = ConfigReader.imgSegmentation.Record;
// Categories
saveLayerSegmentation = ConfigReader.imgCategories.Record;
// Depth
saveDepth = ConfigReader.imgDepth.Record;
// Normals
saveNormals = ConfigReader.imgNormals.Record;
// Optical Flow
saveOpticalFlow = ConfigReader.imgOpticalFlow.Record;
foreach (Filter f in filters)
{
f.initParams();
}
OnSceneChange();
OnCameraChange();
}
void LateUpdate()
......
......@@ -97,13 +97,7 @@ public class LoadEnv : MonoBehaviour
cam_Rec.timeToStart = ConfigReader.recordingStart;
cam_Rec.timeToStop = ConfigReader.recordingEnd;
cam_Rec.framerate = ConfigReader.recordingFramerate;
cam_fc.saveImage = ConfigReader.recordOriginalImg;
cam_fc.saveIdSegmentation = ConfigReader.recordSegmentationImg;
cam_fc.saveLayerSegmentation = ConfigReader.recordLayeredSegImg;
cam_fc.saveDepth = ConfigReader.recordDepthImg;
cam_fc.saveNormals = ConfigReader.recordNormalsImg;
cam_fc.saveOpticalFlow = ConfigReader.recordOpticalFlowImg;
cam_fc.init();
//FB don't know why there this check
//JB to see if it is a relative path or full one
......@@ -178,13 +172,13 @@ public class LoadEnv : MonoBehaviour
private void InitDeepRecorders()
{
GameObject DeepRecorders = GameObject.FindGameObjectWithTag("DeepRecorders");
if (ConfigReader.recordBodyBoudingBoxes)
if (ConfigReader.bboxeBody.Record)
{
DeepRecorders.AddComponent<BodyBoundingBoxRecorder>();
DeepRecorders.GetComponent<BodyBoundingBoxRecorder>().Init(ConfigReader.recordingSaveDir);
}
if (ConfigReader.recordHeadBoundingBoxes)
if (ConfigReader.bboxeHead.Record)
{
DeepRecorders.AddComponent<HeadBoundingBoxRecorder>();
DeepRecorders.GetComponent<HeadBoundingBoxRecorder>().Init(ConfigReader.recordingSaveDir);
......
......@@ -194,60 +194,60 @@ public static class ConfigReader
/// <summary>
/// Indicate if body bounding boxes should be recorded
/// </summary>
static public bool recordOriginalImg
static public DataImgOriginal imgOriginal
{
get { return data.recording.savedData.ImgOriginal; }
get { return data.recording.saveImgOriginal; }
}
/// <summary>
/// Indicate if body bounding boxes should be recorded
/// </summary>
static public bool recordSegmentationImg
static public DataImgSegmentation imgSegmentation
{
get { return data.recording.savedData.ImgSegmentation; }
get { return data.recording.saveImgSegmentation; }
}
/// <summary>
/// Indicate if body bounding boxes should be recorded
/// </summary>
static public bool recordLayeredSegImg
static public DataImgCategories imgCategories
{
get { return data.recording.savedData.ImgCategories; }
get { return data.recording.saveImgCategories; }
}
/// <summary>
/// Indicate if body bounding boxes should be recorded
/// </summary>
static public bool recordDepthImg
static public DataImgDepth imgDepth
{
get { return data.recording.savedData.ImgDepth; }
get { return data.recording.saveImgDepth; }
}
/// <summary>
/// Indicate if body bounding boxes should be recorded
/// </summary>
static public bool recordNormalsImg
static public DataImgNormals imgNormals
{
get { return data.recording.savedData.ImgNormals; }
get { return data.recording.saveImgNormals; }
}
/// <summary>
/// Indicate if body bounding boxes should be recorded
/// </summary>
static public bool recordOpticalFlowImg
static public DataImgOpticalFlow imgOpticalFlow
{
get { return data.recording.savedData.ImgOpticalFlow; }
get { return data.recording.saveImgOpticalFlow; }
}
/// <summary>
/// Indicate if body bounding boxes should be recorded
/// </summary>
static public bool recordBodyBoudingBoxes
static public DataBodyBoundingBoxes bboxeBody
{
get { return data.recording.savedData.BodyBoundingBoxes; }
get { return data.recording.saveBodyBoundingBoxes; }
}
/// <summary>
/// Indicate if head bounding boxes should be recorded
/// </summary>
static public bool recordHeadBoundingBoxes
static public DataHeadBoundingBoxes bboxeHead
{
get { return data.recording.savedData.HeadBoundingBoxes; }
get { return data.recording.saveHeadBoundingBoxes; }
}
/// <summary>
......@@ -425,8 +425,18 @@ public class ConfigRecording
[XmlAttribute]
public int framerate;
public DataImgOriginal saveImgOriginal;
public DataImgSegmentation saveImgSegmentation;
public DataImgCategories saveImgCategories;
public DataImgDepth saveImgDepth;
public DataImgNormals saveImgNormals;
public DataImgOpticalFlow saveImgOpticalFlow;
public DataBodyBoundingBoxes saveBodyBoundingBoxes;
public DataHeadBoundingBoxes saveHeadBoundingBoxes;
public string saveDir;
public ConfigRecordingData savedData;
public ConfigRecording()
{
......@@ -435,43 +445,66 @@ public class ConfigRecording
framerate = 15;
saveDir = ".\\Output\\";
savedData = new ConfigRecordingData();
saveImgOriginal = new DataImgOriginal();
saveImgSegmentation = new DataImgSegmentation();
saveImgCategories = new DataImgCategories();
saveImgDepth = new DataImgDepth();
saveImgNormals = new DataImgNormals();
saveImgOpticalFlow = new DataImgOpticalFlow();
saveBodyBoundingBoxes = new DataBodyBoundingBoxes();
saveHeadBoundingBoxes = new DataHeadBoundingBoxes();
}
}
/// <summary>
/// Recording configuration to be serialize in XML config
/// </summary>
public class ConfigRecordingData
public class DataImgOriginal
{
[XmlAttribute]
public bool ImgOriginal;
public bool Record = true;
}
public class DataImgSegmentation
{
[XmlAttribute]
public bool ImgSegmentation;
public bool Record = false;
}
public class DataImgCategories
{
[XmlAttribute]
public bool ImgCategories;
public bool Record = false;
}
public class DataImgDepth
{
[XmlAttribute]
public bool ImgDepth;
public bool Record = false;
[XmlAttribute]
public bool ImgNormals;
public float MinDepth=0;
[XmlAttribute]
public bool ImgOpticalFlow;
public float MaxDepth=50;
}
public class DataImgNormals
{
[XmlAttribute]
public bool BodyBoundingBoxes;
public bool Record = true;
}
public class DataImgOpticalFlow
{
[XmlAttribute]
public bool HeadBoundingBoxes;
public bool Record = false;
}
public ConfigRecordingData()
{
ImgOriginal=true;
ImgSegmentation = false;
ImgCategories = false;
ImgDepth = false;
ImgNormals = false;
ImgOpticalFlow = false;
BodyBoundingBoxes = false;
HeadBoundingBoxes = false;
}
public class DataBodyBoundingBoxes
{
[XmlAttribute]
public bool Record = false;
}
public class DataHeadBoundingBoxes
{
[XmlAttribute]
public bool Record = false;
}
/// <summary>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment