请问如何检测视频中的圆圈并从中获取坐标
我有一个像下面这样的代码,可以从图片中检测球,但是我可以问一下如何将其转换为检测视频版本并获取每一帧的球坐标吗?
import cv2
import numpy as np
img = cv2.imread('maze1.jpg')#讀取圖片
img=cv2.resize(img, (0,0), fx=0.2,fy=0.2)
GrayImage=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)#灰度化
GrayImage= cv2.medianBlur(GrayImage,5)#中值模糊
ret,th1 = cv2.threshold(GrayImage,127,255,cv2.THRESH_BINARY
th2 = cv2.adaptiveThreshold(GrayImage,255,cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY,3,5)
I have a code like this below which can detect the ball from the picture, but may I ask how could I transform it to detect the video version and get the ball's coordinate at each frame?
import cv2
import numpy as np
img = cv2.imread('maze1.jpg')#讀取圖片
img=cv2.resize(img, (0,0), fx=0.2,fy=0.2)
GrayImage=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)#灰度化
GrayImage= cv2.medianBlur(GrayImage,5)#中值模糊
ret,th1 = cv2.threshold(GrayImage,127,255,cv2.THRESH_BINARY
th2 = cv2.adaptiveThreshold(GrayImage,255,cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY,3,5)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
openCV 通常处理视频的方式是读取每一帧,分析和/或修改该帧,然后显示它。
因此,上述方法可以应用于视频的每个单独帧,或者如果足以满足您的需求或者您的目标解决方案和平台存在性能问题,则可以应用于每个“第 n”帧。
如果您查看 openCv 文档中的一些示例,您将看到这种类型的循环 - 例如:
您可以在此处看到完整的掩码示例和其他示例:https://docs.opencv.org/3.4/d1/dc5/tutorial_background_subtraction.html
The way openCV usually works with video is to read each frame, analyse and/or modify the frame, and then display it.
So your approach above can be applied to each individual frame of the video, or to every 'nth' frame if that is good enough for your needs or you have performance issues with your target solution and platform.
If you look at some of the examples in the openCv docs you will see this type of loop - e.g.:
You can see the full masking example and other examples here: https://docs.opencv.org/3.4/d1/dc5/tutorial_background_subtraction.html