https://github.com/adamspannbauer/lens_blur
https://github.com/adamspannbauer/lens_blur
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/adamspannbauer/lens_blur
- Owner: AdamSpannbauer
- License: mit
- Created: 2019-02-15T14:29:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-15T17:25:05.000Z (over 7 years ago)
- Last Synced: 2025-07-05T06:51:56.752Z (about 1 year ago)
- Language: Python
- Size: 6.55 MB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Poor Man's Portrait Mode
> Inspired by [Computerphile](https://www.youtube.com/watch?v=vNG3ZAd8wCc)
Quickly thrown together imitation of iPhone's 'portrait mode'. Made with Mask RCNN and a complex kernel lens blur.
Performance is... quite terrible on my local machine, but no need/desire to optimize.
### Example Output
### Process
* Run pre-trained COCO Mask RCNN (reference: [GluonCV](https://gluon-cv.mxnet.io/api/model_zoo.html#gluoncv.model_zoo.MaskRCNN)).
* Assume largest detected object mask is focal point.
* Apply lens blur everywhere but on largest detected object (reference: [Computerphile](https://github.com/mikepound/convolve))
### Example Usage
This is the code used to generate the above example output (found in file: [`apply_portrait_mode.py`](apply_portrait_mode.py)).
```python
import cv2
from portrait_mode import portrait_mode
IMAGE_PATH = 'images/jasper_deck.jpg'
# Run detection and blurring effects
portrait_mode_img, original_img = portrait_mode(IMAGE_PATH)
# Display results
cv2.imshow("Poor Man's Portrait Mode", portrait_mode_img)
cv2.imshow('Original', original_img)
cv2.waitKey(0)
```