当前位置:网站首页>Opencv implements object tracking
Opencv implements object tracking
2022-06-27 05:17:00 【Keep_ Trying_ Go】
List of articles
1. Contour finding and contour drawing
https://mydreamambitious.blog.csdn.net/article/details/125339604
2. Gaussian denoising
https://mydreamambitious.blog.csdn.net/article/details/125203273
3. Corrosion and expansion
https://mydreamambitious.blog.csdn.net/article/details/125265431
4.cv2.inRange function
effect :rgb Color space to hsv Color space , The color removes the white background
Parameters :
The first parameter :hsv Refers to the input original drawing ;
The second parameter :lower_red It's below this in the image lower_red Value , The pixel value becomes 0;
The third parameter :upper_red It's higher than this in the image upper_red Value , The pixel value becomes 0;
5.cv2.minEnclosingCircle function
Function function : Get the smallest circle containing two-dimensional point set
Parameters :
InputArray points: Input two-dimensional point set ;
Point2f& center: Represents the center coordinate of the output circle , yes float type ;
float& radius: The radius of the smallest circle output , yes float type ;
6.cv2.moments function
Find the moment of the contour :
mu = cv.moments(contour) #contour It's an outline
cx = mu[‘m10’] / mu[‘m00’] # outline contour Abscissa of the center of mass of
cy = mu[‘m01’] / mu[‘m00’] # outline contour The ordinate of the center of mass of
https://blog.csdn.net/Caesar6666/article/details/103257632
7. Code combat
import os
import cv2
import numpy as np
cap=cv2.VideoCapture(0)
# Set up RGB->HSV Low threshold and high threshold
Obj_low=np.array([0,0,0])
Obj_high=np.array([179,157,79])
while cap.isOpened():
OK,frame=cap.read()
if OK==False:
break
# Flip the picture ,Opencv The image read is the opposite of our normal display
img=cv2.flip(src=frame,flipCode=2)
img=cv2.resize(src=img,dsize=(600,600))
# Gaussian processing of the image
gauss=cv2.GaussianBlur(src=img,ksize=(3,3),sigmaX=0)
# Convert the image to grayscale
gray=cv2.cvtColor(src=gauss,code=cv2.COLOR_BGR2HSV)
inrange=cv2.inRange(src=gray,lowerb=Obj_low,upperb=Obj_high)
# Corrode the image
kernel=cv2.getStructuringElement(shape=cv2.MORPH_RECT,ksize=(3,3))
erode=cv2.erode(src=inrange,kernel=kernel,iterations=2)
# Inflate the graph
dilate=cv2.dilate(src=erode,kernel=kernel,iterations=2)
# Find the outline
contours,hierarchy=cv2.findContours(image=dilate,mode=cv2.RETR_TREE,
method=cv2.CHAIN_APPROX_SIMPLE)
maxArea=0
index=0
length=len(contours)
if length>0:
for i in range(length):
# Calculate the area of the contour
area=cv2.contourArea(contours[i])
if area>maxArea:
maxArea=area
index=i
# Get the circle containing the minimum point set
((x,y),radius)=cv2.minEnclosingCircle(contours[index])
M=cv2.moments(contours[index])
center=(int(M['m10']/M['m00']),int(M['m01']/M['m00']))
if radius>5:
cv2.circle(img=img,center=center,radius=2,
color=(0,255,0),thickness=-1)
cv2.circle(img=img,center=center,radius=int(radius),
color=(0,0,255),thickness=3)
cv2.imshow('image',img)
if cv2.waitKey(1)&0xFF==27:
break
cv2.destroyAllWindows()
if __name__ == '__main__':
print('Pycharm')
边栏推荐
- 躲避小行星游戏
- 015 basics of C language: C structure and common body
- 微服务系统设计——分布式事务服务设计
- EasyExcel合并相同内容单元格及动态标题功能的实现
- Almost because of json Stringify lost his bonus
- 论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》
- 重映像(STM32)
- Microservice system design -- Distributed timing service design
- Execution rules of pytest framework
- 010 C language foundation: C function
猜你喜欢

Microservice system design -- distributed cache service design

双位置继电器RXMD2-1MRK001984 DC220V

Microservice system design -- microservice monitoring and system resource monitoring design

【B站UP DR_CAN学习笔记】Kalman滤波1

【622. 设计循环队列】

Reading graph augmentations to learn graph representations (lg2ar)

Asp.Net Core6 WebSocket 简单案例
![[station B up dr_can learning notes] Kalman filter 2](/img/52/777f2ad2db786c38fd9cd3fe55142c.gif)
[station B up dr_can learning notes] Kalman filter 2

微服务系统设计——分布式定时服务设计

机械转码日记【17】模板,STL简介
随机推荐
Microservice system design -- service registration, discovery and configuration design
halcon常用仿射变换算子
微服务系统设计——API 网关服务设计
微服务系统设计——微服务监控与系统资源监控设计
重映像(STM32)
齐纳二极管 稳压二极管 SOD123封装 正负区分
006 C language foundation: C storage class
Microservice system design -- API gateway service design
双位置继电器XJLS-8G/220
The most detailed download tutorial of MySQL
高翔slam14讲-笔记1
Neo4j database export
Interview: what are the positioning methods in selenium? Which one do you use most?
unity点光源消失
Microservice system design -- distributed cache service design
007 C语言基础:C运算符
双位置继电器DLS-34A DC0.5A 220VDC
Microservice system design -- distributed transaction service design
golang hello 安装环境异常【已解决】
014 C语言基础:C字符串