When an image is written to a file path using imwrite, how will the image content be modified due to default ImwriteFlags like IMWRITE_JPEG_QUALITY with 95 as default value

I observed a difference of output when I extracted test using tesseract in the following two scenarios:
There is an image from which a region of interest (ROI) is to be read.

  1. I have cropped the ROI from the image
    cropped_roi = image[y:y+h,x:x+w]
    output1 = passing cropped_roi to tesseract for extraction with psm 6
  2. I saved the same cropped_roi into a file_path “saved_in_path_roi.jpg” by cv2.imwrite(“saved_in_path_roi.jpg”,cropped_roi)
    loaded_from_path = cv2.imread(“saved_in_path_roi.jpg”)
    output2 = passing loaded_from_path to tesseract for extraction with psm 6
    output1 : [confidence_score = 14, text = ‘/18’]
    output2 : [confidence_score = 88, text = ‘718’]
    Actual text is ‘718’

Please let me know your suggestions to handle this

did you test that with several, different images ?

it’s probably just some arbitrary effect from jpg block compression, e.g. your “missing” horizontal line ended up on some block border, which enhanced it in the crop

(well, you should NOT use lossy jpg codecs for computer vision, in general)

ah, and please show us your images !