Introduction to OpenCV

OpenCV - Chapter 1

OpenCV Tutorial

We appreciate your patience while we actively develop and enhance our content for a better experience.

Sample Code
import cv2

def main():
    print("This program demonstrates how to use OpenCV to load an image, convert it to grayscale, and display both the original and grayscale images.")

    # Load an image (replace 'path/to/image.jpg' with the actual path to an image file)
    image = cv2.imread('path/to/image.jpg')

    # Check if the image was loaded successfully
    if image is None:
        print("Error: Could not load the image.")
        return

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

    # Display the original image
    cv2.imshow('Original Image', image)

    # Display the grayscale image
    cv2.imshow('Grayscale Image', gray_image)

    # Wait for a key press and close the windows
    cv2.waitKey(0)
    cv2.destroyAllWindows()

if __name__ == "__main__":
    main()