登录
首页 >  Golang >  Go问答

NormalizedVertex 返回空值时,Google Cloud Vision 检测文本

来源:stackoverflow

时间:2024-02-16 22:09:24 411浏览 收藏

大家好,我们又见面了啊~本文《NormalizedVertex 返回空值时,Google Cloud Vision 检测文本》的内容中将会涉及到等等。如果你正在学习Golang相关知识,欢迎关注我,以后会给大家带来更多Golang相关文章,希望我们能一起进步!下面就开始本文的正式内容~

问题内容

我正在尝试检测 png、图像的文本,然后我会执行以下操作:

image, err := vision.newimagefromreader(file)
if err != nil {
    log.fatalf("failed to create image: %v", err)
}

texts, err := client.detecttexts(ctx, image, nil, 10)
if err != nil {
    log.fatalf("failed to detect texts: %v", err)
}

但是当尝试寻找标准化顶点时,例如

texts[0].GetBoundingPoly().GetNormalizedVertices()

它们是空的,我错过了什么吗?


正确答案


您可以尝试添加以下代码片段:

for _, text := range texts {
    // Access the detected text and bounding box vertices
    textContent := text.Description
    vertices := text.BoundingPoly.GetVertices()

    // Process the detected text and bounding box information
    fmt.Printf("Detected Text: %s\n", textContent)
    fmt.Printf("Bounding Box Vertices:\n")
    for _, vertex := range vertices {
        fmt.Printf("x: %d, y: %d\n", vertex.X, vertex.Y)
    }

getvertices() 方法可以检索每个检测到的文本的四个边界框顶点。这些顶点表示围绕检测到的文本的边界框的坐标。

对于文本检测,api 似乎不提供标准化顶点。

请记住,google cloud vision api 提供的边界框坐标以图像内的像素为单位,并且未标准化。这意味着坐标与图像的分辨率相关,并且未缩放到标准化范围。如果您需要标准化坐标,则需要根据图像尺寸执行额外的计算,以将像素坐标转换为标准化比例。

到这里,我们也就讲完了《NormalizedVertex 返回空值时,Google Cloud Vision 检测文本》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注golang学习网公众号,带你了解更多关于的知识点!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>