【问题标题】:OpenCV specific object detectionOpenCV 特定对象检测
【发布时间】:2011-10-10 03:09:08
【问题描述】:

在做了一些关于 OpenCV 对象检测的研究和阅读信息之后,我仍然不确定如何检测视频帧中的棒。什么是最好的方法,所以即使用户移动它我也可以检测到。我会把棍子当作剑,用它做光剑。关于我可以从哪里开始的任何要点?谢谢!

【问题讨论】:

    标签: visual-c++ image-processing opencv kinect


    【解决方案1】:

    对此的首选答案通常是霍夫线变换。 Hough 变换旨在找到场景中的直线(或其他轮廓),OpenCV 可以参数化这些直线,以便您获得端点坐标。但是,明智的说法是,如果你正在制作光剑效果,你不需要走那么远 - 只需将棒涂成橙色并做一个色度键。 Adobe Premiere、Final Cut Pro、Sony Vegas 等的标准功能。OpenCV 版本将您的帧转换为 HSV 颜色模式,并隔离位于所需色调和饱和度区域的图片区域。

    http://opencv.itseez.com/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html?highlight=hough

    这是我写的一个旧例程作为例子:

    //Photoshop-style color range selection with hue and saturation parameters.
    //Expects input image to be in Hue-Lightness-Saturation colorspace.
    //Returns a binary mask image. Hue and saturation bounds expect values from 0 to 255.
    IplImage* selectColorRange(IplImage *image, double lowerHueBound, double upperHueBound, 
                    double lowerSaturationBound, double upperSaturationBound) {
        cvSetImageCOI(image, 1);  //select hue channel
        IplImage* hue1 = cvCreateImage(cvSize(image->width, image->height), IPL_DEPTH_8U, 1);
        cvCopy(image, hue1); //copy hue channel to hue1
        cvFlip(hue1, hue1); //vertical-flip
        IplImage* hue2 = cvCloneImage(hue1); //clone hue image
        cvThreshold(hue1, hue1, lowerHueBound, 255, CV_THRESH_BINARY); //threshold lower bound
        cvThreshold(hue2, hue2, upperHueBound, 255, CV_THRESH_BINARY_INV); //threshold inverse upper bound
        cvAnd(hue1, hue2, hue1); //intersect the threshold pair, save into hue1
        cvSetImageCOI(image, 3); //select saturation channel
        IplImage* saturation1 = cvCreateImage(cvSize(image->width, image->height), IPL_DEPTH_8U, 1);
        cvCopy(image, saturation1); //copy saturation channel to saturation1
        cvFlip(saturation1, saturation1); //vertical-flip
        IplImage* saturation2 = cvCloneImage(saturation1); //clone saturation image
        cvThreshold(saturation1, saturation1, lowerSaturationBound, 255, CV_THRESH_BINARY); //threshold lower bound
        cvThreshold(saturation2, saturation2, upperSaturationBound, 255, CV_THRESH_BINARY_INV); //threshold inverse upper bound
        cvAnd(saturation1, saturation2, saturation1); //intersect the threshold pair, save into saturation1
        cvAnd(saturation1, hue1, hue1); //intersect the matched hue and matched saturation regions
        cvReleaseImage(&saturation1);
        cvReleaseImage(&saturation2);
        cvReleaseImage(&hue2);
        return hue1;
    }
    

    有点冗长,但你明白了!

    【讨论】:

    • 我应该使用 blob 跟踪器来获取我的棍子的长度吗?还是有其他方法可以获得我的棍子的起点和终点?谢谢!
    • 你可以findContours你的二进制图像。用contourArea 找到最大的contour,然后用minAreaRect 得到一个RotatedRect,一个围绕contour 的边界形状。 RotatedRect 的高度就是你的棍子长度。
    • 我使用了 findContours,我认为创建的矩形不是那么稳定,尤其是在对象移动时。然后我使用了霍夫变换 CV_HOUGH_PROBABILISTIC,它完成了这项工作。非常感谢。
    【解决方案2】:

    我的老教授总是说,计算机视觉的第一定律是尽你所能对图像做任何事情,让你的工作更轻松。

    如果您可以控制棒的外观,那么您最好将棒涂上非常特殊的颜色 --- 霓虹粉或不太可能出现在背景中的东西 --- 然后使用颜色分割与连接组件标记相结合。那会非常快。

    【讨论】:

      【解决方案3】:

      您可以从为 OpenCV 编写的人脸识别(训练和检测)技术开始。

      如果您正在寻找具体步骤,请告诉我。

      【讨论】:

      • 嗯...不知道这对追踪一根棍子有多大影响。
      • 嗨,马特,想一想:一根棍子,通常被想象成一个圆柱形物体。可以位于 3D 空间中任何位置的圆柱体。在某些情况下,我们可以像笔一样检测和跟踪类似的圆柱形物体!同样,此类对象的独特特征总是有助于改进检测/跟踪。因此,您可能必须对这根“棍子”上的显着特征进行分类。此类物体的样本图像,无论是正面还是负面,肯定会帮助我改进对您的建议。
      • 有人,我猜你添加了霍夫变换代码来检测棍子!但是必须考虑任何物体的方向。遮挡是另一方面。 Lowe 的论文可以在这方面提供帮助。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-23
      • 2021-07-29
      • 1970-01-01
      • 2010-09-21
      • 2011-11-30
      • 2013-01-24
      相关资源
      最近更新 更多