我正在使用 tesseract R 包來識別影像檔案中的文本。但是,在繪制單詞的邊界框時,坐標似乎不正確。
- 為什么單詞“This”的邊界框與影像中的文本“This”不對齊?

- 有沒有更簡單的方法來繪制影像上的所有邊界框矩形?
library(tesseract)
library(magick)
library(tidyverse)
text <- tesseract::ocr_data("http://jeroen.github.io/images/testocr.png")
image <- image_read("http://jeroen.github.io/images/testocr.png")
text <- text %>%
separate(bbox, c("x1", "y1", "x2", "y2"), ",") %>%
mutate(
x1 = as.numeric(x1),
y1 = as.numeric(y1),
x2 = as.numeric(x2),
y2 = as.numeric(y2)
)
plot(image)
rect(
xleft = text$x1[1],
ybottom = text$y1[1],
xright = text$x2[1],
ytop = text$y2[1])
uj5u.com熱心網友回復:
這僅僅是因為影像的 x、y 坐標從左上角開始rect計數,而從左下角開始計數。影像高 480 像素,因此我們可以執行以下操作:
plot(image)
rect(
xleft = text$x1[1],
ybottom = 480 - text$y1[1],
xright = text$x2[1],
ytop = 480 - text$y2[1])

或者,為了表明這一點,概括:
plot(image)
rect(
xleft = text$x1,
ybottom = magick::image_info(image)$height - text$y1,
xright = text$x2,
ytop = magick::image_info(image)$height - text$y2,
border = sample(128, nrow(text)))

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/318547.html
上一篇:資料框中各行的累計總和
