edit image in c code in python

To edit an image using OpenCV in Python, you can use the following code:

main.py
import cv2
import numpy as np

# Read the image from file
img = cv2.imread('image.jpg')

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

# Apply a Gaussian blur to the image
blur = cv2.GaussianBlur(gray, (5, 5), 0)

# Apply Canny edge detection to the image
edges = cv2.Canny(blur, 100, 200)

# Display the original and edited images
cv2.imshow('Original', img)
cv2.imshow('Edges', edges)
cv2.waitKey(0)
435 chars
20 lines

This code reads in an image from a file, converts it to grayscale, applies a Gaussian blur to smooth out noise, and then applies Canny edge detection to detect edges in the image. The resulting image is then displayed using OpenCV's imshow function.

gistlibby LogSnag