Welcome to Jetson AGX Orin repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
09.Image binarization
Image binarization
1. Implementation principle
Use cv2.threshold() function to binarize the image.
2. Implementation effect
cd ~/opencv
xxxxxxxxxxpython3 09.image_binarize.py
Note: Select the image and press q to exit the program!

3. Implementation code
ximport cv2def binarize_image(input_path, output_path, threshold):image = cv2.imread(input_path, cv2.IMREAD_GRAYSCALE)if image is None:print("Error: Unable to open image file.")return_, binary_image = cv2.threshold(image, threshold, 255, cv2.THRESH_BINARY)if cv2.imwrite(output_path, binary_image):print(f"Image saved to {output_path}")cv2.imshow('Image Preview', cv2.imread(output_path))cv2.waitKey(0)cv2.destroyAllWindows()else:print("Error: Unable to save image file.")binarize_image('/home/jetson/opencv/images/yahboom_logo.png', \'/home/jetson/opencv/images/yahboom_logo_binarize.png', \127)