Web application for real-time object segmentation using Flask , YOLOv8, AnimeGANv2/v3 model in ONNX weights.
After obtaining images through the camera, it is possible to separate the target and background in the scene, and composite the target with a Web URL/Local Path video background. Additionally, you can change different display styles and save a screenshot.
-
OpenCV, Flask, gevent, onnxruntime and youtube-dl.
-
Install :
The
requirements.txt
file should list all Python libraries that your notebooks depend on, and they will be installed using:pip install -r requirements.txt
-
Note :
If you use a YouTube URL as the link to replace your background, please make sure to modify the following.
- YouTube Unable to extract uploader id, so you need to revise [
Your Path
]\site-packages\youtube_dl\extractor\youtube.py :
-
'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id') if owner_profile_url else None,
$\Downarrow$ -
'uploader_id': self._search_regex(r'/(?:channel/|user/|@)([^/?&#]+)', owner_profile_url, 'uploader id', default=None),
- Youtube does no longer have a like/dislike count, so you need to comment out [
Your Path
]\site-packages\pafy\backend_youtube_dl.py :
-
self._likes = self._ydl_info['like_count']
-
self._dislikes = self._ydl_info['dislike_count']
- YouTube Unable to extract uploader id, so you need to revise [
You can convert the YOLOv8-seg model to ONNX using the following Google Colab notebook :
- The License of the models is GPL-3.0 license: License
-
Quantize ONNX models :
Converting a model to use float16 instead of float32 can decrease the model size.
python onnxQuantization.py -i <path-of-your-onnx-model>
-
Setting Config :
model_config = { "model_path": 'models/yolov8n-seg-coco.onnx', # model path "classes_path" : 'models/coco_label.txt', # classes path "box_score" : 0.4, "box_nms_iou" : 0.45, "box_aspect_ratio" : None, "box_stretch" : None, } cam_config = { "cam_id" : 0, 'exposure': -2, # init cam exposure 'contrast': 50 # init cam contrast }
After running, the config information will appear above the menu :
-
Run :
python Application.py ... The server will be accessible at [ http://localhost:8080 ].
Display Mode Describe DisplayType.NONE
Just show your webcam image. DisplayType.BASIC_MODE
Show detect and segmentation target results on image. DisplayType.DETECT_MODE
Separate the target box and background on image. DisplayType.SEMANTIC_MODE
Separate the target segmentation and background on image.
From the root directory, run :
docker build -t <name-of-your-image> -f ./docker/Dockerfile .
docker run --rm --privileged --device="/dev/video0:/dev/video0" -t -p 8080:8080 <name-of-your-image>
-
Display Mode Switch
-
Display Style Switch
-
Display Background Removal
- 2023/05/05 - Added images with downloadable transparent backgrounds.
- 2023/11/22 - Fixed youtube_dl bug, and remove pafy package.
- 2023/11/26 - Fixed custom diff model size.
GPLv3 License key requirements :
- Disclose Source
- License and Copyright Notice
- Same License
- State Changes