def adjust_focal_points(self): source_width, source_height = self.engine.size self.focal_points = None if self.context.request.focal_points: if self.context.request.should_crop: self.focal_points = [] crop = self.context.request.crop for point in self.context.request.focal_points: if point.x < crop['left'] or point.x > crop['right'] or point.y < crop['top'] or point.y > crop['bottom']: continue point.x -= crop['left'] or 0 point.y -= crop['top'] or 0 self.focal_points.append(point) else: self.focal_points = self.context.request.focal_points if not self.focal_points: self.focal_points = [ FocalPoint.from_alignment(self.context.request.halign, self.context.request.valign, source_width, source_height) ] self.engine.focus(self.focal_points)
def adjust_focal_points(self): source_width, source_height = self.engine.size self.focal_points = None if self.context.request.focal_points: if self.context.request.should_crop: self.focal_points = [] crop = self.context.request.crop for point in self.context.request.focal_points: if point.x < crop['left'] or point.x > crop[ 'right'] or point.y < crop[ 'top'] or point.y > crop['bottom']: continue point.x -= crop['left'] or 0 point.y -= crop['top'] or 0 self.focal_points.append(point) else: self.focal_points = self.context.request.focal_points if not self.focal_points: self.focal_points = [ FocalPoint.from_alignment(self.context.request.halign, self.context.request.valign, source_width, source_height) ] self.engine.focus(self.focal_points)
def calculate_focal_points(self): if self.context['focal_points']: self.focal_points = self.context['focal_points'] else: self.focal_points = [ FocalPoint.from_alignment(self.context['halign'], self.context['valign'], self.source_width, self.source_height) ]
def calculate_focal_points(self): source_width, source_height = self.engine.size if self.context['focal_points']: self.focal_points = self.context['focal_points'] else: self.focal_points = [ FocalPoint.from_alignment(self.context['halign'], self.context['valign'], source_width, source_height) ]
def assert_point_from_alignment(point): comp_point = FocalPoint.from_alignment(point[0], point[1], width=point[2], height=point[3]) assert comp_point.x == point[4], "Expected x => %.2f Got x => %.2f" % ( point[4], comp_point.x) assert comp_point.y == point[5], "Expected y => %.2f Got y => %.2f" % ( point[5], comp_point.y) assert comp_point.weight == 1.0
def calculate_focal_points(self): source_width, source_height = self.engine.size if self.context.request.focal_points: self.focal_points = self.context.request.focal_points else: self.focal_points = [ FocalPoint.from_alignment(self.context.request.halign, self.context.request.valign, source_width, source_height) ] self.engine.focus(self.focal_points)
def calculate_focal_points(self): source_width, source_height = self.engine.size if self.context['focal_points']: self.focal_points = self.context['focal_points'] else: self.focal_points = [ FocalPoint.from_alignment(self.context['halign'], self.context['valign'], source_width, source_height) ] self.engine.focus(self.focal_points)
def process(self, canvas_width, canvas_height, size): try: self.engine.load(self.buffer, self.extension) width, height = self.engine.size new_width, new_height = calc_new_size_by_height(width, height, canvas_height) focal_points = StandaloneFaceDetector.features_to_focal_points( StandaloneFaceDetector.get_features(self.thumbor_filter.context, self.engine)) if focal_points: self.resize_focal_points(focal_points, float(new_width) / width) else: focal_points.append(FocalPoint.from_alignment('center', 'top', new_width, new_height)) self.engine.resize(new_width, new_height) self.engine.focus(focal_points) StandaloneFaceDetector.auto_crop(self.engine, focal_points, size, canvas_height) except Exception as err: logger.exception(err)
def process(self, canvas_width, canvas_height, size): try: self.engine.load(self.buffer, None) width, height = self.engine.size new_width, new_height = calc_new_size_by_height( width, height, canvas_height) focal_points = StandaloneFaceDetector.features_to_focal_points( StandaloneFaceDetector.get_features( self.thumbor_filter.context, self.engine)) if focal_points: self.resize_focal_points(focal_points, float(new_width) / width) else: focal_points.append( FocalPoint.from_alignment('center', 'top', new_width, new_height)) self.engine.resize(new_width, new_height) self.engine.focus(focal_points) StandaloneFaceDetector.auto_crop(self.engine, focal_points, size, canvas_height) except Exception as err: logger.exception(err)
def adjust_focal_points(self): source_width, source_height = self.engine.size self.focal_points = [] if self.context.request.focal_points: crop = self.context.request.crop for point in self.context.request.focal_points: point.x -= crop['left'] or 0 point.y -= crop['top'] or 0 if point.x < 0 or point.x > self.target_width or \ point.y < 0 or point.y > self.target_height: continue self.focal_points.append(point) if not self.focal_points: self.focal_points = [ FocalPoint.from_alignment(self.context.request.halign, self.context.request.valign, source_width, source_height) ] self.engine.focus(self.focal_points)
def test_aligned_point_top_left(self): point = FocalPoint.from_alignment('left', 'top', 300, 200) expect(point.x).to_equal(0) expect(point.y).to_equal(0) expect(point.weight).to_equal(1.0)
def test_aligned_point_center_middle(self): point = FocalPoint.from_alignment('center', 'middle', 300, 200) expect(point.x).to_equal(150) expect(point.y).to_equal(100) expect(point.weight).to_equal(1.0)
def test_aligned_point_bottom_right(self): point = FocalPoint.from_alignment('right', 'bottom', 300, 200) expect(point.x).to_equal(300) expect(point.y).to_equal(200) expect(point.weight).to_equal(1.0)
def topic(self): return FocalPoint.from_alignment('left', 'top', 300, 200)
def topic(self): return FocalPoint.from_alignment('center', 'middle', 300, 200)
def assert_point_from_alignment(point): comp_point = FocalPoint.from_alignment(point[0], point[1], width=point[2], height=point[3]) assert comp_point.x == point[4], "Expected x => %.2f Got x => %.2f" % (point[4], comp_point.x) assert comp_point.y == point[5], "Expected y => %.2f Got y => %.2f" % (point[5], comp_point.y) assert comp_point.weight == 1.0
def topic(self): return FocalPoint.from_alignment('right', 'bottom', 300, 200)