Cal*_*kie 4 opencv image-processing visual-c++ kinect
在做了一些关于OpenCV对象检测的研究和阅读信息后,我仍然不确定如何在视频帧中检测到一根棍子.什么是最好的方式,所以即使用户移动它我也能检测到.我会用棍子作为剑,并用它制作光剑.我可以从哪里开始?谢谢!
对此的回答通常是霍夫线变换.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;
}
Run Code Online (Sandbox Code Playgroud)
有点冗长,但你明白了!