如何使我的彩色对象检测和跟踪程序更有效率? [英] How can i make my Colored object detection and tracking program more efficient?

查看:289
本文介绍了如何使我的彩色对象检测和跟踪程序更有效率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,感谢所有stackoverflow用户的帮助。对此,我真的非常感激。
因此,我做了一个彩色对象检测程序。我能够控制鼠标点击,甚至油漆一些东西在MS油漆。

现在,我必须在我的大学的工程设计比赛中介绍我的工作。我需要使我的程序更有效。首先,我已经用来跟踪和移动的对象是一个红色的对象,我通过调整HSV值过滤掉周围的颜色。
但是,当我在不同的环境中尝试我的代码时,我已经看到一些问题。周围有许多红色的对象,我的程序检测到这些对象,并给我错误的价值观。


所以,我的目标是: - 我必须让我的程序在几乎所有的环境中工作,使程序独立于背景。我的程序应该只跟踪和检测我想要的对象。因为,我是大一本科生,我的知识有限。所以,我想从stackoverflow专家的一些建议。谢谢。

解决方案

为了减少噪音(错误数量)检测),你可以尝试使用双阈值(我可能错了,但我认为它被称为滞后阈值,在Canny边缘检测器中使用的方法):


  1. 您需要创建2个图像,一个阈值为t1 = 50,另一个为t2 = 150(您可以调整参数以获得更稳定的性能,即试探性地找到最佳值)。

    li>
  2. 对于t2中的每个非黑色像素(x,y):floodFill t1在(x,y)

  3. p>现在t1应该有可能的颜色球的可能位置的可能性估计。



    注意:阈值不是必需的意味着你必须使用opencvthreshold功能。



    如果你只需要一个球,只需使用findContours功能找到最大面积的轮廓。



    不要试图实现100%的性能,记住:完美是好的敌人 - Arisotle。 >

    First of all, thanks to all the stackoverflow users for their help. I really appreciate it.
    So, I have made a colored object detection program. I am able to control the mouse clicks and even paint some stuffs in MS paint.

    Now, i have to present my work in my engineering design contest in my college. I need to make my program more effective. Firstly, the object that I have used to track and move is a red colored object and I filtered out the surrounding colors by adjusting the HSV values.
    But, I have seen some problems when I tried my code in different surroundings. There are many red colored objects in the surrounding and my program was detecting those objects and giving me false values.

    So, my goal is:- I have to make my program work in almost all surroundings and make the program independent of the background. My program should only track and detect the object I want. Since, I am a freshman undergraduate and my knowledge is limited. So, I want some advice from the stackoverflow experts. Thanks. Please I don't want source code as I want to understand and rectify my mistakes.

    解决方案

    To reduce noise (number of false detections) you can try to use double thresholding (I maybe wrong, but I think it is called hysteresis thresholding, approach used in Canny edge detector):

    1. You need to create 2 images, one thresholded with t1=50, another with t2=150 (you can adjust parameters to get more stable performance, i.e. heuristically find the optimal values).

    2. For each non black pixel (x,y) in t2: floodFill t1 with gray at (x,y), floodFill t2 with black at (x,y)

    3. once done erase all non-gray pixels in t1.

    Now t1 should have a good likelihood estimate for possible positions of the colored ball.

    Note: Thresholding doesn't neccessaraly means that you have to use opencv "threshold" function. You can write your own that takes as an input a color and a range within which the colors will be passed.

    If you are looking for only one ball, simply use findContours function to find contour with the biggest area.

    Don't try to achieve 100% performance, remember: "Perfect is the enemy of good" - Arisotle.

    这篇关于如何使我的彩色对象检测和跟踪程序更有效率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆