Google Cloud Vision 阻止索引

huangapple go评论71阅读模式
英文:

Google Cloud Vision Block Index

问题

以下是翻译好的部分:

能否为我提供有关如何获取正在迭代的块的索引的信息?也就是说,如果我需要在迭代过程中知道处于哪个块编号。

以下是一个示例:

    TextAnnotation annotation = res.getFullTextAnnotation();				
				for (com.google.cloud.vision.v1.Page page : annotation.getPagesList()) {
					String pageText = "";
					System.out.println("Bloque-->" + page.getBlocksCount());
					
					for (Block block : page.getBlocksList()) {
						String blockText = "";
						
						//System.out.println("Index of block-->" + block.getIndex());
						System.out.println("Paragrafos-->" + block.getParagraphsCount());
英文:

could you give me information on how to obtain the index of the block that is iterating, that is, if I need to know in what block number during the iteration of this.

Here its an example:

TextAnnotation annotation = res.getFullTextAnnotation();				
			for (com.google.cloud.vision.v1.Page page : annotation.getPagesList()) {
				String pageText = "";
				System.out.println("Bloque-->" + page.getBlocksCount());
				
				for (Block block : page.getBlocksList()) {
					String blockText = "";
					
					//System.out.println("Index of block-->" + block.getIndex());
					System.out.println("Paragrafos-->" + block.getParagraphsCount());

答案1

得分: 2

如果您需要知道索引,请不要使用增强型for循环 - 使用普通for循环,通过索引访问元素。(除非自从我上次查看Java protobuf实现以来发生了显著变化,否则通过索引访问是廉价的。)

for (int i = 0; i < page.getBlocksCount(); i++) {
    Block block = page.getBlocksList().get(i);
    // ...
}
英文:

If you need to know the index, just don't use the enhanced for loop - use a regular for loop, and access the element by index. (Unless things have changed significantly since I last looked at the Java protobuf implementation, access by index is cheap.)


for (int i = 0; i &lt; page.getBlocksCount(); i++) {
    Block block = page.getBlocksList().get(i);
    // ...
}

huangapple
  • 本文由 发表于 2020年9月17日 00:16:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63924149.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定