public LocalizationResult Localize(string name, CultureInfo cultureInfo) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } if (cultureInfo == null) { throw new ArgumentNullException(nameof(cultureInfo)); } LocalizationResult result = null; var source = _sources.FirstOrDefault(f => f.CanLocalize(name, cultureInfo)); if (source != null) { var localized = source.Localize(name, cultureInfo); result = new LocalizationResult() { CultureInfo = cultureInfo, Name = name, Source = source, Value = localized }; } else { if (_options.ReturnNameWhenNotFound) { result = new LocalizationResult() { CultureInfo = cultureInfo, Name = name, Source = source, Value = _options.ReturnBracketsOnUsingName ? $"[{name}]" : name }; } } return(result); }
/// <summary> /// Get Joint Transform Matrix from H and image size and position. /// </summary> /// <param name="result"></param> /// <param name="tagSize"></param> /// <returns></returns> private async Task <Mat> GetTransformFromDetection(/*Detector det*/ LocalizationResult result, float tagSize) { var objPoints = new List <Point3f>(); var imgPoints = new List <Point2f>(); var tagRadius = tagSize / 2; objPoints.Add(new Point3f { X = -tagRadius, Y = -tagRadius, Z = 0 }); objPoints.Add(new Point3f { X = tagRadius, Y = -tagRadius, Z = 0 }); objPoints.Add(new Point3f { X = tagRadius, Y = tagRadius, Z = 0 }); objPoints.Add(new Point3f { X = -tagRadius, Y = tagRadius, Z = 0 }); foreach (var point in result.ResultPoints) { imgPoints.Add(new Point2f(point.X, point.Y)); } //switch (det.rotation) //{ // case 1: // // first quadrant // imgPoints.Add(det.points[2]); // imgPoints.Add(det.points[1]); // imgPoints.Add(det.points[0]); // imgPoints.Add(det.points[3]); // break; // case 0: // // fourth quadrant // imgPoints.Add(det.points[3]); // imgPoints.Add(det.points[2]); // imgPoints.Add(det.points[1]); // imgPoints.Add(det.points[0]); // break; // case 3: // // third quadrant // imgPoints.Add(det.points[0]); // imgPoints.Add(det.points[3]); // imgPoints.Add(det.points[2]); // imgPoints.Add(det.points[1]); // break; // case 2: // // second quadrant // imgPoints.Add(det.points[1]); // imgPoints.Add(det.points[0]); // imgPoints.Add(det.points[3]); // imgPoints.Add(det.points[2]); // break; //} var intrinsics = new double[3, 3] { { 446.362, 0, 631.601 }, { 0, 448.676, 350.1 }, { 0, 0, 1 }, }; var distortionCoeff = new double[4] { 0, 0, 0, 0 }; var rVec = new double[9]; var tVec = new double[3]; Cv2.SolvePnP(objPoints.ToArray(), imgPoints.ToArray(), intrinsics, distortionCoeff, out rVec, out tVec, false, SolvePnPFlags.Iterative); var r = new double[3, 3]; Cv2.Rodrigues(rVec, out r); var mat = new Mat(4, 4, MatType.CV_64FC1); var indexer = mat.GetGenericIndexer <double>(); indexer[0, 0] = r[0, 0]; indexer[0, 1] = r[0, 1]; indexer[0, 2] = r[0, 2]; indexer[1, 0] = r[1, 0]; indexer[1, 1] = r[1, 1]; indexer[1, 2] = r[1, 2]; indexer[2, 0] = r[2, 0]; indexer[2, 1] = r[2, 1]; indexer[2, 2] = r[2, 2]; indexer[0, 3] = tVec[0]; indexer[1, 3] = tVec[1]; indexer[2, 3] = tVec[2]; indexer[3, 0] = 0; indexer[3, 1] = 0; indexer[3, 2] = 0; indexer[3, 3] = 1; return(mat); }
public List<LocalizationResult> TransformXmlToTranslationsList(XDocument xDoc) { var keys = GetTranslationKeys(xDoc); var localizations = new List<LocalizationResult>(); var languages = xDoc.Element("languages").Elements("language"); foreach (var lang in languages) { var id = lang.Attribute("id") != null ? lang.Attribute("id").Value : string.Empty; if (string.IsNullOrEmpty(id)) { continue; } foreach (var key in keys) { var selector = $".{key}"; var translationValue = lang.XPathSelectElement(selector); if (translationValue == null) { continue; } var existingLocalizationResult = localizations.SingleOrDefault(loc => loc.Key == key); var translation = new LocalizationResult.Translation(id, translationValue.Value); if (existingLocalizationResult != null) { existingLocalizationResult.Translations.Add(translation); } else { var localizationResult = new LocalizationResult() { Key = key, Translations = new List<LocalizationResult.Translation>() { translation } }; localizations.Add(localizationResult); } } } return localizations; }
private unsafe void buttonSpeedTest_Click(object sender, EventArgs e) { // get lut // rescale lut // var lut = new Bitmap("lut000.jpg"); var dlg = new ProgressBarDlg(); dlg.Show(new Action(delegate { Bitmap lut = TrackerDlgUtils.Properties.Resources.lut000; using (QTrkInstance inst = new QTrkInstance(TrackerConfiguration)) { int total = Math.Max(100000, inst.GetMaxQueueLength() * 4); Trace.WriteLine(string.Format("Max queue len: {1}, running benchmark with {0} images...", total, inst.GetMaxQueueLength())); dlg.Update(0.0f, "Generating lookup table...", "Benchmark in progress"); GetTimestamp(); // use LUT to generate images for new rescaled lut table var lutf = new FloatImg(lut, 0); using (FloatImg img = QTrkUtil.RescaleAndSetLUT(inst, lutf, lut.Height)) { } // make sample image var cfg = inst.Config; var sample = new FloatImg(cfg.config.width, cfg.config.height); QTrkUtil.GenerateImageFromLUT(sample, lutf, cfg.config.ZLUT_minradius, cfg.zlut_maxradius, new Vector3(cfg.config.width / 2, cfg.config.height / 2, lutf.h / 2), false, 1); dlg.Update(0.0f, "Running speed test...", "Benchmark in progress"); // measure tracking speed double st = GetTimestamp(); ImageData imgd = sample.ImageData; LocalizationJob job = new LocalizationJob(); LocalizationJob *pj = &job; int lastUpdate = 0; for (uint i = 0; i < total; i++) { pj->frame = i; pj->zlutIndex = 0; inst.ScheduleLocalization(ref imgd, pj); int rc = inst.GetResultCount(); if (rc - lastUpdate > total / 20) { dlg.Update(rc / (float)total, "Running speed test...", "Benchmark in progress"); lastUpdate = rc; } } double st0 = GetTimestamp(); inst.Flush(); // wait for results while (true) { System.Threading.Thread.Sleep(20); int rc = inst.GetResultCount(); if (rc - lastUpdate > total / 20) { dlg.Update(rc / (float)total, "Running speed test...", "Benchmark in progress"); lastUpdate = rc; } if (rc == total) { break; } } double end = GetTimestamp(); double fps = total / (end - st); double scheduleTime = (st0 - st) * 1000; Trace.WriteLine(string.Format("Scheduling time: {0} ms. Per frame: {1} us. Scheduling FPS={2}. Processing FPS={3}", (int)scheduleTime, (int)(scheduleTime / total * 1000), (int)(total / (st0 - st)), (int)fps)); Invoke(new Action(delegate { labelSpeedResults.Text = string.Format("{0} frames processed in {1} ms. \nFPS={2}", total, (int)((end - st) * 1000), (int)fps); })); var results = new LocalizationResult[total]; inst.GetResults(results); for (int i = 0; i < 10; i++) { Vector3 p = results[i].pos; Trace.WriteLine(string.Format("x={0}, y={1}, z={2}", p.x, p.y, p.z)); } sample.Dispose(); } lut.Dispose(); })); }