【发布时间】:2011-10-10 03:09:08
【问题描述】:
在做了一些关于 OpenCV 对象检测的研究和阅读信息之后,我仍然不确定如何检测视频帧中的棒。什么是最好的方法,所以即使用户移动它我也可以检测到。我会把棍子当作剑,用它做光剑。关于我可以从哪里开始的任何要点?谢谢!
【问题讨论】:
标签: visual-c++ image-processing opencv kinect
在做了一些关于 OpenCV 对象检测的研究和阅读信息之后,我仍然不确定如何检测视频帧中的棒。什么是最好的方法,所以即使用户移动它我也可以检测到。我会把棍子当作剑,用它做光剑。关于我可以从哪里开始的任何要点?谢谢!
【问题讨论】:
标签: visual-c++ image-processing opencv kinect
对此的首选答案通常是霍夫线变换。 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;
}
有点冗长,但你明白了!
【讨论】:
findContours你的二进制图像。用contourArea 找到最大的contour,然后用minAreaRect 得到一个RotatedRect,一个围绕contour 的边界形状。 RotatedRect 的高度就是你的棍子长度。
我的老教授总是说,计算机视觉的第一定律是尽你所能对图像做任何事情,让你的工作更轻松。
如果您可以控制棒的外观,那么您最好将棒涂上非常特殊的颜色 --- 霓虹粉或不太可能出现在背景中的东西 --- 然后使用颜色分割与连接组件标记相结合。那会非常快。
【讨论】:
您可以从为 OpenCV 编写的人脸识别(训练和检测)技术开始。
如果您正在寻找具体步骤,请告诉我。
【讨论】: