public static void writeTrackletsIntoVIRAT(Dictionary <string, VATIC_Tracklet> tracklets, string outputFilePath) { List <string> output = new List <string>(); foreach (string key in tracklets.Keys) { VATIC_Tracklet tck = tracklets[key]; for (int i = 0; i < tck.boxes.Count; i++) { string objId = key; int objType = tck.label; int frameId = Convert.ToInt32(tck.boxes[i][4]); int xtl = Convert.ToInt32(tck.boxes[i][0]); int ytl = Convert.ToInt32(tck.boxes[i][1]); int xbr = Convert.ToInt32(tck.boxes[i][2]); int ybr = Convert.ToInt32(tck.boxes[i][3]); int width = xbr - xtl; int height = ybr - ytl; List <string> line = new List <string>(); line.Add(objId); line.Add("0"); line.Add(frameId.ToString()); line.Add(xtl.ToString()); line.Add(ytl.ToString()); line.Add(width.ToString()); line.Add(height.ToString()); line.Add(objType.ToString()); string ln = ObjectsToStrings.ListString(line, ' '); output.Add(ln); } File.WriteAllLines(outputFilePath, output); } }
private bool getNewRandomJob() { SatyamTaskTableAccess taskTableDB = new SatyamTaskTableAccess(); SatyamTaskTableEntry entry = taskTableDB.getMinimumTriedEntryByTemplate(TaskConstants.Tracking); if (entry != null) { taskTableDB.IncrementDoneScore(entry.ID); SatyamTask task = JSonUtils.ConvertJSonToObject <SatyamTask>(entry.TaskParametersString); SatyamJobStorageAccountAccess satyamStorage = new SatyamJobStorageAccountAccess(); List <string> ImageURLs = satyamStorage.getURLListOfSubDirectoryByURL(task.SatyamURI); //string urls = ""; //for (int i=0;i<ImageURLs.Count;i++) //{ // urls += ImageURLs[i]; // if (i == ImageURLs.Count - 1) break; // urls += ','; //} Hidden_ImageURLList.Value = ObjectsToStrings.ListString(ImageURLs, ','); SatyamJob jobDefinitionEntry = task.jobEntry; MultiObjectTrackingSubmittedJob job = JSonUtils.ConvertJSonToObject <MultiObjectTrackingSubmittedJob>(jobDefinitionEntry.JobParameters); Dictionary <string, List <string> > subcategories = job.Categories; List <string> categories = subcategories.Keys.ToList(); //CategorySelection_RakdioButtonList.Items.Clear(); for (int i = 0; i < categories.Count; i++) { ListItem l = new ListItem(categories[i]); //CategorySelection_RadioButtonList.Items.Add(l); } if (job.Description != "") { //DescriptionPanel.Visible = true; //DescriptionTextPanel.Controls.Add(new LiteralControl(job.Description)); } //Hidden_BoundaryLines.Value = JSonUtils.ConvertObjectToJSon(job.BoundaryLines); Hidden_TaskEntryString.Value = JSonUtils.ConvertObjectToJSon <SatyamTaskTableEntry>(entry); Hidden_PageLoadTime.Value = DateTime.Now.ToString(); // pass parameters from old template Slug_Hidden.Value = "null"; Start_Hidden.Value = "0"; Stop_Hidden.Value = (ImageURLs.Count - 1).ToString(); Skip_Hidden.Value = "0"; PerObject_Hidden.Value = "0.1"; Completion_Hidden.Value = "0.5"; BlowRadius_Hidden.Value = "0"; JobId_Hidden.Value = "1"; LabelString_Hidden.Value = ObjectsToStrings.ListString(categories.ToList(), ','); Attributes_Hidden.Value = ObjectsToStrings.DictionaryStringListString(subcategories, ',', ':', '_'); Training_Hidden.Value = "0"; fps_Hidden.Value = job.FrameRate.ToString(); Hidden_ChunkDuration.Value = job.ChunkDuration.ToString(); var web = new WebClient(); System.Drawing.Image x = System.Drawing.Image.FromStream(web.OpenRead(ImageURLs[0])); ImageWidth_Hidden.Value = x.Width.ToString(); ImageHeight_Hidden.Value = x.Height.ToString(); // image boundary for now //string[] region = new string[] { "0-0-1242-0-1242-375-0-375-0-0" }; string[] region = new string[] { "0-0-" + x.Width + "-0-" + x.Width + "-" + x.Height + "-0-" + x.Height + "-0-0" }; RegionString_Hidden.Value = ObjectsToStrings.ListString(region, ','); taskTableDB.close(); return(true); } else { taskTableDB.close(); return(false); } }
private bool getNewRandomJob() { double price = 0; bool success = Double.TryParse(Hidden_Price.Value, out price); if (!success) { price = 0; } SatyamTaskTableAccess taskTableDB = new SatyamTaskTableAccess(); SatyamTaskTableEntry entry = null; if (Submit_Button.Enabled == true) { //entry = taskTableDB.getMinimumTriedNewEntryForWorkerIDByTemplateAndPrice(Hidden_AmazonWorkerID.Value, // TaskConstants.TrackletLabeling_MTurk, price); entry = taskTableDB.getTopKNewEntryForWorkerIDByTemplateAndPrice(50, Hidden_AmazonWorkerID.Value, TaskConstants.TrackletLabeling_MTurk, price); } else { entry = taskTableDB.getMinimumTriedEntryByTemplate(TaskConstants.TrackletLabeling_MTurk); } taskTableDB.close(); if (entry == null) { return(false); } taskTableDB = new SatyamTaskTableAccess(); taskTableDB.IncrementDoneScore(entry.ID); taskTableDB.close(); SatyamTask task = JSonUtils.ConvertJSonToObject <SatyamTask>(entry.TaskParametersString); SatyamJobStorageAccountAccess satyamStorage = new SatyamJobStorageAccountAccess(); string videoDir = URIUtilities.localDirectoryFullPathFromURI(task.SatyamURI); List <string> ImageURLs = satyamStorage.getURLListOfSpecificExtensionUnderSubDirectoryByURI(videoDir, new List <string>() { "jpg" }); string annotationFilePath = task.SatyamURI; //string urls = ""; //for (int i=0;i<ImageURLs.Count;i++) //{ // urls += ImageURLs[i]; // if (i == ImageURLs.Count - 1) break; // urls += ','; //} Hidden_ImageURLList.Value = ObjectsToStrings.ListString(ImageURLs, ','); SatyamJob jobDefinitionEntry = task.jobEntry; MultiObjectTrackingSubmittedJob job = JSonUtils.ConvertJSonToObject <MultiObjectTrackingSubmittedJob>(jobDefinitionEntry.JobParameters); Dictionary <string, List <string> > subcategories = job.Categories; List <string> categories = subcategories.Keys.ToList(); //CategorySelection_RakdioButtonList.Items.Clear(); for (int i = 0; i < categories.Count; i++) { ListItem l = new ListItem(categories[i]); //CategorySelection_RadioButtonList.Items.Add(l); } if (job.Description != "") { //DescriptionPanel.Visible = true; //DescriptionTextPanel.Controls.Add(new LiteralControl(job.Description)); } //Hidden_BoundaryLines.Value = JSonUtils.ConvertObjectToJSon(job.BoundaryLines); Hidden_TaskEntryString.Value = JSonUtils.ConvertObjectToJSon <SatyamTaskTableEntry>(entry); Hidden_PageLoadTime.Value = DateTime.Now.ToString(); // pass parameters from old template Slug_Hidden.Value = "null"; Start_Hidden.Value = "0"; Stop_Hidden.Value = (ImageURLs.Count - 1).ToString(); Skip_Hidden.Value = "0"; PerObject_Hidden.Value = "0.1"; Completion_Hidden.Value = "0.5"; BlowRadius_Hidden.Value = "0"; JobId_Hidden.Value = "1"; LabelString_Hidden.Value = ObjectsToStrings.ListString(categories.ToList(), ','); Attributes_Hidden.Value = ObjectsToStrings.DictionaryStringListString(subcategories, ',', ':', '_'); Training_Hidden.Value = "0"; fps_Hidden.Value = job.FrameRate.ToString(); Hidden_ChunkDuration.Value = job.ChunkDuration.ToString(); var web = new WebClient(); System.Drawing.Image x = System.Drawing.Image.FromStream(web.OpenRead(ImageURLs[0])); ImageWidth_Hidden.Value = x.Width.ToString(); ImageHeight_Hidden.Value = x.Height.ToString(); // image boundary for now //string[] region = new string[] { "0-0-1242-0-1242-375-0-375-0-0" }; string[] region = new string[] { "0-0-" + x.Width + "-0-" + x.Width + "-" + x.Height + "-0-" + x.Height + "-0-0" }; RegionString_Hidden.Value = ObjectsToStrings.ListString(region, ','); // temp test List <VATIC_Tracklet> prevTracesTemp = new List <VATIC_Tracklet>(); WebClient client = new WebClient(); Stream stream = client.OpenRead(annotationFilePath); StreamReader reader = new StreamReader(stream); List <string> trace = new List <string>(); while (reader.Peek() >= 0) { string content = reader.ReadLine(); trace.Add(content); } Dictionary <string, VATIC_Tracklet> tracklets = VATIC_Tracklet.ReadTrackletsFromVIRAT(trace); foreach (string id in tracklets.Keys) { //string output = JSonUtils.ConvertObjectToJSon(tracklets[id]); prevTracesTemp.Add(tracklets[id]); } string output = JSonUtils.ConvertObjectToJSon(prevTracesTemp); PreviousTrackString_Hidden.Value = output; return(true); }
public static string stitchAnnotationStringByAssociation(List <List <string> > CrossChunkEntitiesAnnotationStrings, List <List <string> > SingleChunkEntitiesAnnotationStrings, List <MultipartiteWeightedMatch> association, DateTime NewFrameStartTime) { List <string> stitchedAnnotationStrings = new List <string>(); // traverse the current trace for (int i = 0; i < CrossChunkEntitiesAnnotationStrings[0].Count; i++) { string stitchedAnnotationString = ""; foreach (MultipartiteWeightedMatch match in association) { if (match.elementList.Count == 2 && match.elementList[0] == i) { // there is an association from the next trace string[] currentTraceFields = CrossChunkEntitiesAnnotationStrings[0][match.elementList[0]].Split(':'); string[] nextTraceFields = CrossChunkEntitiesAnnotationStrings[1][match.elementList[1]].Split(':'); //List<string> LabelRemovedStringList = new List<string>(); List <string> MergedStringList = new List <string>(); // majority label, if same segment use second one. string curLabel = currentTraceFields[0].Split('_')[0]; string nextLabel = nextTraceFields[0].Split('_')[0]; //if (curLabel != nextLabel) //{ // MergedStringList.Add(nextTraceFields[0]); //} //else //{ // MergedStringList.Add(currentTraceFields[0]); //} MergedStringList.Add(currentTraceFields[0]); int a = 1; int b = 1; while (true) { if (a == currentTraceFields.Length && b == nextTraceFields.Length) { break; } if (a == currentTraceFields.Length) { MergedStringList.Add(nextTraceFields[b]); b++; continue; } if (b == nextTraceFields.Length) { MergedStringList.Add(currentTraceFields[a]); a++; continue; } DateTime curTime = DateTimeUtilities.getDateTimeFromString(currentTraceFields[a].Split(',')[0]); DateTime nextTime = DateTimeUtilities.getDateTimeFromString(nextTraceFields[b].Split(',')[0]); if (curTime <= nextTime) { MergedStringList.Add(currentTraceFields[a]); a++; if (curTime == nextTime) { b++; // skip the same frame from next trace } } else { MergedStringList.Add(nextTraceFields[b]); b++; } } stitchedAnnotationString = ObjectsToStrings.ListString(MergedStringList, ':'); //// remove the label of the second string //for (int j = 1; j < nextTraceFields.Length; j++) //{ // // remove the overlapping part. // DateTime time = DateTimeUtilities.getDateTimeFromString(nextTraceFields[j].Split(',')[0]); // if (time < NewFrameStartTime) continue; // LabelRemovedStringList.Add(nextTraceFields[j]); //} //if (LabelRemovedStringList.Count > 0) //{ // string LabelRemovedString = ObjectsToStrings.ListString(LabelRemovedStringList, ':'); // stitchedAnnotationString = CrossChunkEntitiesAnnotationStrings[0][match.elementList[0]] + ":" + LabelRemovedString; //} //else //{ // stitchedAnnotationString = CrossChunkEntitiesAnnotationStrings[0][match.elementList[0]]; //} } } if (stitchedAnnotationString == "") { // there is no match from next stitchedAnnotationString = CrossChunkEntitiesAnnotationStrings[0][i]; } stitchedAnnotationStrings.Add(stitchedAnnotationString); } // traverse the next trace for (int i = 0; i < CrossChunkEntitiesAnnotationStrings[1].Count; i++) { bool added = false; foreach (MultipartiteWeightedMatch match in association) { if (match.elementList.Count == 2 && match.elementList[1] == i) { //this track has been associated and added. added = true; } } if (!added) { stitchedAnnotationStrings.Add(CrossChunkEntitiesAnnotationStrings[1][i]); } } //add the irrelavant single chunk entities from both chunk for (int i = 0; i < 2; i++) { foreach (string anno in SingleChunkEntitiesAnnotationStrings[i]) { stitchedAnnotationStrings.Add(anno); } } string totalStitchedAnnotationString = ObjectsToStrings.ListString(stitchedAnnotationStrings, '|'); return(totalStitchedAnnotationString); }
public static MultiObjectTrackingResult stitchTwoTracesByTubeletsOfOverlappingVideoChunk(MultiObjectTrackingResult currentTrace, MultiObjectTrackingResult nextTrace, int totalFrameCountsBeforeStitching, int totalFrameCountsAfterStitching, int noFramesOverlap, int fps = 10) { //if (noFramesOverlap == 0) return null; double frameTimeInMiliSeconds = (double)1000 / (double)fps; List <MultiObjectTrackingResult> compressedOverlappingTracks = new List <MultiObjectTrackingResult>(); DateTime overlapStart = currentTrace.VideoSegmentStartTime.AddMilliseconds(frameTimeInMiliSeconds * (totalFrameCountsBeforeStitching - noFramesOverlap)); DateTime overlapEnd = currentTrace.VideoSegmentStartTime.AddMilliseconds(frameTimeInMiliSeconds * (totalFrameCountsBeforeStitching - 1)); //DateTime nextTrace_overlapStart = nextTrace.VideoSegmentStartTime; //DateTime nextTrace_overlapEnd = nextTrace.VideoSegmentStartTime.AddMilliseconds(frameTimeInMiliSeconds * (noFramesOverlap-1)); //MultiObjectTrackingResult nextTrace_Overlap = nextTrace.getSubTimeSegment(nextTrace_overlapStart, nextTrace_overlapEnd, fps); //compressedOverlappingTracks.Add(nextTrace_Overlap); List <List <string> > CrossChunkEntitiesAnnotationStrings = new List <List <string> >(); List <List <string> > SingleChunkEntitiesAnnotationStrings = new List <List <string> >(); for (int i = 0; i < 2; i++) { //boundingboxes.Add(new List<BoundingBox>()); CrossChunkEntitiesAnnotationStrings.Add(new List <string>()); SingleChunkEntitiesAnnotationStrings.Add(new List <string>()); } double timeToPostponeInMilliSeconds = (double)(totalFrameCountsBeforeStitching - noFramesOverlap) * frameTimeInMiliSeconds; //TimeSpan timeSpanToPostponeInSeconds = new TimeSpan(0,0,0,0, (int)timeToPostponeInMilliSeconds); TimeSpan timeSpanToPostponeInSeconds = DateTimeUtilities.getTimeSpanFromTotalMilliSeconds((int)timeToPostponeInMilliSeconds); //// get the end of the first trace and the begining + overlap of the second trace //DateTime CurrentTraceSampleFrameTime = currentTrace.VideoSegmentStartTime.AddMilliseconds(frameTimeInMiliSeconds * (totalFrameCountsBeforeStitching - 1)); //DateTime NextTraceSampleFrameTime = nextTrace.VideoSegmentStartTime.AddMilliseconds(frameTimeInMiliSeconds * (Math.Max(noFramesOverlap - 1, 0))); // current trace List <string> currentTrace_filteredAnnotationStrings = new List <string>(); foreach (CompressedTrack entity in currentTrace.tracks) { // get a snapshot frame at start and end of current trace VATIC_DVA_Frame currentTraceOverlapStartFrame = entity.getFrameAt(overlapStart); string annotationString = entity.unCompressToTrackAnnotationString(); string[] fields = annotationString.Split(':'); List <string> TimeFilteredSegmentStringList = new List <string>(); TimeFilteredSegmentStringList.Add(fields[0]); // adds the label back if (currentTraceOverlapStartFrame != null) { TimeFilteredSegmentStringList.Add(currentTraceOverlapStartFrame.ToAnnotationString()); // adds a starting frame } // remove the label of the second string int count = 0; for (int j = 1; j < fields.Length; j++) { // remove the overlapping part. DateTime time = DateTimeUtilities.getDateTimeFromString(fields[j].Split(',')[0]); if (time <= overlapStart || time > overlapEnd) { continue; } TimeFilteredSegmentStringList.Add(fields[j]); count++; } if (count == 0) { // not a cross chunk one SingleChunkEntitiesAnnotationStrings[0].Add(annotationString); continue; } else { //a cross chunk one CrossChunkEntitiesAnnotationStrings[0].Add(annotationString); // construct for association string filteredAnnotationString = ObjectsToStrings.ListString(TimeFilteredSegmentStringList, ':'); currentTrace_filteredAnnotationStrings.Add(filteredAnnotationString); } } string currentOverlap_totalFilteredAnnotationString = ObjectsToStrings.ListString(currentTrace_filteredAnnotationStrings, '|'); MultiObjectTrackingResult currentTrace_Overlap = MultiObjectTrackingResult.ConvertAnnotationStringToMultiObjectTrackingResult(overlapStart, currentOverlap_totalFilteredAnnotationString, "current", "0", noFramesOverlap, fps); compressedOverlappingTracks.Add(currentTrace_Overlap); // next trace /// postpone the timestamp of the second trace nextTrace.postpone(timeSpanToPostponeInSeconds); List <string> nextTrace_filteredAnnotationStrings = new List <string>(); foreach (CompressedTrack entity in nextTrace.tracks) { VATIC_DVA_Frame nextTraceOverlapStartFrame = entity.getFrameAt(overlapStart); VATIC_DVA_Frame nextTraceOverlapEndFrame = entity.getFrameAt(overlapEnd); string annotationString = entity.unCompressToTrackAnnotationString(); string[] fields = annotationString.Split(':'); List <string> TimeFilteredSegmentStringList = new List <string>(); TimeFilteredSegmentStringList.Add(fields[0]); // adds the label back if (nextTraceOverlapStartFrame != null) { TimeFilteredSegmentStringList.Add(nextTraceOverlapStartFrame.ToAnnotationString()); // adds a starting frame } // remove the label of the second string int count = 0; for (int j = 1; j < fields.Length; j++) { // remove the overlapping part. DateTime time = DateTimeUtilities.getDateTimeFromString(fields[j].Split(',')[0]); if (time <= overlapStart || time >= overlapEnd) { continue; } TimeFilteredSegmentStringList.Add(fields[j]); count++; } if (count == 0) { // not a cross chunk one SingleChunkEntitiesAnnotationStrings[1].Add(annotationString); continue; } else { //a cross chunk one CrossChunkEntitiesAnnotationStrings[1].Add(annotationString); // construct for association if (nextTraceOverlapEndFrame != null) { TimeFilteredSegmentStringList.Add(nextTraceOverlapEndFrame.ToAnnotationString()); // adds a ending frame } string filteredAnnotationString = ObjectsToStrings.ListString(TimeFilteredSegmentStringList, ':'); nextTrace_filteredAnnotationStrings.Add(filteredAnnotationString); } } string nextOverlap_totalFilteredAnnotationString = ObjectsToStrings.ListString(nextTrace_filteredAnnotationStrings, '|'); MultiObjectTrackingResult nextTrace_Overlap = MultiObjectTrackingResult.ConvertAnnotationStringToMultiObjectTrackingResult(overlapStart, nextOverlap_totalFilteredAnnotationString, "next", "1", noFramesOverlap, fps); compressedOverlappingTracks.Add(nextTrace_Overlap); List <MultipartiteWeightedMatch> association = TrackletsAssociation.AssociateTracklets(compressedOverlappingTracks); DateTime NewFrameStartTime = currentTrace.VideoSegmentStartTime + DateTimeUtilities.getTimeSpanFromTotalMilliSeconds((int)(totalFrameCountsBeforeStitching * frameTimeInMiliSeconds)); string totalStitchedAnnotationString = stitchAnnotationStringByAssociation(CrossChunkEntitiesAnnotationStrings, SingleChunkEntitiesAnnotationStrings, association, NewFrameStartTime); MultiObjectTrackingResult ret = MultiObjectTrackingResult.ConvertAnnotationStringToMultiObjectTrackingResult(currentTrace.VideoSegmentStartTime, totalStitchedAnnotationString, currentTrace.cameraId, currentTrace.UID, totalFrameCountsAfterStitching, fps); return(ret); }