python – How can I adapt this code to use a webcam or RTSP stream for the front panel locking system on a Raspberry Pi?

I found a code on Github called "python_face_recognition_door_opener_raspberry_pi", it basically works with a Pi camera, but I want to adapt this code to use a webcam (usb) or use an rtsp stream, I was looking on the web about this problem, my first try was to use Imutils, and it works partially but in def recognizeFaces (): part of this code uses a different code that is created by the pi camera, i also read about the use of the V4l2 but if I try to meet the same problem.

this is the original code:

import face_recognition
import argparse
import pickle
import cv2
import system

# import the necessary packages for the camera
picamera.array import PiRGBArray
picamera import PiCamera
from the hour of import sleep
# Import the necessary self-created functions
door of import
import servocontrol #may not be necessary to import

#Setting up the camera
camera = PiCamera ()
#Choose the resolution of the image, a lower resolution reduces the preparation time.
camera.resolution = (250, 250)
# Initialization of the capture.
rawCapture = PiRGBArray (camera)
#Capture the first boot image.
camera.capture (rawCapture, format = "bgr")

I have therefore changed the code in this:

from import VideoStream

#Setting up the camera
camera = VideoStream (src = 0) .start ()
camerac = ()

# load faces and known embeddings
impression("[INFO] loading encodings ... ")
data = pickle.loads (open ("/ home / pi / python_face_recognition_door_opener_raspberry_pi / encodings.pickle", "rb"). read ())

nrunknown = 0

# Run all the time until the end
# While True:
def recognizeFaces ():
#To take a picture.
rawCapture = PiRGBArray (camera)
camera.capture (rawCapture, format = "bgr")
print ("Tar bilde")
image = rawCapture.array

The trace of a person is approved or not.
approved = false

# load the input image and convert it from BGR to RGB
rgb = cv2.cvtColor (image, cv2.COLOR_BGR2RGB)