public void DeleteFrameEdit(long timestamp, FRAME_EDIT_TYPE type, BoundingBox bbox) { if (m_editsDictionary.ContainsKey(timestamp)) { ObservableCollection <FrameEdit> list = m_editsDictionary[timestamp]; bool found = false; foreach (FrameEdit fe in list) { if (fe.box.x1 == bbox.x1 && fe.box.y1 == bbox.y1 && fe.box.x2 == bbox.x2 && fe.box.y2 == bbox.y2) { found = true; list.Remove(fe); } } if (!found) { OnVideoEditsDatabaseEvent(new VideoEditsDatabase_EventArgs(true, "Failed to remove Frame Edit:\n" + "given bounding box not found for timestamp")); } } else { OnVideoEditsDatabaseEvent(new VideoEditsDatabase_EventArgs(true, "Failed to remove Frame Edit:\n" + "given timestamp not found")); } }
public void RemoveEditsByType(FRAME_EDIT_TYPE type) { // iterate each frame with edits List <double> entriesToDelete = new List <double>(); foreach (KeyValuePair <double, ObservableCollection <FrameEdit> > frame in m_editsDictionary) { ObservableCollection <FrameEdit> list = frame.Value; ObservableCollection <FrameEdit> itemsToDelete = new ObservableCollection <FrameEdit>(); foreach (FrameEdit fe in list) { if (fe.type == type) { itemsToDelete.Add(fe); } } foreach (FrameEdit fe in itemsToDelete) { list.Remove(fe); } if (list.Count == 0) { entriesToDelete.Add(frame.Key); } } foreach (double timestamp in entriesToDelete) { m_editsDictionary.Remove(timestamp); } }
public bool ReadDatabase() { bool success = true; try { if (File.Exists(m_databaseFilename)) { m_editsDictionary = new ObservableConcurrentDictionary <double, ObservableCollection <FrameEdit> >(); using (BinaryReader br = new BinaryReader(new FileStream(m_databaseFilename, FileMode.Open))) { int numFrames = br.ReadInt32(); // read number of frames with edits // iterate each frame with edits for (int i = 0; i < numFrames; i++) { double timestamp = br.ReadDouble(); int numFrameEdits = br.ReadInt32(); ObservableCollection <FrameEdit> feList = new ObservableCollection <FrameEdit>(); for (int j = 0; j < numFrameEdits; j++) { FRAME_EDIT_TYPE type = (FRAME_EDIT_TYPE)br.ReadInt32(); int x1 = br.ReadInt32(); int y1 = br.ReadInt32(); int x2 = br.ReadInt32(); int y2 = br.ReadInt32(); FrameEdit fe = new FrameEdit(type, new BoundingBox(x1, y1, x2, y2)); feList.Add(fe); } m_editsDictionary.Add(timestamp, feList); } } } else { success = false; m_errorMsg = "File does not exist: " + m_databaseFilename; OnVideoEditsDatabaseEvent(new VideoEditsDatabase_EventArgs(true, m_errorMsg)); } } catch (Exception ex) { m_errorMsg = ex.Message; success = false; OnVideoEditsDatabaseEvent(new VideoEditsDatabase_EventArgs(true, m_errorMsg)); } return(success); }
public void AddFrameEdit(double timestamp, FRAME_EDIT_TYPE type, BoundingBox bbox) { if (bbox.x2 - bbox.x1 > m_minimumRedactionSize && bbox.y2 - bbox.y1 > m_minimumRedactionSize) // make sure bounding box is big enough { if (m_editsDictionary.ContainsKey(timestamp)) { ObservableCollection <FrameEdit> list = m_editsDictionary[timestamp]; list.Add(new FrameEdit(type, bbox)); } else { ObservableCollection <FrameEdit> list = new ObservableCollection <FrameEdit>(); list.Add(new FrameEdit(type, bbox)); m_editsDictionary.Add(timestamp, list); } } }
public FrameEdit(FRAME_EDIT_TYPE Type, BoundingBox BBox) { type = Type; box = BBox; }