Extract bounding box and save it as an image
The following will give you a single letter letter = im[y:y+h,x:x+w]
The following will give you a single letter letter = im[y:y+h,x:x+w]
I wrote an article about finding the bounding coordinates: http://JanMatuschek.de/LatitudeLongitudeBoundingCoordinates The article explains the formulae and also provides a Java implementation. (It also shows why IronMan’s formula for the min/max longitude is inaccurate.)
For axis-aligned bounding boxes it is relatively simple. “Axis-aligned” means that the bounding box isn’t rotated; or in other words that the boxes lines are parallel to the axes. Here’s how to calculate the IoU of two axis-aligned bounding boxes. def get_iou(bb1, bb2): “”” Calculate the Intersection over Union (IoU) of two bounding boxes. Parameters … Read more
Compute the area of the intersection, which is a rectangle too: SI = Max(0, Min(XA2, XB2) – Max(XA1, XB1)) * Max(0, Min(YA2, YB2) – Max(YA1, YB1)) From there you compute the area of the union: SU = SA + SB – SI And you can consider the ratio SI / SU (100% in case of … Read more
Option 2 does work in iOS with the proper parameters. NSAttributedString *attrStr = … // your attributed string CGFloat width = 300; // whatever your desired width is CGRect rect = [attrStr boundingRectWithSize:CGSizeMake(width, 10000) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil]; Without the proper values for the options parameter you will get the wrong height. It is also … Read more
Transform the coordinates of all four corners Find the smallest of all four x’s as min_x Find the largest of all four x’s and call it max_x Ditto with the y’s Your bounding box is (min_x,min_y), (min_x,max_y), (max_x,max_y), (max_x,min_y) AFAIK, there isn’t any royal road that will get you there much faster. If you are … Read more
You can use the getTextBounds(String text, int start, int end, Rect bounds) method of a Paint object. You can either use the paint object supplied by a TextView or build one yourself with your desired text appearance. Using a Textview you Can do the following: Rect bounds = new Rect(); Paint textPaint = textView.getPaint(); textPaint.getTextBounds(text, … Read more
I used a gradient based method in the program below. Added the resulting images. Please note that I’m using a scaled down version of the image for processing. c++ version The MIT License (MIT) Copyright (c) 2014 Dhanushka Dangampola Permission is hereby granted, free of charge, to any person obtaining a copy of this software … Read more