https://github.com/jjoe64/android-motion-detection
Camera motion detector example
https://github.com/jjoe64/android-motion-detection
Last synced: 12 days ago
JSON representation
Camera motion detector example
- Host: GitHub
- URL: https://github.com/jjoe64/android-motion-detection
- Owner: jjoe64
- License: apache-2.0
- Created: 2016-11-05T17:24:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-06-02T12:55:03.000Z (11 months ago)
- Last Synced: 2025-03-25T07:36:09.702Z (29 days ago)
- Language: Java
- Size: 104 KB
- Stars: 66
- Watchers: 9
- Forks: 31
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: license
Awesome Lists containing this project
README
# Android Motion Detector
## functional description
The preview of the camera will be drawn on a 1x1 pixel surface. At this point the preview input of the camera will be analysed at a given interval.
To detect a movement the picture will be dived into tiles. For each tile the average brightness will be calculated. If a average value of a single tile differs from the previous value, a motion is registered.## integration
1. Copy all classes of the subpackge `motiondetection` into your project. Adapt the package names.
2. There must be a `SurfaceView` in your layout:
``````
3. create instance of `MotionDetector`
```
motionDetector = new MotionDetector(this, (SurfaceView) findViewById(R.id.surfaceView));
```
4. call lifecycle methods: `motionDetector.onResume() and .onPause()`
5. register callbacks
```
motionDetector.setMotionDetectorCallback(new MotionDetectorCallback() {
@Override
public void onMotionDetected() {
txtStatus.setText("Bewegung erkannt");
}@Override
public void onTooDark() {
txtStatus.setText("Zu dunkel hier");
}
});
```## customize parameters
there are some important parameters that can be adjusted at runtime.
| Method | Description | Default |
| --- | --- | --- |
| motionDetector.setCheckInterval(500); | milliseconds between pictures to compare. less = less energy cos t | 500 |
| motionDetector.setLeniency(20); | maximal tolerence of difference in pictures. less = more sensible | 20 |
| motionDetector.setMinLuma(1000); | minimum brightness. if lower the callback onTooDark is called | 1000 |## notice
1. Permissions must be given in the AndroidManifest.xml
``````
2. if `targetSdkVersion` is greater than 21 you have to implement Runtime Permissions
3. the detection is only running while the activity is active. It may make sense to build in a Wake-Lock.
4. Parts of the code is taken from https://github.com/phishman3579/android-motion-detection## license
Jonas Gehring
Apache license 2.0