antonimaciej commented on a change in pull request #4986: [AIRFLOW-4169] Create 
Google Cloud Vision Detect Operators
URL: https://github.com/apache/airflow/pull/4986#discussion_r271869850
 
 

 ##########
 File path: airflow/contrib/operators/gcp_vision_operator.py
 ##########
 @@ -961,3 +961,275 @@ def execute(self, context):
             timeout=self.timeout,
             metadata=self.metadata,
         )
+
+
+class CloudVisionDetectTextOperator(BaseOperator):
+    """
+    Detects Text in the image
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:CloudVisionDetectTextOperator`
+
+    :param image: (Required) The image to analyze. See more:
+        
https://googleapis.github.io/google-cloud-python/latest/vision/gapic/v1/types.html#google.cloud.vision_v1.types.Image
+    :type image: dict or google.cloud.vision_v1.types.Image
+    :param max_results: (Optional) Number of results to return.
+    :type max_results: int
+    :param retry: (Optional) A retry object used to retry requests. If `None` 
is
+        specified, requests will not be retried.
+    :type retry: google.api_core.retry.Retry
+    :param timeout: Number of seconds before timing out.
+    :type timeout: float
+    :param language_hints: List of languages to use for TEXT_DETECTION.
+        In most cases, an empty value yields the best results since it enables 
automatic language detection.
+        For languages based on the Latin alphabet, setting language_hints is 
not needed.
+    :type str, list or google.cloud.vision.v1.ImageContext.language_hints:
+    :param web_detection_params: Parameters for web detection.
+    :type web_detection_params: dict or 
google.cloud.vision.v1.ImageContext.web_detection_params
+    :param additional_properties: Additional properties to be set on the 
AnnotateImageRequest. See more:
+        :class:`google.cloud.vision_v1.types.AnnotateImageRequest`
+    :type additional_properties: dict
+    """
+
+    # [START vision_detect_text_set_template_fields]
+    template_fields = ("image", "max_results", "timeout", "gcp_conn_id")
+    # [END vision_detect_text_set_template_fields]
+
+    def __init__(
+        self,
+        image,
+        max_results=None,
+        retry=None,
+        timeout=None,
+        language_hints=None,
+        web_detection_params=None,
+        additional_properties=None,
+        gcp_conn_id="google_cloud_default",
+        *args,
+        **kwargs
+    ):
+        super(CloudVisionDetectTextOperator, self).__init__(*args, **kwargs)
+        self.image = image
+        self.max_results = max_results
+        self.retry = retry
+        self.timeout = timeout
+        self.gcp_conn_id = gcp_conn_id
+        self.kwargs = kwargs
+        self.additional_properties = prepare_additional_parameters(
+            additional_properties=additional_properties,
+            language_hints=language_hints,
+            web_detection_params=web_detection_params,
+        )
+
+    def execute(self, context):
+        hook = CloudVisionHook(gcp_conn_id=self.gcp_conn_id)
+        return hook.text_detection(
+            image=self.image,
+            max_results=self.max_results,
+            retry=self.retry,
+            timeout=self.timeout,
+            additional_properties=self.additional_properties,
+        )
+
+
+class CloudVisionDetectDocumentTextOperator(BaseOperator):
+    """
+    Detects Document Text in the image
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:CloudVisionDetectDocumentTextOperator`
+
+    :param image: (Required) The image to analyze. See more:
+        
https://googleapis.github.io/google-cloud-python/latest/vision/gapic/v1/types.html#google.cloud.vision_v1.types.Image
+    :type image: dict or google.cloud.vision_v1.types.Image
+    :param max_results: Number of results to return.
+    :type max_results: int
+    :param retry: (Optional) A retry object used to retry requests. If `None` 
is
+        specified, requests will not be retried.
+    :type retry: google.api_core.retry.Retry
+    :param timeout: Number of seconds before timing out.
+    :type timeout: float
+    :param language_hints: List of languages to use for TEXT_DETECTION.
+        In most cases, an empty value yields the best results since it enables 
automatic language detection.
+        For languages based on the Latin alphabet, setting language_hints is 
not needed.
+    :type str, list or google.cloud.vision.v1.ImageContext.language_hints:
 
 Review comment:
   fixed

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to