I need to find affine projections of rectangular content in an image, e.g., paintings, postcards, posters, etc.
I was surprised that FindImageShapes
only supports lines, circles, and eclipses!
Is there a built-in way to do this in v14? And if not, how to extend FindImageShapes
?
Example:
img = Import@
"https://www.wolframcloud.com/obj/ffcb49f6-e44c-4c2b-a2e3-3cdc842ae085"
FindImageShapes[img, "Rectangle"]
First and worst attempt:
comp = ImageSegmentationComponents[img];
Colorize@comp
area = Times @@ ImageDimensions[img];
rects = SortBy[
ComponentMeasurements[
comp, {"BoundingBox", "Rectangularity",
"Area"}], -#[[2, 2]]^(1/2) + (#[[2, 3]]/area) &];
HighlightImage[img, {Red, Rectangle @@@ rects[[1 ;; UpTo[15], 2, 1]]}]