增加在线标注util类

This commit is contained in:
weiweiw 2024-11-24 15:30:29 +08:00
parent 95b6942b31
commit d554c3eb6f
1 changed files with 22 additions and 4 deletions

View File

@ -1,21 +1,24 @@
package com.bonus.ai.client;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class OnlineAnnotateUtil {
final static String template = "<View><RectangleLabels name=\"label\" toName=\"image\">.*?</RectangleLabels></View>";
/**
* 替换 View 中的 Label 标签内容
* @param template 原始字符串模板
* @param labels 要替换的 labels 列表
* @return 替换后的字符串
*/
public static String rectangleImageLabels(String template, List<String> labels) {
public static String rectangleImageLabels(List<String> labels) {
if (labels == null || labels.isEmpty()){
return "";
}
// 构建新的 Label 标签内容
StringBuilder labelBuilder = new StringBuilder();
String[] colors = {"#FFA39E", "#D4380D", "#36CFC9", "#FF85C0", "#FFD666"}; // 颜色数组
String[] colors = {"blue", "green", "orange", "purge"}; // 颜色数组
int colorIndex = 0;
for (String label : labels) {
@ -36,5 +39,20 @@ public class OnlineAnnotateUtil {
);
}
/**
* <View>
* <Image name="image" value="$image" zoom="true" rotateControl="true" />
* <RectangleLabels name="label" toName="image">
* <Label value="Person" background="blue"/>
* <Label value="Car" background="green"/>
* </RectangleLabels>
* </View>
*/
public static void main(String[] args) {
// List<String> labels = Arrays.asList("label1", "label2", "label3");
List<String> labels = Stream.of("label1", "label2", "label3")
.collect(Collectors.toList());
String result = rectangleImageLabels(labels);
System.out.println(result);
}
}