Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The go-to answer for this would usually be the Hough line transform. The Hough transform is designed to find straight lines (or other contours) in the scene, and OpenCV can parameterize these lines so you get the endpoints coordinates. But, word to the wise, if you are doing lightsaber effects, you don't need to go that far - just paint the stick orange and do a chroma key. Standard feature of Adobe Premiere, Final Cut Pro, Sony Vegas, etc. The OpenCV version of this is to convert your frame to HSV color mode, and isolate regions of the picture that lie in your desired hue and saturation region.</p> <p><a href="http://opencv.itseez.com/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html?highlight=hough">http://opencv.itseez.com/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html?highlight=hough</a></p> <p>Here is an old routine I wrote as an example:</p> <pre><code>//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-&gt;width, image-&gt;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-&gt;width, image-&gt;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(&amp;saturation1); cvReleaseImage(&amp;saturation2); cvReleaseImage(&amp;hue2); return hue1; } </code></pre> <p>A little verbose, but you get the idea!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload