Introducing a program that displays the screen in real time with the camera attached to the personal computer
Language: python3 Library: opencv Editor: jupyter notebook
import cv2
#Preparing for capture
cap = cv2.VideoCapture(0)
#From startup to screen display
while(1):
#Creating a capture frame
_, frame = cap.read()
cv2.imshow('Original', frame)
#Inversion of original (mirror state)
original = cv2.flip(frame, 1)
cv2.imshow('Inversion', original)
#binarization
gray = cv2.cvtColor(original, cv2.COLOR_RGB2GRAY)
cv2.imshow('Binarization', gray)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
cap.release()
"Original" is the body captured by the camera. "Inversion" looks like a mirror by flipping the original screen. "Binarization" is a binarization of the Inversion screen, which is black and white.
This time, the process is easy to understand, but depending on the person who writes the code, it can be sorted as follows.
import cv2
#Preparing for capture
cap = cv2.VideoCapture(0)
#From startup to screen display
while(1):
#Creating a capture frame
_, frame = cap.read()
#Inversion of original (mirror state)
original = cv2.flip(frame, 1)
#binarization
gray = cv2.cvtColor(original, cv2.COLOR_RGB2GRAY)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.imshow('Original', frame)
cv2.imshow('Inversion', original)
cv2.imshow('Binarization', gray)
cv2.destroyAllWindows()
cap.release()
Nothing changes the process itself. However, the following may be easier for programmers to see as a chunk of processing. This is because it looks like they are being processed one by one.
This time I did the basics in the basics. I will write something that applies this, and I can do various things including other libraries, so I recommend you to try it.
Recommended Posts