1
$\begingroup$

I want to detect door blockage on a camera. Basically if the exit door is blocked by an object, it detects it as an anomaly. How can we do it? Is it possible to do it using OpenCV?

Remember, it doesn’t catch light or shadow changes, so it understands object blockage.

enter image description here

$\endgroup$
2
  • $\begingroup$ Would it be enough to check if blue area is a rectancle, perhaps? $\endgroup$
    – Jonas
    Jul 25, 2023 at 21:59
  • $\begingroup$ Not that easy!! $\endgroup$
    – Tina J
    Jul 26, 2023 at 1:54

2 Answers 2

3
$\begingroup$

In your example image, you show what appears to be a fixed camera feed (for example, a security camera). If it is safe to assume that this is a fixed camera feed, this becomes much easier, since we can:

  1. Take your image, and have a reference image from when you know the door isn't blocked
  2. Take an identically-sized subsection of each that zooms in on the section in front of the door
  3. Use one of several approaches to find differences between those two sub-images, and decide if those differences are beyond some threshold.

There are many ways to compare two similar images (and many stack overflow posts, code snippets, python examples, etc). As a quick-and-easy subset to consider, take a look at:

  • The compareHist() function, which would allow you to see if the colors in each image are generally similar. If they are almost exactly the same there's probably nothing blocking your door, but there would be a rare set of cases where there is a floor-colored object blocking it and this would fail. But this is generally quick, easy, and good enough.
  • The matchTemplate() function, which allows you to provide a template and find the probabilty that that template is found at a given pixel. If you have a template in the form of the floor in front of the door, and you can't find a match for that floor, the door is blocked. I would expect this to be a bit more robust than the histogram approach.
  • If you're doing things in Python, Scikit also has some helpful tools for computing the structural similarity index (SSIM), which allows you to find the difference between two images.

If we can't make that assumption, things become harder: you'll need your approach to be robust against a large variety of possible perspective shifts. The most common method for doing that is by training a classifier model that is robust to a wide variety of different viewing angles.

$\endgroup$
4
  • $\begingroup$ Good points. Yes camera is fixed. But it needs to be robust to days and nights, light on and off. Not sure if these approaches are good for that. Btw, doesn't SSIM generally measures noises and not really "similarity" of two images?! $\endgroup$
    – Tina J
    Aug 9, 2023 at 21:03
  • 1
    $\begingroup$ @TinaJ The HSV approach will help, but you're right, I'd be skeptical of it being enough if we're dealing with dramatic lighting changes. However, that's not too hard to work around: instead of comparing to a single case, compare to a day case, a night case, a night with lights on case... You can streamline that if you can access the time at which the image was taken. $\endgroup$
    – cst0
    Aug 9, 2023 at 21:19
  • $\begingroup$ @TinaJ just saw your edit asking about SSIM-- yes, but you can consider "noise" as "anything that I don't want to see in the image". So SSIM can be used to compare two images that should be the same and find where the differences are. $\endgroup$
    – cst0
    Aug 10, 2023 at 12:26
  • $\begingroup$ Good point. I think I can assume we capture multiple image of normal scenes and compare against all of them. I have to try ssim and see how robust it is against color changes $\endgroup$
    – Tina J
    Aug 10, 2023 at 16:20
2
$\begingroup$

You could create a categorical deep learning model by taking images of the door blocked and unblocked. Basically a Hotdog, Not Hotdog model. https://www.datacamp.com/blog/classification-machine-learning This should be relatively simple if the camera is in a fixed location. If lighting conditions are variable then you will want examples in various lighting conditions and you may want to use data augmentation (variable image brightness and blurring, things like that) to make your model more resilient, especially if you have a limited amount of data.

$\endgroup$
1
  • $\begingroup$ It's not just classification. I would need bounding box as well. Plus, I don't have data to train a model myself $\endgroup$
    – Tina J
    Jul 24, 2023 at 4:48

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.