Google colaboratory 如何在google colab上访问摄像头并在实时视频中绘制地标,代码如下
单元格1由以下代码组成-Google colaboratory 如何在google colab上访问摄像头并在实时视频中绘制地标,代码如下,google-colaboratory,Google Colaboratory,单元格1由以下代码组成- !wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 # DOWNLOAD LINK !bunzip2 /content/shape_predictor_68_face_landmarks.dat.bz2 datFile = "/content/shape_predictor_68_face_landmarks.dat" import cv2 impor
!wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 # DOWNLOAD LINK
!bunzip2 /content/shape_predictor_68_face_landmarks.dat.bz2
datFile = "/content/shape_predictor_68_face_landmarks.dat"
import cv2
import dlib
cap = cv2.VideoCapture(0)
hog_face_detector = dlib.get_frontal_face_detector()
dlib_facelandmark = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
while True:
_, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = hog_face_detector(gray)
for face in faces:
face_landmarks = dlib_facelandmark(gray, face)
for n in range(0, 68):
x = face_landmarks.part(n).x
y = face_landmarks.part(n).y
cv2.circle(frame, (x, y), 1, (0, 255, 255), 1)
cv2.imshow("Face Landmarks", frame)
key = cv2.waitKey(1)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()
单元格2由以下代码组成-
!wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 # DOWNLOAD LINK
!bunzip2 /content/shape_predictor_68_face_landmarks.dat.bz2
datFile = "/content/shape_predictor_68_face_landmarks.dat"
import cv2
import dlib
cap = cv2.VideoCapture(0)
hog_face_detector = dlib.get_frontal_face_detector()
dlib_facelandmark = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
while True:
_, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = hog_face_detector(gray)
for face in faces:
face_landmarks = dlib_facelandmark(gray, face)
for n in range(0, 68):
x = face_landmarks.part(n).x
y = face_landmarks.part(n).y
cv2.circle(frame, (x, y), 1, (0, 255, 255), 1)
cv2.imshow("Face Landmarks", frame)
key = cv2.waitKey(1)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()
我需要现场视频上的地标,而不是拍摄的图像上的地标。如果可能,请在运行代码后共享您的colab链接