Identify text area in image and crop it in R

Is there a way in R (R Studio) to identify the text area in the image and crop it? Like I need to locate the license plate only and crop it then extract the text using tesseract. Thank you.

image

It's going to be difficult, as shown in the sample below, trying OCR on the full image, an image cropped programmatically but with height/width and cropped area set by hand and of a manual screenshot.

library(tesseract)
eng <- tesseract("eng")
text <- tesseract::ocr("https://community.rstudio.com/uploads/default/original/3X/d/5/d591d3342bcc274fcb16d78924d65f9547a25d50.png", engine = eng)
cat(text)
#> oF
#> — —

library(magick)
#> Linking to ImageMagick 6.9.11.60
#> Enabled features: fontconfig, freetype, fftw, heic, lcms, pango, webp, x11
#> Disabled features: cairo, ghostscript, raw, rsvg
#> Using 12 threads
img <- image_read("https://community.rstudio.com/uploads/default/original/3X/d/5/d591d3342bcc274fcb16d78924d65f9547a25d50.png")
img

cropped <- image_crop(img, "320x100+150+100")
cropped

tesseract::ocr(cropped, engine = eng)
#> [1] ""

shot <- image_read("~/Desktop/Screenshot from 2022-01-01 11-09-34.png")
shot

tesseract::ocr(shot, engine = eng)
#> [1] "WOR SIGK |\n"
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.