import cv2 #The module is called cv2. Python requires the opencv-python module. You can enter in command line mode:
#pip install opencv-python -i https://pypi.douban.com/simple/
capture = cv2.VideoCapture(0)
while(capture.isOpened()): #If the camera status is open, it will be refreshed continuously. The specific time for refreshing is written in the waitKey() method later.
retval, frame = capture.read()#Camera read, ret is whether to open the camera successfully, true, false. frame is the image of each frame of the video
frame = cv2.flip(frame, 0)#The camera is opposed to the person, and the image is reversed from left to right and displayed normally. # The second parameter indicates the direction of rotation, 0 indicates rotation around the x axis, a number greater than 0 indicates rotation around the y axis, and a negative number less than 0 indicates rotation around the x and y axes.
frame = cv2.flip(frame, 1)#The camera is opposed to people, and the image is reversed from left to right and displayed normally. # The second parameter indicates the direction of rotation, 0 indicates rotation around the x axis, a number greater than 0 indicates rotation around the y axis, and a negative number less than 0 indicates rotation around the x and y axes.
cv2.imshow("video", frame)
if cv2.waitKey(5) >= 0:
cv2.imwrite('c:/person.jpg', frame) #save image
capture.release() #close camera
break
import cv2 #模块称作cv2。python需要用到opencv-python模块。可在命令行模式输入:
#pip install opencv-python -i https://pypi.douban.com/simple/
capture = cv2.VideoCapture(0)
while(capture.isOpened()): #摄像头状态是开的话不断地刷新。刷新的具体时间写在后面的waitKey()方法中。
retval,frame = capture.read()#摄像头读取,ret为是否成功打开摄像头,true,false。 frame为视频的每一帧图像
frame = cv2.flip(frame, 0)#摄像头是和人对立的,将图像左右调换回来正常显示。# 第二个参数表示旋转的方向,0表示绕x轴旋转,大于0的数表示绕y轴旋转,小于0的负数表示绕x和y轴旋转。
frame = cv2.flip(frame, 1)#摄像头是和人对立的,将图像左右调换回来正常显示。# 第二个参数表示旋转的方向,0表示绕x轴旋转,大于0的数表示绕y轴旋转,小于0的负数表示绕x和y轴旋转。
cv2.imshow("video", frame)
if cv2.waitKey(5) >= 0:
cv2.imwrite('c:/person.jpg', frame) #保存图像
capture.release() #关闭摄像头
break