Exemple #1
0
    def post(self, request):
        image_serializer = ImageSerializer(data=request.data)
        if image_serializer.is_valid() and request.FILES.get("image", None):
            image_id = str(uuid.uuid4())
            #request_id = request.data.get("request_id")
            #callback_url = request.data.get("callback_url")
            name = upload_image(request, image_id)
            image = Image_object()
            image.image_id = image_id
            #image.request_id = request_id
            #image.callback_url = callback_url
            image.name = name
            image.save()
            print("-----------image_id---------------")
            print(image_id)
            detected_faces2 = detect_faces_retina(image_id)
            detect_faces_callback_retina(image_id)
            #detect_faces(image_id)
            #detect_faces_callback(image_id)

            return Response({"status": detected_faces2},
                            status=status.HTTP_202_ACCEPTED)
        else:
            if not request.FILES.get("image", None):
                return Response({'`image` is required'},
                                status=status.HTTP_400_BAD_REQUEST)
            return Response(image_serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
Exemple #2
0
    def post(self, request):
        image_serializer = ImageSerializer(data=request.data)
        if image_serializer.is_valid() and request.FILES.get("image", None):
            image_id = str(uuid.uuid4())
            request_id = request.data.get("request_id")
            callback_url = request.data.get("callback_url")
            name = upload_image(request, image_id)
            image = Image_object()
            image.image_id = image_id
            image.request_id = request_id
            image.callback_url = callback_url
            image.name = name
            image.save()

            chain(
                detect_faces.s(image_id=image_id)
                | detect_faces_callback.s(image_id=image_id)).delay()

            return Response({"status": "ok"}, status=status.HTTP_202_ACCEPTED)
        else:
            if not request.FILES.get("image", None):
                return Response({'`image` is required'},
                                status=status.HTTP_400_BAD_REQUEST)
            return Response(image_serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
    def put(self, id, user):
        album = Album.query.get_or_404(id)
        keys = request.form.keys()

        if "title" in keys:
            album.title = request.form["name"]
        if "receptionAppropriate" in keys:
            album.receptionAppropriate = request.form["receptionAppropriate"]

        ## TODO: Remove images from albums

        photos = request.files.getlist("photos")
        if photos:
            for photo in photos:
                image = Image()
                image.url = upload_album_photo(photo, album.title)
                album.images.append(image)
                db.session.add(image)

        album.lastEdit = datetime.now()

        db.session.commit()
        return jsonify({"message": "ok"})
    def post(self, user):
        data = request.form

        album_name = data.get("name")

        if not album_name:
            return jsonify(success=False), 400

        album = Album()
        album.title = album_name

        albumDate = data.get("albumDate")

        if albumDate:
            albumDate = datetime.strptime(albumDate, ISO_DATE_DEF)
            album.date = albumDate

        receptionAppropriate = inputs.boolean(data.get("receptionAppropriate"))
        if receptionAppropriate:
            album.receptionAppropriate = receptionAppropriate

        #data to add to the image
        photographer = data.get("photographer")
        needsCred = inputs.boolean(data.get("needsCred"))
        editingAllowed = inputs.boolean(data.get("editingAllowed"))

        photos = request.files.getlist("photos")
        if photos:
            for photo in photos:
                image = Image()
                image.url = upload_album_photo(photo, album.title)
                if photographer:
                    image.photographer = photographer
                if albumDate:
                    image.date = albumDate
                image.needsCred = needsCred
                image.editingAllowed = editingAllowed
                album.images.append(image)
                db.session.add(image)

        ## TODO: Details for each photo

        db.session.add(album)
        db.session.commit()
        return jsonify(success=True, id=album.albumId)
Exemple #5
0
 def get(self):
     return [Image('test', 1000)]
Exemple #6
0
 def post(self):
     return Image('test', 500)
Exemple #7
0
 def get(self, **kwargs):
     return Image('test', 1000)
Exemple #8
0
 def validate_image_404_ko_test(self):
     """Image: Validate image (ERROR 404)"""
     image = Image(title='title1', description='Description1', url="http://echaloasuerte.com/asdsad")
     image.validate_and_cache()
     cached_image = image.image
     self.assertIsNotNone(cached_image)
Exemple #9
0
 def validate_image_title_ko_test(self):
     """Image: Validate image (empty title)"""
     image = Image(description='Description1', url="http://comps.canstockphoto.com/can-stock-photo_csp9177473.jpg")
     image.validate_and_cache()
     cached_image = image.image
     self.assertIsNotNone(cached_image)
Exemple #10
0
 def validate_image_url_ko_test(self):
     """Image: Validate image (empty URL)"""
     image = Image(title='title1', description='Description1')
     image.validate_and_cache()
     cached_image = image.image
     self.assertIsNotNone(cached_image)
Exemple #11
0
 def cache_image_ko_test(self):
     """Image: URL does not contain an image"""
     image = Image(title='title1', description='Description1', url="http://www.google.com")
     image.cache_image()
Exemple #12
0
 def cache_image_ok_test(self):
     """Image: Cache image"""
     image = Image(title='title1', description='Description1', url="http://comps.canstockphoto.com/can-stock-photo_csp9177473.jpg")
     image.cache_image()
     cached_image = image.image
     self.assertIsNotNone(cached_image)
Exemple #13
0
    def post(self, request, *args, **kwargs):
        device_id = request.POST.get('device_id')
        min_temperature = request.POST.get('min_temperature')
        max_temperature = request.POST.get('max_temperature')

        # image_id = str(uuid.uuid4())
        num_imgs = Image_object.objects.filter(device_id=device_id).count()
        if (num_imgs > 1000):  # max buffering images
            num_imgs = 0

        imageid = "{:05d}".format(num_imgs)

        photo_filename = upload_photo_image(request, device_id, imageid)
        thermal_filename = upload_thermal_image(request, device_id, imageid)

        name, ext = os.path.splitext(photo_filename)
        photo_preprocessed_filename = name + '_pre' + ext
        photo_output_filename = name + '_out' + ext

        name, ext = os.path.splitext(thermal_filename)
        thermal_preprocessed_filename = name + '_pre' + ext
        thermal_output_filename = name + '_out' + ext

        ### Check if the image_id is already exist in the database
        image_object = None
        try:
            image_object = Image_object.objects.filter(
                device_id=device_id).get(image_id=imageid)
        except Image_object.DoesNotExist:
            image_object = None

        if image_object:  # update the record in the database
            image_object.device_id = device_id
            image_object.image_id = imageid
            image_object.min_temperature = min_temperature
            image_object.max_temperature = max_temperature
            image_object.photo_filename = photo_filename
            image_object.thermal_filename = thermal_filename
            image_object.photo_preprocessed_filename = photo_preprocessed_filename
            image_object.thermal_preprocessed_filename = thermal_preprocessed_filename
            image_object.photo_output_filename = photo_output_filename
            image_object.thermal_output_filename = thermal_output_filename
            image_object.status = ''
            image_object.date_created = datetime.now()
            image_object.save()
        else:  # create a new record in the database
            image = Image_object()
            image.device_id = device_id
            image.image_id = imageid
            image.min_temperature = min_temperature
            image.max_temperature = max_temperature
            image.photo_filename = photo_filename
            image.thermal_filename = thermal_filename
            image.photo_preprocessed_filename = photo_preprocessed_filename
            image.thermal_preprocessed_filename = thermal_preprocessed_filename
            image.photo_output_filename = photo_output_filename
            image.thermal_output_filename = thermal_output_filename
            image.status = ''
            image.save()

        # detect_faces.s(device_id=device_id, image_id=imageid).delay()
        chain(
            preprocessing_image.s(device_id=device_id, image_id=imageid)
            | detect_faces.s(device_id=device_id, image_id=imageid)
            | form_bounding_boxes.s(device_id=device_id, image_id=imageid)
        ).delay()

        return Response({"status": "ok"}, status=status.HTTP_202_ACCEPTED)