I would like to reliably detect the presence of a human within a defined radius of a fixed place in a room. Think of a diamond in an art museum -- if there's a person within 5 feet of it, I could use the sensor to output a signal as a continuous 1 otherwise 0. Further, would it also work for a half-circle (such as a portrait on the wall in the museum)?

I am currently doing this with OpenCV and a webcam, but there's too much delay > 200 ms in processing. I'm hoping for a better approach that can provide latency < 20 ms.

enter image description here

  • 2
    \$\begingroup\$ "better approach": better is a term relative to your metric of goodness. What's good about a solution? What's bad about the webcam solution? Also, what kind of objects are you detecting, and is the radius actually 5 ft (um, that's 1.5 m, right?)? \$\endgroup\$ Commented Oct 23, 2020 at 19:53
  • 2
    \$\begingroup\$ I think you’re getting pushback because there’s not an obvious elegant solution better than the one you have without knowing more constraints. Could do an array of sonar but there would be gaps. Could do IR but a circular pattern would be tricky. Might be able to do this with lidar but range is an issue. \$\endgroup\$
    – Jack Wade
    Commented Oct 24, 2020 at 12:15
  • \$\begingroup\$ Without much, much more information this can not be answered. In particular, put bounds on the size, shape, surface material, and velocity of the "object". \$\endgroup\$ Commented Oct 24, 2020 at 12:34
  • \$\begingroup\$ Revised, can you take another look? @MarcusMüller \$\endgroup\$ Commented Oct 24, 2020 at 12:59
  • \$\begingroup\$ @y3sh thanks! is the type of object actually "people"? \$\endgroup\$ Commented Oct 24, 2020 at 13:00

2 Answers 2


This should be a relatively simple problem, as much as the comments and answers are saying otherwise. Just to give my background before I go into the answer and also ask more questions, I work with sensors every day to detect positions of objects (humans, or fixed objects).

Going off of your diagrams:

  1. I am going to assume the "detector" (all hardware for detecting your person) is right under or above the art picture. So it is at a fixed height above the ground
  2. You are only detecting people above a certain height. So you can not determine if there is a mouse within 5 feet, but can detect a small child.
  3. You are only interested in detecting a semi-circle from the picture, so you are looking out from a wall. This is not an unbreakable assumption, just changes the hardware a bit.

The first solution I would propose is a 2D LiDAR. This is literally what its designed for. There are many, many, many 2D lidars. Ranging from $100 to over $10,000. I personally have this lidar. So if you are just looking at doing this for a school project (not a product), I would go with that lidar, and a raspberry pi. Maybe 4-8 hours of some python code running and you are up and running. This should be almost near real time, with the biggest limitation coming from the OS on the pi, and python vs something like C/C++ (so basically no delays unless you programmed it terribly).

A bit about lidar:

  1. They fire multiple lasers (or a single laser spinning) and measure the time it takes to get back. So they are super fast, and super accurate on range.
  2. They will either provide you exact x/y locations of targets, or distance and an angle which you then turn into x/y locations (search polar coordinates).
  3. They have a fixed interval or gap between angles. So it will fire a laser at 0 degrees, and then maybe 1 degree later, and 2, etc. So it is possible to have something in between the firing angles, however that really only comes to play for long long distances. A big object (a person) at a small distance (5 feet) will almost definitely be detected

So all you would need to do is say "if lidar returns distance <5ft, there is a person there". The lidar I have and recommended talks over USB but looks like serial data, and there are some open source drivers to connect/read the data from it.

Edit: Also with a 2D lidar you have the ability to detect if there are multiple people/objects. This is exactly how self driving cars and robots (my area of work) detect obstacles. Just with fancier versions of lidars and computers.


I agree with user2840470's lidar approach. It's certainly the most versatile.

The classical way of such presence detection would be through movement detection – through a rather boring PIR motion sensor. But: that will literally not catch someone who's moving slow enough, or carrying a room-temperature shield or something.

If this isn't good enough, I actually think your webcam solution is fine; in fact, while 20 ms doesn't sound easy, it sounds far from impossible – I'd expect latency from camera sensor to "frame in userland software" to be in the 5 to 15 ms range, which gives you plenty of time to do detection (assuming don't try to go too high-level, but keep it simple: get the lowest feasible resolution from the camera, avoid unnecessary processing steps like complex color space conversions (greyscale or IR camera would do) and do a very simple cross-correlation with a reference scene, especially if lighting is internal or reliable (infrared lighting?).

Other than that, there's cheap ultrasonic distance sensors. You'd need an array of these, and you need to use them in sequence so not to confuse them with each other, but it does sound feasible, too. Speed might be a limit (sound travels at 300 m/s, so for 1.5m you'd need 1/200 of a second, i.e. 5 ms already), but since the processing would be arduino-level simple, that might work.

Your 20 ms time frame might indicate this is safety-critical ("stop this spinning blade of destruction and painful death if someone comes close to it within 20 ms, or there will be minced employee"); in that case, don't build yourself. Use laser curtains (an array of beams, or one beam zig-zagging between two aligned mirrors) and hardware (or very low-level firmware) interlocks; your latency will be almost 0.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.