-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGettingAndSettingsBgr.py
41 lines (31 loc) · 1.06 KB
/
GettingAndSettingsBgr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import cv2
img = cv2.imread('images/logo.png')
dimensions = img.shape
print(dimensions)
(h, w, c) = img.shape
print("Dimensions of the image - Height: {}, Width: {}, Channels: {}".format(h, w, c))
totalNumberOfPixels = img.size
print("Total number of elements: {}".format(totalNumberOfPixels))
print("Total number of elements: {}".format(h * w * c))
imageDtype = img.dtype
print("Image datatype: {}".format(imageDtype))
cv2.imshow("original image", img)
cv2.waitKey(0)
(b, g, r) = img[6, 40]
print("Pixel at (6,40) - Red: {}, Green: {}, Blue: {}".format(r, g, b))
b = img[6, 40, 0]
g = img[6, 40, 1]
r = img[6, 40, 2]
print("Pixel at (6,40) - Red: {}, Green: {}, Blue: {}".format(r, g, b))
img[6, 40] = (0, 0, 255)
(b, g, r) = img[6, 40]
print("Pixel at (6,40) - Red: {}, Green: {}, Blue: {}".format(r, g, b))
topLeftCorner = img[0:50, 0:50]
cv2.imshow("top left corner original", topLeftCorner)
cv2.waitKey(0)
img[20:70, 20:70] = topLeftCorner
cv2.imshow("modified image", img)
cv2.waitKey(0)
img[0:50, 0:50] = (255, 0, 0)
cv2.imshow("modified image", img)
cv2.waitKey(0)