自定义Keypoint Template

0

【以下的问题经过翻译处理】 我已经完成整个过程,并成功使用crowd-keypoint元素和模板创建并接收图像定位任务的结果。然而,根据得到的结果,我想限制某些东西以确保更干净的数据:

1.我想要使每个关键点的标签都是必需的(即如果缺少标签,任务无法提交)。 2.我想要限制每个关键点只能标注一个实例(现在,任务可以提交多个相同标签的实例,而我只需要每个标签标注一个非常特定的点),理想情况下,一个新的点放置会删除旧实例或给出错误信息。

有人知道如何使用关键点模板实现这些限制吗?

profile picture
EXPERTO
preguntada hace 6 meses37 visualizaciones
1 Respuesta
0

【以下的回答经过翻译处理】 这个代码应该符合你的使用情况。在提交时,它会验证每个标签是否只使用了一次。

这是一个可行的JSFiddle演示例子:https://jsfiddle.net/01jpzs2n/

<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>

<crowd-form>
  <div id="errorBox"></div>
   
  <crowd-keypoint
    src="https://s3.amazonaws.com/cv-demo-images/ken-griffey-jr.jpg"
    labels="['Item A', 'Item B', 'Item C']"        
    header="Please locate the centers of each item."
    name="annotatedResult">
    <short-instructions>
      Describe your task briefly here and give examples
    </short-instructions>
    <full-instructions>
      Give additional instructions and good/bad examples here
    </full-instructions>   
  </crowd-keypoint>
</crowd-form>

<script>
  var num_obj = 1;
  document.querySelector('crowd-form').onsubmit = function(e) {
    const keypoints = document.querySelector('crowd-keypoint').value.keypoints || document.querySelector('crowd-keypoint')._submittableValue.keypoints;
    const labels = keypoints.map(function(p) {
      return p.label;
    });
    // 1. Make sure total number of keypoints is correct.
    var original_num_labels = document.getElementsByTagName("crowd-keypoint")[0].getAttribute("labels");
    original_num_labels = original_num_labels.substring(2, original_num_labels.length - 2).split("\",\"");
    var goalNumKeypoints = num_obj*original_num_labels.length;
    if (keypoints.length != goalNumKeypoints) {
      e.preventDefault();
      errorBox.innerHTML = '<crowd-alert type="error" dismissible>You must add all keypoint annotations and use each label only once.</crowd-alert>';
      errorBox.scrollIntoView();
      return;
    }
    // 2. Make sure all labels are unique.
    labelCounts = {};
    for (var i = 0; i < labels.length; i++) {
      if (!labelCounts[labels[i]]) {
        labelCounts[labels[i]] = 0;
      }
      labelCounts[labels[i]]++;
    }
    const goalNumSingleLabel = num_obj;
    const numLabels = Object.keys(labelCounts).length;
    Object.entries(labelCounts).forEach(entry => {
      if (entry[1] != goalNumSingleLabel) {
        e.preventDefault();
        errorBox.innerHTML = '<crowd-alert type="error" dismissible>You must use each label only once.</crowd-alert>';
        errorBox.scrollIntoView();
      }
    })
  };
</script>

请告诉我们是否有任何其他问题。

profile picture
EXPERTO
respondido hace 6 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas