python - 使用 opencv 识别球时遇到问题

标签 python opencv image-processing

我正在尝试创建一个简单的程序来检测球在图像中的位置。问题是我从网上找到的任何东西都得到了一些奇怪的输出。我一直主要使用 pyimagesearch 的 adrian 提供的示例。链接如下 www.pyimagesearch.com/2015/09/14/ball-tracking-with-opencv/

这是 original image这是另一个processed image .

我不知道该尝试什么。到目前为止,我已经尝试编辑程序来绘制所有轮廓,只是为了查看是否检测到球。我看着规范化图像,但这似乎没有任何帮助。任何帮助,将不胜感激。

按照建议,我尝试了一种非基于颜色的方法。 Hough Circles 最终为我工作。它只有大约 66% 的时间看到球,但其他 33% 的时间它只是看不到任何改进(因为我正在使用它生成的数据,我不能有误报)。下面是霍夫圆的魔力。

while True:
    # grab the current frame
    (grabbed, frame) = camera.read()
    frame = cv2.flip(frame, -1)
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    frame = cv2.GaussianBlur(frame, (9,9), 2)
    circles = cv2.HoughCircles(frame, cv2.cv.CV_HOUGH_GRADIENT, 1, 100, 50, 10)
    if circles is not None:
        # convert the (x, y) coordinates and radius of the circles to integers
        circles = np.round(circles[0, :]).astype("int")

        # loop over the (x, y) coordinates and radius of the circles
        for (x, y, r) in circles:
            # draw the circle in the output image, then draw a rectangle
            # corresponding to the center of the circle
            cv2.circle(frame, (x, y), r, (0, 255, 0), 4)
            cv2.rectangle(frame, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)

    cv2.imshow("Frame", frame)

最佳答案

写出您的蒙版图像的副本。我会说图像顶部的毯子(?)与您的颜色范围重叠,因此它将其用作检测球位置的数据的一部分。这似乎与目标的大小和位置有关。

关于python - 使用 opencv 识别球时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36347152/

相关文章:

python - 使用 Pandas 加入 2 CSV

python - 读取文件并转换值 "'列表'对象没有属性 'find'”

python - keras model.fit 函数打印的准确率与验证集还是训练集有关?

python - 在 Python 中使用 dlib 训练对象检测器

opencv - 在立体相机中找到右图像上对应的 2d 点

python - traincascade、分类器和 openCV

c++ - 如何在 OpenCV 中获取特定元素的行和列?

image-processing - 模糊图像的阈值 - 第 2 部分

android - 以编程方式将 GIF 转换为 PNG

python - 如何将分割的图像与重叠合并