Read Pixel
import cv2 import numpy as np import pprint image = cv2.imread('cow.jpg',cv2.IMREAD_COLOR) pixel= image[55,55] pprint.pprint(pixel)
Change Pixel
import cv2 import numpy as np import pprint image = cv2.imread('cow.jpg', cv2.IMREAD_COLOR) image[55, 55] = [255, 255, 255] pixel = image[55, 55] pprint.pprint(pixel)
Change the color of Region of Image
import cv2 import numpy as np import pprint image = cv2.imread('cow.jpg', cv2.IMREAD_COLOR) image[150:200, 100:150] = [255, 255, 255] cv2.imshow("image", image) cv2.waitKey(0) cv2.destroyAllWindows()
Image Characteristics
import cv2 import numpy as np import pprint image = cv2.imread('cow.jpg', cv2.IMREAD_COLOR) print(image.shape) print(image.size) print(image.dtype)
Copy Paste Region
import cv2 import numpy as np import pprint image = cv2.imread('cow.jpg', cv2.IMREAD_COLOR) watch_face = image[200:250,107:194] image[0:50,0:87] = watch_face cv2.imshow('image',image) cv2.waitKey(0) cv2.destroyAllWindows()
References
https://pythonprogramming.net/image-operations-python-opencv-tutorial/
https://www.youtube.com/watch?v=1pzk_DIL_wo&list=PLQVvvaa0QuDdttJXlLtAJxJetJcqmqlQq&index=4
https://github.com/mhdr/OpenCV/tree/master/004