def detect_violence(self, image): """Detect violence Documentation: https://ai.qq.com/doc/imageterrorism.shtml According to the doc, the image format can be JPG, PNG and BMP. :param image: a Pillow image, a file of image or a path to image :type image: file or path to image in str. """ base64_image = any_image_to_base64(image) response_json = self.client.http_post('image/image_terrorism', { 'image': base64_image, }) return response_json
def ocr(self, image): """OCR :param image: a Pillow image, a file of image or a path to image :type image: file or path to image in str :return: JSON result :rtype: json dict """ base64_image = any_image_to_base64(image) response_json = self.client.http_post('ocr/ocr_generalocr', { 'image': base64_image, }) return response_json
def detect_faces(self, image, mode=1): """Detect faces Documentation: https://ai.qq.com/doc/detectface.shtml :param image: a Pillow image, a file of image or a path to image :type image: file or path to image in str :param mode: mode, defaults to 1 :param mode: int, optional """ base64_image = any_image_to_base64(image) response_json = self.client.http_post('face/face_detectface', { 'image': base64_image, 'mode': int(mode) }) return response_json
def detect_objects(self, image): """Detect objects Documentation: https://ai.baidu.com/docs#/ImageClassify-API/ed0a8379 Args: image (:obj:`str`, :obj:`PIL.Image.Image`, :obj:`file`): path to image file, or a PIL image, or a file-like object. Supported formats: jpg, png and bmp. Returns: dict: JSON response """ params = { 'image': any_image_to_base64(image), } return self.client.http_post('image-classify/v1/object_detect', params)
def detect_objects(self, image): """Detect objects :param image: a Pillow image, a file of image or a path to image :type image: file or path to image in str :return: json result :rtype: json """ base64_image = any_image_to_base64(image) response_json = self.client.http_post('vision/vision_objectr', { 'image': base64_image, 'topk': 5, 'format': 1, }) return response_json
def detect_violence(self, image): """Detect violence Documentation: http://ai.baidu.com/docs#/ImageCensoring-API/top Args: image (:obj:`str`, :obj:`PIL.Image.Image`, :obj:`file`): path to image file, or a PIL image, or a file-like object. Supported formats: jpg, png and bmp. Returns: dict: JSON response """ base64_image = any_image_to_base64(image) response_json = self.client.http_post( 'solution/v1/img_censor/user_defined', { 'image': base64_image, }) return response_json
def detect_faces(self, image): """Detect faces Documentation: http://ai.baidu.com/docs#/Face-Detect-V3/top Args: image (:obj:`str`, :obj:`PIL.Image.Image`, :obj:`file`): path to image file, or a PIL image, or a file-like object. Supported formats: jpg, png and bmp. Returns: dict: JSON response """ params = { 'image': any_image_to_base64(image).decode('utf-8'), 'image_type': 'BASE64', 'face_field': 'age,beauty,expression,faceshape,gender,' + 'glasses,landmark,race,quality,facetype', 'max_face_num': 10, 'face_type': 'LIVE', } return self.client.http_post('face/v3/detect', params, is_json=True)
def _ocr(self, uri, image): base64_image = any_image_to_base64(image) response_json = self.client.http_post(uri, { 'image': base64_image, }) return response_json