Here is a downsampled input image I converted to greyscale.
To select the rectangular region of interest we first preform preprocessing:
binarizedImage =
Dilation[Erosion[
Dilation[Binarize[FillingTransform@ColorNegate@resizedGreyImage],
3], 4], 3]
And then find the relevant components and corners
regions =
SelectComponents[
DeleteSmallComponents[binarizedImage,
Method -> "Mean"], {"Rectangularity"}, 1]
corners =
ImageCorners[regions, 4, 0, 10, MaxFeatures -> 4,
"MaxRefinement" -> 0]
Here is the result:
Show[input,
Graphics[{Opacity[0.5], PointSize[.05], Yellow,
Polygon[corners[[ConvexHull[corners]]]], Thickness[0.4], Blue,
Point /@ corners, White, Text[ToString@#, #] & /@ corners, Green,
Point /@ centers, EdgeForm[{Red, Thick}], FaceForm[Opacity[0]],
Rectangle @@ # & /@ boundingBoxes}], ImageSize -> 600]
I'd like this to be more robust. I'm not sure that "Rectangularity" is the best measure, for instance, in this picture, selecting the component with highest "Rectangularity" doesn't always work:
![enter code here][3]
DeleteSmallComponents[
ImageForestingComponents[ImageResize[input, 300]]]
% // Colorize
regions = SelectComponents[%%, {"Rectangularity"}, 1] // Colorize
Also, I'm coding this in opencv, I'm only using mathematica to prototype so if you know the underlying methods used that would be very helpful.
Here are some test images: