current position:Home>Python+opencv+dlib to achieve target tracking
Python+opencv+dlib to achieve target tracking
2022-07-25 15:10:26【weixin_ forty-two million seven hundred and nine thousand five 】
Background introduction
Dlib Is a deep learning open source tool , be based on C++ Development , Also support Python Development interface , Function like TensorFlow And PyTorch, because dlib It has good support for facial features , There are many trained face feature extraction models for developers to use , therefore dlib It is very suitable for face project development . Concrete dlib The environment configuration method will not be repeated here , There are many related tutorials on the Internet for reference .
Target tracking
In application ,dlib In most cases, it is used for face detection and face recognition , However ,dlib It can also be used for object tracking , By calling Python API Medium dlib.correlation_tracker Class can implement a preliminary tracking result , It is divided into the following four steps :
(1) Use dlib.correlation_tracker() Create a trace class ;
(2) start_track() Set the box in the picture to track the target object ;
(3) update() Track the next frame in real time ;
(4) get_position() Get the location of the tracked target .
import cv2
import dlib
import glob
# Import face detector , Tracker and required pictures
detector = dlib.get_frontal_face_detector()
tracker = dlib.correlation_tracker()
paths = sorted(glob.glob('video_frames/*.jpg')) #video_frames Is the folder where the current picture is located
# Track the target object in the picture
for i, path in enumerate(paths):
img = cv2.imread(path)
if i == 0:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Convert to gray image processing
dets = detector(gray, 1) #1 It means to double the size of the picture , Easy to detect more faces
d=dets[0] # Suppose there is only one face in the picture
tracker.start_track(img, dlib.rectangle(d.left(),d.top(),d.right(),d.bottom()))
# Subsequent frames , Automatic tracking
else:
tracker.update(img)
box_predict = tracker.get_position() # Get the location of the target
cv2.rectangle(img,(int(box_predict.left()),int(box_predict.top())),(int(box_predict.right()),int(box_predict.bottom())),(0,255,255),1)
cv2.imshow('image',img)
if cv2.waitKey(10) == 27:
break
cv2.destroyAllWindows()
After setting up the running code , We can achieve the tracking effect we want .
copyright notice
author[weixin_ forty-two million seven hundred and nine thousand five ],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/206/202207251506571195.html
The sidebar is recommended
- Python collection
- Python simple test
- Python requests module
- How to write the formula y=a*exp (b*x) as a condition in python (parameter estimation program using least square fitting)
- Python modulenotfounderror: no module named '* * *' solution
- Numpy of Python learning
- Python Wu Enda deep learning assignment 17 -- deep learning and art neurostyle transfer (NST)
- Python output font color
- Pandas modify column
- leetcode 240. Search a 2D Matrix II(python)
guess what you like
How does Django realize remote file download?
How does Python count the number of lines?
Python uses ARIMA and arimax to predict the time series data of store commodity sales demand
Python reads all the pictures in the folder and writes the picture names line by line into TXT
Django3 ----- views and simple templates
Web development Python
Django 2 ----- database and admin
Django 1 ----- installation and start-up
What is the reason why Python socket client reports an error connection reset by peer?
Detailed explanation of static method usage in Python
Random recommended
- Python_ Simulate login to QQ email & save cookies
- Python_ Crawl_ Spider crawls the recruitment network
- Python pit entry Guide
- Vscode Python code completion repetition
- Python decorator with parameters
- Python list deep copy shallow copy
- Django+vue quickly realizes blog website
- Python data analysis and machine learning 27 examples of spelling correction
- Python data analysis and machine learning 28 news classification
- After reading so many Python tutorials, the most delicious thing is
- Several ways for Python to write xlsx files
- Summary of Python object-oriented details
- Python multi process / process pool / shared data between processes practical scenario analysis and practice pit records
- How to import sort into pandas foundation?
- What are columns in pandas foundation?
- Why not use apply in pandas foundation?
- Python decorator engineering examples and key points summary
- Triplicate in Python
- Implementation, encapsulation and call of paging function in Django (super detailed)
- Learning pandas, you can't stop at all
- Automation appium common API (Python version)
- Python packaged exe flash back (packaged installer flash back)
- Automation appium wechat applet (Python version)
- Automation appium wechat official account (Python version)
- Automation appium get toast message (Python version)
- Automation appium connect the real machine through WiFi for automatic testing (Python version)
- Some thoughts on pooling in Python -2022
- How to change all values into lowercase in pandas data processing?
- [Python Script] this time I rewritten SVN in another language_ back
- Python data type
- Does Python Tkinter have a quick tutorial
- How does Python import all data in Excel tables into SQL Server database in batches?
- How to segment words according to sentences in Python?
- Pythonnote026 --- automatic email
- Pythonnote027--- flattening operation of nested list
- Pythonnote028--- list filtering and extraction
- PyPackage01---Pandas11_ Use of explode method
- Pythonnote029 --- Python queries memory and CPU Information
- Pythonnote030 --- use of sklearn nearest neighbor API
- PyPackage01---Pandas12_ print dataframe