kmisc 2.1.127__py3-none-any.whl → 2.1.128__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
kmisc/__init__.py CHANGED
@@ -3650,8 +3650,8 @@ def web_capture(url,output_file,image_size='full',wait_time=3,ignore_certificate
3650
3650
  if backup == 2:
3651
3651
  comp_a=f'{output_file}.0'
3652
3652
  comp_b=f'{output_file}.1'
3653
- if os.path.isfile(comp_a) and os.path.isfile(comp_b):
3654
- if filecmp.cmp(comp_a,comp_b):
3653
+ if os.path.isfile(output_file) and os.path.isfile(comp_a) and os.path.isfile(comp_b):
3654
+ if filecmp.cmp(comp_a,comp_b) and (filecmp.cmp(output_file,comp_a) or filecmp.cmp(output_file,comp_b)):
3655
3655
  if log:
3656
3656
  if IsIn(log,['screen','log','print',print]):
3657
3657
  printf(Dot(),direct=True)
@@ -3743,8 +3743,6 @@ class OCR:
3743
3743
  else:
3744
3744
  Import('easyocr')
3745
3745
  Import('logging')
3746
- if self.enhance:
3747
- Import('PIL',install_name='Pillow')
3748
3746
  logging.getLogger('easyocr').setLevel(logging.ERROR)
3749
3747
  warnings.filterwarnings("ignore", category=RuntimeWarning, module="networkx.utils.backends")
3750
3748
  warnings.filterwarnings("ignore", category=UserWarning, module="torch.utils.data.dataloader")
@@ -3756,10 +3754,20 @@ class OCR:
3756
3754
  model_storage_directory=self.model_storage_directory,
3757
3755
  download_enabled=False)
3758
3756
 
3759
- def Text(self,detail=0,low_text=None,contrast_ths=None,image_file=None,output=str):
3757
+ def Text(self,detail=0,low_text=None,contrast_ths=None,image_file=None,output=str,enhance=None):
3760
3758
  if not image_file: image_file=self.image_file
3761
3759
  if not image_file: return False
3762
3760
  if not os.path.isfile(image_file): return False
3761
+ if enhance is None:
3762
+ enhance=self.enhance
3763
+ if enhance:
3764
+ Import('PIL',install_name='Pillow')
3765
+ image = PIL.Image.open(image_file)
3766
+ image = image.convert('L') #Grayscale
3767
+ image = PIL.ImageEnhance.Contrast(image).enhance(3.0) #high contrast
3768
+ image = PIL.ImageEnhance.Sharpness(image).enhance(2.0)#Sharpen
3769
+ image = image.convert('RGB').point(lambda p: 255 if p > 140 else 0) # Adjust threshold if needed
3770
+ image.save(image_file)
3763
3771
  if self.ocr_module == 'pytesseract':
3764
3772
  image = cv2.imread(image_file)
3765
3773
  # Convert to grayscale
@@ -3803,13 +3811,6 @@ class OCR:
3803
3811
  opts['allowlist']='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:/-_@,"+'
3804
3812
  if isinstance(low_text,float): opts['low_text']=low_test
3805
3813
  if isinstance(contrast_ths,float): opts['contrast_ths']=contrast_ths
3806
- if self.enhance:
3807
- image = PIL.Image.open(image_file)
3808
- image = image.convert('L') #Grayscale
3809
- image = PIL.ImageEnhance.Contrast(image).enhance(3.0) #high contrast
3810
- image = PIL.ImageEnhance.Sharpness(image).enhance(2.0)#Sharpen
3811
- image = image.convert('RGB').point(lambda p: 255 if p > 140 else 0) # Adjust threshold if needed
3812
- image.save(image_file)
3813
3814
  text=self.reader.readtext(image_file,**opts)
3814
3815
  if output is str:
3815
3816
  return ' '.join(text)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kmisc
3
- Version: 2.1.127
3
+ Version: 2.1.128
4
4
  Summary: Enginering useful library
5
5
  Home-page: https://github.com/kagepark/kmisc
6
6
  Author: Kage Park
@@ -0,0 +1,6 @@
1
+ kmisc/__init__.py,sha256=HyGUe_FMo91P5_9TokUZNbb5xuGcIbzZou14MI5gdgU,164285
2
+ kmisc-2.1.128.dist-info/LICENSE,sha256=mn9ekhb34HJxsrVhcxrLXJUzy55T62zg-Gh9Ro0mVJI,1066
3
+ kmisc-2.1.128.dist-info/METADATA,sha256=TSjRtdKRGBUSGeTCoCXO9bdgFd6ptpwPH_QiGJTVw2o,5523
4
+ kmisc-2.1.128.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
5
+ kmisc-2.1.128.dist-info/top_level.txt,sha256=wvdHf5aQTqcGYvxk-F9E_BMWLMhlwC8INBmwO-V6_X4,6
6
+ kmisc-2.1.128.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- kmisc/__init__.py,sha256=tnoEHQodYetr4uQXg_A_b9POuG0exGcOI_bRP19gqaI,164172
2
- kmisc-2.1.127.dist-info/LICENSE,sha256=mn9ekhb34HJxsrVhcxrLXJUzy55T62zg-Gh9Ro0mVJI,1066
3
- kmisc-2.1.127.dist-info/METADATA,sha256=9jln_ajfJ95qi1plPWB42lcMEQ5AvEk7ucVvb02NaHc,5523
4
- kmisc-2.1.127.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
5
- kmisc-2.1.127.dist-info/top_level.txt,sha256=wvdHf5aQTqcGYvxk-F9E_BMWLMhlwC8INBmwO-V6_X4,6
6
- kmisc-2.1.127.dist-info/RECORD,,