code: def _compare_to_cv_distortion(in_img, out_img, q, no):
      bgr = cv2.cvtColor(in_img, cv2.COLOR_RGB2BGR)
      encode_params = [int(cv2.IMWRITE_JPEG_QUALITY), q]
      _, encoded_img = cv2.imencode(".jpg", bgr, params=encode_params)
  
      decoded_img_bgr = cv2.imdecode(encoded_img, cv2.IMREAD_COLOR)
      decoded_img = cv2.cvtColor(decoded_img_bgr, cv2.COLOR_BGR2RGB)
  
      diff = cv2.absdiff(out_img, decoded_img)
      diff_in_range = np.average(diff) < 5
  
      if dump_images or (dump_broken and not diff_in_range):
          i, j = no
          cv2.imwrite(
              f"./reference_q{q}_sample{i}_{j}.bmp",
              cv2.cvtColor(decoded_img, cv2.COLOR_BGR2RGB),
          )
          cv2.imwrite(
              f"./output_q{q}_sample{i}_{j}.bmp",
              cv2.cvtColor(out_img, cv2.COLOR_BGR2RGB),
          )
  
      assert (
          diff_in_range
      ), f"Absolute difference with the reference is too big: {np.average(diff)}"
  
file_path: DALI/dali/test/python/operator_1/test_jpeg_compression_distortion.py
imports: from nvidia.dali import pipeline_def
  import nvidia.dali.fn
  import nvidia.dali.types
  from random import shuffle
  import numpy
  from test_utils import as_array
  import os
  import cv2
label_desc: Use image node_id 1 for calling a global function with example usage: _compare_to_cv_distortion(in_img, out_img, q, no) without return types