Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opencv program to read and display image #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions class01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# reading image (storing image in 'img' variable) and writeing image (saving the image in detination folder)
# image location (relative path) -> "res/lena.jpg"
# destination to save images -> "result/*.jpg"

# importing OpenCV, Numpy, Matplotlib.Pyplot
import cv2
import numpy as np
import matplotlib.pyplot as plt

# cv2.imread -> image read
img = cv2.imread("res/lena.jpg", -1)
# cv2.IMREAD_COLOR -> 1 --> color
# cv2.IMREAD_GRAYSCALE -> 0 --> black and white
# cv2.IMREAD_UNCHANGED -> -1 --> color + alpha scale

cv2.imshow("Image", img)

cv2.imwrite("result/lena_Unchanged.jpg", img)

cv2.waitKey(0)
cv2.destroyAllWindows()

# using plt method to display image

# cv2.imread -> B,G,R
# plt.imshow -> R,G,B
# so we convert from B,G,R to R,G,B

# img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# plt.imshow(img)
# plt.show()