Discover specific OpenCV objects

After some research and reading OpenCV object detection information, I'm still not sure how I can detect a stick in a video frame. What would be the best way that I can detect, even if the user moves it. I use a stick as a sword and make a lightsaber out of it. Any points where I can start? Thanks!

+4
source share
3 answers

The answer to this question usually should be a Hough string conversion. The Hough transform is for finding straight lines (or other contours) in a scene, and OpenCV can parameterize these lines so you get the coordinates of the end points. But, wise word, if you make lightsaber effects, you don’t have to go that far - just draw an orange wand and make a key color. Standard feature of Adobe Premiere, Final Cut Pro, Sony Vegas, etc. OpenCV version is to convert your frame to HSV color mode and isolate areas of the image that lie in the desired area of ​​hue and saturation.

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

Here is an old routine that I wrote as an example:

//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; } 

A bit detailed, but you get the idea!

+7
source

You can start by using face recognition methods (training and detection) written for OpenCV.

If you are looking for specific steps, let me know.

+2
source

My old professor always said that the first law of computer vision is to do everything possible to make your work easier.

If you have control over the appearance of a stick, then you may have the best luck drawn with a stick of a very specific color β€” neon pink or something that is unlikely to appear in the background β€” and then use segmentation color in conjunction with the marking of the connected components. It will be very fast.

+2
source

All Articles