In [ ]:
%matplotlib inline

import cv2
import matplotlib.pyplot as plot

getting one image from webcam


In [ ]:
camera = cv2.VideoCapture(0)

In [ ]:
retval, image = camera.read()

In [ ]:
camera.release()

In [ ]:
plot.imshow(image)

save image and read it back


In [ ]:
filename = 'first_image.png'
cv2.imwrite(filename, image)

In [ ]:
image2 = cv2.imread(filename)

In [ ]:
plot.imshow(image)

image data format


In [ ]:
type(image)

In [ ]:
image.shape, image.dtype

color space


In [ ]:
rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
plot.imshow(rgb_image)

In [ ]:
r_image = rgb_image[:, :, 0]
plot.imshow(r_image, cmap='gray')

In [ ]:
rgb_image[:, :, 1:] = 0
plot.imshow(rgb_image)

Pixels


In [ ]:
rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
rgb_image[100:200, 100:200, 0] = 255
plot.imshow(rgb_image)

In [ ]:
rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
roi = rgb_image[100:200, 100:200]
plot.imshow(roi)

In [ ]: