Python real-time video capture (with source code

This article is “face recognition complete project combat” series of blog post part 3: programming (Python version), the first section “Python real-time video capture program design”, this chapter content system introduction: based on Python+ OpencV how to achieve real-time video capture.

Complete related content has been recorded into the video course, click jump: “Face recognition complete project combat (attached source code)”

The entire system architecture structure of face recognition complete project combat is shown as follows:

Project overview: the system introduces the face recognition project system architecture design, project key technology description, project business demand analysis, project business process design;

Environment deployment: C++ and Python two programming language versions, the system introduces the project development environment overview, DLib framework source code compilation, project engineering file creation, project development environment configuration, project performance optimization Settings;

Program design: from the beginning of real-time video collection, covering face area detection, face feature point calibration, face alignment, face comparison and in vivo detection of all technical links of code design, running demonstration and execution results output;

Model training: based on the face recognition area detection and two recognition feature point calibration two application scenarios, introduces the process of data sample collection, algorithm model training and algorithm model testing, so that everyone has a complete intuitive understanding of face recognition;

Algorithm principle: based on face recognition area detection and two recognition feature point calibration two application scenarios, face area detection and face feature point calibration algorithm principle and implementation mechanism, so that we can effectively associate face recognition with machine learning, deep learning;

Learning framework: a systematic introduction to the mainstream deep learning framework, focusing on the introduction of Dlib deep learning framework used in this course, through Dlib deep learning case 1 and Dlib deep learning case 2, two complete cases, let everyone have an intuitive understanding of Dlib deep learning framework;

Second, the body

2.1 Program Logic

The main flow of Python real-time video capture program is divided into 10 steps, as shown below:Copy the code

Process Description:

Library file import: Import the Python installation package that the program depends on.

Camera management object creation and initialization: is the creation and initialization of opencV VideoCapture object, through which to open the camera device;

Start cycle monitoring: cycle processing each frame picture;

Image capture: use the camera management equipment provided by OpencV to capture image content frame by frame and then process it;

Image window display: Using opencV window object, capture content display.

Waiting for user input: Use the keyboard input monitoring program provided by OpencV to obtain user instructions.

Release camera: After receiving the exit command, release the camera to manage device resources.

2.2 Interface Description

The realization of Python real-time video surveillance and collection function mainly adopts the camera management class: VideoCapture provided by OpencV open source framework. The main methods and properties of this class are shown below:Copy the code

Opencv camera management class, we mainly applied its open (open camera), read (read every frame), release (release device) and other functions.

2.3 Source code Design

Source code execution, need to import opencV library file, directly execute: PIP install Opencv can be achieved. The specific program code is shown in the figure below:

Real-time: Video Image Capture (OpencV)

import cv2

cap = cv2.VideoCapture(0)

Loop frames from video stream

while True:

ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow("Frame", frame)
# exit: Q
if cv2.waitKey(1) & 0xFF == ord('q') :breakCopy the code

Clean the window

Cv2.destroyallwindows () 2.4 Run effect

Three, to be continued

This article is “face recognition complete project combat” series of blog post part 3: programming (Python version) the first section “Real-time video acquisition programming (Python)”, the full text of 53 chapters, continue to update, please pay attention to. Face recognition technology communication QQ group: 887934385.