1 thought on “Machine Learning

  1. It is the sample script for searching sample from certain image generated by ChatGPT.
    ———————————

    import cv2
    import pytesseract

    def search_and_count_sample(image_path, search_text):
    # Load the image using OpenCV
    image = cv2.imread(image_path)

    # Convert the image to grayscale
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # Apply image preprocessing (you can adjust these parameters based on your image quality)
    preprocessed_image = cv2.GaussianBlur(gray_image, (5, 5), 0)

    # Perform OCR using Tesseract
    extracted_text = pytesseract.image_to_string(preprocessed_image)

    # Count the occurrences of the search text
    sample_count = extracted_text.lower().count(search_text.lower())

    return sample_count

    if __name__ == “__main__”:
    image_path = “path/to/your/image.jpg” # Replace with the actual image path
    search_text = “sample” # Replace with the text you want to search for

    sample_count = search_and_count_sample(image_path, search_text)

    print(f”Number of occurrences of ‘{search_text}’ in the image: {sample_count}”)

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.