Skip to content

Commit 84b3230

Browse files
authored
Create capture_and_collage.py
1 parent efb6180 commit 84b3230

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

capture_and_collage.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import cv2
2+
from datetime import datetime
3+
import sys
4+
import numpy as np
5+
6+
# create the VideoCapture inst
7+
cam = cv2.VideoCapture(0)
8+
input('Press Enter to capture')
9+
ret, img = cam.read()
10+
capture_image1_name = "test1_" + str(datetime.now()) + ".png"
11+
cv2.imwrite(capture_image1_name, img)
12+
cam.release()
13+
14+
# Let me click one more pic
15+
cam = cv2.VideoCapture(0)
16+
input('Press Enter to capture another one')
17+
ret, img = cam.read()
18+
capture_image2_name = "test2_" + str(datetime.now()) + ".png"
19+
cv2.imwrite(capture_image2_name, img)
20+
cam.release()
21+
22+
# Now we have captured the image let's create the collage out of it
23+
# with color
24+
img_read1_0 = cv2.imread(capture_image1_name, cv2.IMREAD_COLOR)
25+
img_read2_0 = cv2.imread(capture_image2_name, cv2.IMREAD_COLOR)
26+
27+
# resize
28+
img_read1 = cv2.resize(img_read1_0, (250, 250))
29+
img_read2 = cv2.resize(img_read2_0, (250, 250))
30+
31+
# Vertically stack up two images of first capture
32+
col1 = np.vstack([img_read1, img_read1])
33+
34+
# Vertically stack up two images of secodn capture
35+
col2 = np.vstack([img_read2, img_read2])
36+
37+
# Now horizontally put them side-by-side
38+
collage = np.hstack([col1, col2])
39+
40+
# Create the collage
41+
k = cv2.waitKey(0)
42+
cv2.imwrite("collage.png", collage)

0 commit comments

Comments
 (0)