Skip to content

Instantly share code, notes, and snippets.

@EteimZ
Last active March 22, 2023 09:40
Show Gist options
  • Select an option

  • Save EteimZ/4f95ba9b8cfaebdf54f0d461c7ccf367 to your computer and use it in GitHub Desktop.

Select an option

Save EteimZ/4f95ba9b8cfaebdf54f0d461c7ccf367 to your computer and use it in GitHub Desktop.
Opencv example to load image
import cv2 as cv
import sys
# load gray scale image by setting the flag argument to cv.IMREAD_GRAYSCALE
img = cv.imread("img.jpg", cv.IMREAD_GRAYSCALE)
if img is None:
sys.exit("Could not read the image")
cv.imshow("Display window", img)
k = cv.waitKey(0)
if k == ord('s'):
cv.imwrite("gray_img.jpg", img)
elif k == ord('x'):
sys.exit("Exiting image")
import cv2 as cv
import sys
img = cv.imread("img.jpg")
if img is None:
sys.exit("Could not read the image")
cv.imshow("Display window", img)
k = cv.waitKey(0)
if k == ord('s'):
cv.imwrite("new_pic.jpg", img)
elif k == ord('x'):
sys.exit("Exiting image")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment