Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would go with something as simple as thresholding for near and far depths, using the <strong>and</strong> operation to merge the two and find the contours in the resulting image. </p> <p>It's not super flexible as you're kind of hard coding a depth range (a minimum human height expected), but it's easy to setup/tweak and shouldn'be that costly computationally. Optionally you can use a bit of blur and erode/dilate to help refine the contours.</p> <p>Although it has more than what I explained, you can see a demo <a href="http://lifesine.eu/rec/cv3c.mov" rel="nofollow noreferrer">here</a> <img src="https://i.stack.imgur.com/mgYsE.png" alt="CV threshold and contours"></p> <p>And here's a basic example using OpenCV with OpenNI:</p> <pre><code>#include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include &lt;iostream&gt; using namespace cv; using namespace std; int threshNear = 60; int threshFar = 100; int dilateAmt = 1; int erodeAmt = 1; int blurAmt = 1; int blurPre = 1; void on_trackbar(int, void*){} int main( ) { VideoCapture capture; capture.open(CV_CAP_OPENNI); if( !capture.isOpened() ) { cout &lt;&lt; "Can not open a capture object." &lt;&lt; endl; return -1; } cout &lt;&lt; "ready" &lt;&lt; endl; vector&lt;vector&lt;Point&gt; &gt; contours; namedWindow("depth map"); createTrackbar( "amount dilate", "depth map", &amp;dilateAmt,16, on_trackbar ); createTrackbar( "amount erode", "depth map", &amp;erodeAmt,16, on_trackbar ); createTrackbar( "amount blur", "depth map", &amp;blurAmt,16, on_trackbar ); createTrackbar( "blur pre", "depth map", &amp;blurPre,1, on_trackbar ); createTrackbar( "threshold near", "depth map", &amp;threshNear,255, on_trackbar ); createTrackbar( "threshold far", "depth map", &amp;threshFar,255, on_trackbar ); for(;;) { Mat depthMap; if( !capture.grab() ) { cout &lt;&lt; "Can not grab images." &lt;&lt; endl; return -1; } else { if( capture.retrieve( depthMap, CV_CAP_OPENNI_DEPTH_MAP ) ) { const float scaleFactor = 0.05f; Mat show; depthMap.convertTo( show, CV_8UC1, scaleFactor ); //threshold Mat tnear,tfar; show.copyTo(tnear); show.copyTo(tfar); threshold(tnear,tnear,threshNear,255,CV_THRESH_TOZERO); threshold(tfar,tfar,threshFar,255,CV_THRESH_TOZERO_INV); show = tnear &amp; tfar;//or cvAnd(tnear,tfar,show,NULL); to join the two thresholded images //filter if(blurPre == 1) blur(show,show,Size(blurAmt+1,blurAmt+1)); Mat cntr; show.copyTo(cntr); erode(cntr,cntr,Mat(),Point(-1,-1),erodeAmt); if(blurPre == 0) blur(cntr,cntr,Size(blurAmt+1,blurAmt+1)); dilate(cntr,cntr,Mat(),Point(-1,-1),dilateAmt); //compute and draw contours findContours(cntr,contours,0,1); drawContours(cntr,contours,-1,Scalar(192,0,0),2,3); //optionally compute bounding box and circle to exclude small blobs(non human) or do further filtering,etc. int numContours = contours.size(); vector&lt;vector&lt;Point&gt; &gt; contours_poly( numContours ); vector&lt;Rect&gt; boundRect( numContours ); vector&lt;Point2f&gt; centers( numContours ); vector&lt;float&gt; radii(numContours); for(int i = 0; i &lt; numContours; i++ ){ approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true ); boundRect[i] = boundingRect( Mat(contours_poly[i]) ); minEnclosingCircle(contours_poly[i],centers[i],radii[i]); rectangle( cntr, boundRect[i].tl(), boundRect[i].br(), Scalar(64), 2, 8, 0 ); circle(cntr,centers[i],radii[i],Scalar(192)); } imshow( "depth map", show ); imshow( "contours", cntr ); } } if( waitKey( 30 ) == 27 ) break;//exit on esc } } </code></pre> <p>Even if you're not using OpenNI to grab the depth stream you can still plug the depth image into OpenCV. Also, you can detect the bounding box and circle which might help filter things further a bit. Say you're setup is in an office space, you might want to avoid a column, tall plant,shelves, etc. so you can check the bounding circle's radius or bounding box's width/height ratio.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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