首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenCV特定对象检测

OpenCV特定对象检测
EN

Stack Overflow用户
提问于 2011-10-10 11:09:08
回答 3查看 2.8K关注 0票数 4

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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-10-13 09:12:18

这个问题的首选答案通常是霍夫线变换。霍夫变换旨在查找场景中的直线(或其他轮廓),OpenCV可以对这些直线进行参数化,以便您获得端点坐标。但是,明智的话,如果你正在做光剑效果,你不需要走那么远-只需将棍子涂成橙色并做色度键即可。标准功能的Adobe Premiere,Final Cut Pro,索尼维加斯等OpenCV版本的这是转换您的帧到HSV颜色模式,并隔离区域的图片位于您想要的色调和饱和度区域。

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

以下是我编写的一个旧例程作为示例:

代码语言:javascript
复制
//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;
}

有点罗嗦,但你明白我的意思!

票数 7
EN

Stack Overflow用户

发布于 2011-10-10 22:03:03

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

如果您正在寻找具体的步骤,请让我知道。

票数 2
EN

Stack Overflow用户

发布于 2011-10-13 09:27:35

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

如果你能控制棒子的外观,那么你可能会有最好的运气,把棒子涂成一种非常特殊的颜色-霓虹灯粉色或不太可能出现在背景中的东西-然后使用颜色分割与连接分量标记相结合。这将是非常快的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7708179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档