Esempio n. 1
0
def object_detect(request):
    """
    """
    logger.debug(prepend_ip("Request received: %s" % request, request))

    image = get_image_from_request(request, "obj")
    if not isinstance(image, np.ndarray):
        return image

    logger.debug(prepend_ip("Performing detection process", request))
    start = time.time()
    objects = myObjectDetector.process_image(image)
    elapsed = "%.3f" % ((time.time() - start) * 1000)

    # Create a JSON response to be returned in a consistent manner
    if len(objects) == 0:
        ret = {
            "success": "false",
            "server_processing_time": elapsed,
            "gpu_support": myObjectDetector.is_gpu_supported()
        }
    else:
        ret = {
            "success": "true",
            "server_processing_time": elapsed,
            "gpu_support": myObjectDetector.is_gpu_supported(),
            "objects": objects
        }
    logger.info(
        prepend_ip("%s ms to detect objects: %s" % (elapsed, ret), request))
    json_ret = json.dumps(ret)
    return HttpResponse(json_ret)
    def receive(self, text_data=None, bytes_data=None):
        if bytes_data != None:
            logger.info("bytes_data length=%d" % (len(bytes_data)))
            self.frame_count += 1
            start = time.time()
            image = imread(io.BytesIO(bytes_data))
            try:
                objects = myObjectDetector.process_image(image)
            except Exception as e:
                logger.error("Could not process image. Exception: %s" % e)
                objects = []
            elapsed = "%.3f" % ((time.time() - start) * 1000)
            if len(objects) == 0:
                ret = {
                    "success": "false",
                    "server_processing_time": elapsed,
                    "gpu_support": myObjectDetector.is_gpu_supported()
                }
            else:
                ret = {
                    "success": "true",
                    "server_processing_time": elapsed,
                    "gpu_support": myObjectDetector.is_gpu_supported(),
                    "objects": objects
                }
            response = json.dumps(ret)
        else:
            logger.info("text_data=%s" % (text_data))
            # If text is received, just echo back what we received.
            response = text_data

        logger.info("response=%s" % response)
        self.send(text_data=response)
Esempio n. 3
0
def server_capabilities(request):
    """ Return whether the server has GPU support. """
    if request.method == 'GET':
        ret = {
            "success": "true",
            "gpu_support": myObjectDetector.is_gpu_supported()
        }
        json_ret = json.dumps(ret)
        return HttpResponse(json_ret)

    return HttpResponseBadRequest("Please send request as a GET")
Esempio n. 4
0
def server_capabilities(request):
    """ Test the connection to the backend """
    if request.method == 'GET':
        ret = {
            "success": "true",
            "gpu_support": myObjectDetector.is_gpu_supported()
        }
        json_ret = json.dumps(ret)
        return HttpResponse(json_ret)

    return HttpResponseBadRequest("Please send request as a GET")