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)
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 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)