def getMargins(cut, margin, factor=1): lines = [] if cut.p1.x == cut.p2.x: dx = margin dy = 0 elif cut.p1.y == cut.p2.y: dx = 0 dy = margin else: raise OrientationException("The cut is not straight") lower_p1 = cv.cvPoint(cut.p1.x - dx, cut.p1.y - dy) lower_p2 = cv.cvPoint(cut.p2.x - dx, cut.p2.y - dy) lower_p1 = transformer.translatePoint(lower_p1, factor) lower_p2 = transformer.translatePoint(lower_p2, factor) upper_p1 = cv.cvPoint(cut.p1.x + dx, cut.p1.y + dy) upper_p2 = cv.cvPoint(cut.p2.x + dx, cut.p2.y + dy) upper_p1 = transformer.translatePoint(upper_p1, factor) upper_p2 = transformer.translatePoint(upper_p2, factor) lines.append(Line(lower_p1, lower_p2)) lines.append(Line(upper_p1, upper_p2)) return lines
def drawBoundingBoxes(out, component_dictionary, thickness=1, color=None, factor=1): """Given a dictionary of components, draw its bounding box on the outimage. If no color is supplied, the box will be the same color at the blob.""" # This is a bit hacky, but we need to keep track of the original argument inColor = color for entry in component_dictionary: component = component_dictionary[entry][1] rect = component.rect if inColor == None: color = component_dictionary[entry][0] p1 = cv.cvPoint(rect.x, rect.y) p2 = cv.cvPoint(rect.x + rect.width, rect.y + rect.height) p1 = transformer.translatePoint(p1, factor) p2 = transformer.translatePoint(p2, factor) cv.cvRectangle(out, p1, p2, color, thickness)