Skip to content

imported cv2 as cv #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions 03-Open-Camera/cv2_capture_live_video_from_camera.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import cv2
import cv2 as cv

# 1.打开摄像头
capture = cv2.VideoCapture(2)
capture = cv.VideoCapture(2)

# 2.获取捕获的分辨率
width, height = capture.get(3), capture.get(4)
print(width, height)
# 以原分辨率的一倍来捕获,
# 参数1可以直接写数字,或者OpenCV符号表示
capture.set(cv2.CAP_PROP_FRAME_WIDTH, width * 2)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, height * 2)
capture.set(cv.CAP_PROP_FRAME_WIDTH, width * 2)
capture.set(cv.CAP_PROP_FRAME_HEIGHT, height * 2)

while(True):
# 获取一帧
ret, frame = capture.read()
# 将这帧转换为灰度图
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)

cv2.imshow('frame', gray)
if cv2.waitKey(1) == ord('q'):
cv.imshow('frame', gray)
if cv.waitKey(1) == ord('q'):
break