Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nuriofernandez/keys-in-door-experiment
A simple experimental project to detect if the keys of my apartment are in the door thru the security camera. 🚪 📷
https://github.com/nuriofernandez/keys-in-door-experiment
Last synced: 2 days ago
JSON representation
A simple experimental project to detect if the keys of my apartment are in the door thru the security camera. 🚪 📷
- Host: GitHub
- URL: https://github.com/nuriofernandez/keys-in-door-experiment
- Owner: nuriofernandez
- Created: 2024-03-25T10:33:51.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-04-18T00:56:55.000Z (7 months ago)
- Last Synced: 2024-04-18T01:48:07.395Z (7 months ago)
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Are keys in the door?
I keep forgetting my keys on the outside of the door, and realize next morning I slept
with the keys in the door. 😱So, I decided to create this service to be able to send me notifications.
## Requirements
- A security camera that supports `RTSP` (I use a TPlink/TAPO security camera)
- A device that can serve as a server
- FFmpeg installed## My setup
I have my security camera looking to the door:
![](https://i.imgur.com/izcFbCu.jpeg)
## Technical explanation
From the keys area, I defined an area where the keys should be visible, and
for color comparaison, there is a control point to compare the colors with the
keys area.![](https://i.imgur.com/4inD0In.png)
I get all pixels in that area and calculate the average color,
ignoring those too close to the control point.```go
for y := startY; y >= endY; y-- {
for x := startX; x <= endX; x++ {
// Get the color of the pixel at the current position
pixelColor := img.At(x, y)
// Extract the RGB components
r, g, b, _ := pixelColor.RGBA()if distance(r,g,b, controlPoint) < 10 {
// Ignore colors too close to the control point
// so later the comparator will be more precise.
continue;
}
}
}
```Since the keys are darker than the door,
the difference between the control point should be noticeable.```go
// Calculate the difference between the avg and the control point colors
difference := distance(
avgR, avgB, avgG,
controlPoint
)// if the color from the control point differs more than 5 points,
// then the keys are there.
keysThere := difference > 5
return keysThere, nil
```## What I do with the bool?
For now, I just established a simple http server that prints a json with it 🤣
```bash
GET http://localhost:8090/status
```
```json
{
"keysInDoor": true
}
```