You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code for some reason only works when used in a python ide / anaconda cmd, but not when packed into a .exe. The .exe works on my coding laptop, but when tested on my other non-coding laptop (that doesn't have python installed) it doesnt work I want to know why that is? Am I not adding the necessary "additional files" or not adding a necessary "hidden import"? Can someone help test.json
import easyocr
import os
import sys
import sys
import warnings
warnings.filterwarnings("ignore", module="easyocr")
os.environ["PYTHONWARNINGS"] = "ignore"
# sys.stderr = open(os.devnull, 'w') # Prevent printing warnings
b=[]
if getattr(sys, 'frozen', False):
script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
else:
script_dir = os.path.dirname(os.path.abspath(__file__))
reader = easyocr.Reader(['ja'], user_network_directory=script_dir, recog_network="japanese_g2", gpu=True)
import cv2
# Load image
path_set = os.path.join(script_dir, "swstella_system_cg1.jpg")
img = cv2.imread(path_set)
if img is None:
print("Image not found at path")
# Increase contrast
contrast = cv2.convertScaleAbs(img, alpha=1.5, beta=1)
# Greyscale
gray = cv2.cvtColor(contrast, cv2.COLOR_BGR2GRAY)
# Denoise the image with Gaussian Blur
#blurred = cv2.GaussianBlur(gray, (3, 3), 0)
# Threshold the image (binary)
_, threshold_img = cv2.threshold(gray, 128, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
# Calculate the percentage of black pixels
import numpy as np
black_pixels = np.sum(threshold_img == 0)
total_pixels = threshold_img.size
black_ratio = black_pixels / total_pixels
# Invert the image if black pixels dominate
if black_ratio > 0.75:
processed_img = cv2.bitwise_not(threshold_img)
else:
processed_img = threshold_img
# Perform OCR on the processed image
result = reader.readtext(processed_img, text_threshold=0.7, low_text=0.5)
print(str(result))
if getattr(sys, 'frozen', False):
script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
else:
script_dir = os.path.dirname(os.path.abspath(__file__))
path_set = os.path.join(script_dir, "file.txt")
print(path_set)
try:
with open(path_set, "wb") as file: # Open in binary mode
file.write(str(result).encode("utf-8"))
print(f"File written successfully to {path_set}")
except Exception as e:
print(f"An error occurred: {e}")
# height, width = img.shape[:2]
# aspect_ratio = height / width
# new_height = int(800 * aspect_ratio)
# cv2.namedWindow("Image", cv2.WINDOW_NORMAL)
# cv2.resizeWindow("Image", 800, new_height)
# cv2.imshow("Image", processed_img)
# cv2.waitKey(0)
The text was updated successfully, but these errors were encountered:
This code for some reason only works when used in a python ide / anaconda cmd, but not when packed into a .exe. The .exe works on my coding laptop, but when tested on my other non-coding laptop (that doesn't have python installed) it doesnt work I want to know why that is? Am I not adding the necessary "additional files" or not adding a necessary "hidden import"? Can someone help
test.json
The text was updated successfully, but these errors were encountered: