(转)python+opencv实现动态物体追踪,,原文链接:https
(转)python+opencv实现动态物体追踪,,原文链接:https
原文链接:https://blog.csdn.net/cike14/article/details/50649811
import cv2 import numpy as np camera=cv2.VideoCapture(0) firstframe=None while True: ret,frame = camera.read() if not ret: break gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) gray=cv2.GaussianBlur(gray,(21,21),0) if firstframe is None: firstframe=gray continue frameDelta = cv2.absdiff(firstframe,gray) thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1] thresh = cv2.dilate(thresh, None, iterations=2) # cnts= cv2.findContours(thresh.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) x,y,w,h=cv2.boundingRect(thresh) frame=cv2.rectangle(frame,(x,y),(x+w,y+h),(0,0,255),2) cv2.imshow("frame", frame) cv2.imshow("Thresh", thresh) cv2.imshow("frame2", frameDelta) key = cv2.waitKey(1)&0xFF if key == ord("q"): break camera.release() cv2.destroyAllWindows()
效果图
(转)python+opencv实现动态物体追踪
相关内容
- Django项目的创建与管理和pycharm与Github的秘密,,随笔
- win7中python3.4下安装scrapy爬虫框架(亲测可用),,貌似
- Python开发简单爬虫(一),,一 、简单爬虫架构:
- Python之小作业,,文档如下:# nam
- Python学习-37.Python中的正则表达式,,作为一门现代语言
- python-锁机制,, 1 锁 2 Lo
- Python3学习-基础,,1.直接运行.py文
- python快速教程,,网上有个人写的pyt
- [leetcode]Divide Two Integers @ Python,,原题地址:https
- Python list去重及找出,统计重复项,,http://bbs
评论关闭