How to 'mirror' live webcam video when using OpenCV?
Question:
I want to have two different outputs of webcam videos, one being the normal webcam footage and the other to be the "mirrored" version of it. Is that possible with OpenCV?
import time, cv2
video = cv2.VideoCapture(0)
a = 0
while True:
a = a+1
check, frame = video.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow("Capturing", gray)
key = cv2.waitKey(1)
if key == ord('q'):
break
print(a)
video.release()
cv2.destroyAllWindows()
Answers:
In short, Yes it is possible using cv2. I have made some modification in your code to make it happen.
# Loading modules
import cv2
import numpy as np # Numpy module will be used for horizontal stacking of two frames
video=cv2.VideoCapture(0)
a=0
while True:
a=a+1
check, frame= video.read()
# Converting the input frame to grayscale
gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Fliping the image as said in question
gray_flip = cv2.flip(gray,1)
# Combining the two different image frames in one window
combined_window = np.hstack([gray,gray_flip])
# Displaying the single window
cv2.imshow("Combined videos ",combined_window)
key=cv2.waitKey(1)
if key==ord('q'):
break
print(a)
video.release()
cv2.destroyAllWindows
Hope you get what you were looking for 🙂
to get the mirror image:
flip_img = cv2.flip(img,1)
I want to have two different outputs of webcam videos, one being the normal webcam footage and the other to be the "mirrored" version of it. Is that possible with OpenCV?
import time, cv2
video = cv2.VideoCapture(0)
a = 0
while True:
a = a+1
check, frame = video.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow("Capturing", gray)
key = cv2.waitKey(1)
if key == ord('q'):
break
print(a)
video.release()
cv2.destroyAllWindows()
In short, Yes it is possible using cv2. I have made some modification in your code to make it happen.
# Loading modules
import cv2
import numpy as np # Numpy module will be used for horizontal stacking of two frames
video=cv2.VideoCapture(0)
a=0
while True:
a=a+1
check, frame= video.read()
# Converting the input frame to grayscale
gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Fliping the image as said in question
gray_flip = cv2.flip(gray,1)
# Combining the two different image frames in one window
combined_window = np.hstack([gray,gray_flip])
# Displaying the single window
cv2.imshow("Combined videos ",combined_window)
key=cv2.waitKey(1)
if key==ord('q'):
break
print(a)
video.release()
cv2.destroyAllWindows
Hope you get what you were looking for 🙂
to get the mirror image:
flip_img = cv2.flip(img,1)