/
var
/
www
/
barefootlaw.org
/
will-generator
/
test
/
Upload File
HOME
import cv2 import numpy as np import sys # Get the image path from command line arguments image_path = sys.argv[1] # Load the image image = cv2.imread(image_path) # Convert the image to grayscale gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Apply Otsu's thresholding _, thresholded = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) # Invert the thresholded image thresholded = cv2.bitwise_not(thresholded) # Find contours contours, _ = cv2.findContours(thresholded, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # Create a mask mask = np.zeros_like(image) # Draw contours on the mask cv2.drawContours(mask, contours, -1, (255, 255, 255), thickness=cv2.FILLED) # Make the rest of the image transparent transparent_image = np.zeros_like(image) transparent_image[mask == 255] = image[mask == 255] # Save the transparent image output_path = "output/transparent_signature.png" cv2.imwrite(output_path, transparent_image) print("Image processing completed. Output saved as: " + output_path)