From 84b32307d5e1258945a608cff30e8a2c544e6d06 Mon Sep 17 00:00:00 2001 From: Ashit Kumar Date: Wed, 29 Jul 2020 00:40:06 +0530 Subject: [PATCH] Create capture_and_collage.py --- capture_and_collage.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 capture_and_collage.py diff --git a/capture_and_collage.py b/capture_and_collage.py new file mode 100644 index 0000000..19876de --- /dev/null +++ b/capture_and_collage.py @@ -0,0 +1,42 @@ +import cv2 +from datetime import datetime +import sys +import numpy as np + +# create the VideoCapture inst +cam = cv2.VideoCapture(0) +input('Press Enter to capture') +ret, img = cam.read() +capture_image1_name = "test1_" + str(datetime.now()) + ".png" +cv2.imwrite(capture_image1_name, img) +cam.release() + +# Let me click one more pic +cam = cv2.VideoCapture(0) +input('Press Enter to capture another one') +ret, img = cam.read() +capture_image2_name = "test2_" + str(datetime.now()) + ".png" +cv2.imwrite(capture_image2_name, img) +cam.release() + +# Now we have captured the image let's create the collage out of it +# with color +img_read1_0 = cv2.imread(capture_image1_name, cv2.IMREAD_COLOR) +img_read2_0 = cv2.imread(capture_image2_name, cv2.IMREAD_COLOR) + +# resize +img_read1 = cv2.resize(img_read1_0, (250, 250)) +img_read2 = cv2.resize(img_read2_0, (250, 250)) + +# Vertically stack up two images of first capture +col1 = np.vstack([img_read1, img_read1]) + +# Vertically stack up two images of secodn capture +col2 = np.vstack([img_read2, img_read2]) + +# Now horizontally put them side-by-side +collage = np.hstack([col1, col2]) + +# Create the collage +k = cv2.waitKey(0) +cv2.imwrite("collage.png", collage)