visual-c++ - OpenCV 特定物体检测

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

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

最佳答案

对此的首选答案通常是霍夫线变换。霍夫变换旨在寻找场景中的直线(或其他轮廓),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;
}

有点冗长,但你明白了!

关于visual-c++ - OpenCV 特定物体检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7708179/

相关文章:

c++ - libtorrent 和 tcp::acceptor 在 Windows 上因访问冲突而崩溃

c++ - 枚举数组作为参数 c++

c++ - 如何定义 lib 文件的依赖关系?

python - 在多个轮廓CV2上拟合边界椭圆

c++ - LSH 和 ORB opencv?

c++ - Visual Studio 2013 代码分析卡在 native 代码上

java - 使用Java以多线程模式进行图像处理

python - 寻找物体中心: showing wrong coordinate outside of the target object

python - 安装了 Opencv 但是 python 找不到包

selenium - 使用 WinAPpDriver 对 Windows 桌面应用程序和 C# 进行图像比较和可视化测试