diff --git a/coco/storage.py b/coco/storage.py index 1208636..0a7e3cb 100644 --- a/coco/storage.py +++ b/coco/storage.py @@ -311,12 +311,12 @@ class COCOStorage: annotation_id = None return self.getRandomAnnotation(annotation_id=annotation_id, withZerkine=withZerkine) - def getRandomAnnotation(self, annotation_id=None, category_id=None, withZerkine=False) -> Annotation: + def getRandomAnnotation(self, annotation_id=None, category_id=None, withZerkine=False, min_area=None) -> Annotation: result = self.getRandomAnnotations( - annotation_id, category_id, withZerkine, limit=1) + annotation_id, category_id, withZerkine, min_area=min_area, limit=1) return result[0] if len(result) else None - def getRandomAnnotations(self, annotation_id=None, category_id=None, withZerkine=False, limit=None): + def getRandomAnnotations(self, annotation_id=None, category_id=None, withZerkine=False, min_area=None, limit=None): cur = self.con.cursor() where = "" params = [] @@ -332,6 +332,12 @@ class COCOStorage: if withZerkine: where += " AND zerkine_moment IS NOT NULL" + if min_area: + where += " AND area > ?" + params.append(min_area) + print(where) + + sqlLimit = "" if limit: sqlLimit = f"LIMIT {int(limit)}" diff --git a/server.py b/server.py index f812814..ec1bcff 100644 --- a/server.py +++ b/server.py @@ -40,13 +40,16 @@ class AnnotationHandler(tornado.web.RequestHandler): normalise = self.get_argument('normalise', False) normalise = int(normalise) if normalise is not False else False + min_area = self.get_argument('min_area', None) + min_area = int(min_area) if min_area is not None else None + # category_id = None if not category_id else int(category_id) logger.debug( - f'Get annotation id: {annotation_id}, category: {category_id}, normalised: {normalise}') + f'Get annotation id: {annotation_id}, category: {category_id}, normalised: {normalise}, min_area: {min_area}') annotation = self.storage.getRandomAnnotation( - annotation_id=annotation_id, category_id=category_id) + annotation_id=annotation_id, category_id=category_id, min_area=min_area) if normalise: return annotation.getNormalised(normalise, normalise) return annotation diff --git a/www/js/game.js b/www/js/game.js index 68a00b4..2364c5e 100644 --- a/www/js/game.js +++ b/www/js/game.js @@ -26,7 +26,7 @@ export class Game { } loadAnnotation() { - let json_request = new Request('/annotation.json'); + let json_request = new Request('/annotation.json?min_area=500'); fetch(json_request).then(function (response) { return response.json();