๐ปBasic OpenCV API with Django ๐ท
๐Face Detection API ๐
Resource :
I updated the code from PyImageSearch Blog to Python 3 and Django 3.
MVT (Model - View -Template)

Setup :
pip install numpy django requests
Create Project :
django-admin startproject face_api
cd face_api
code . # Visual Stusio Code

- create a new app named face_detector
python manage.py startapp face_detector

Create API :
- Edit views.py in face_detector
โ ๏ธ _grab_image is private function. Unable to run from outside the views.py file. you can move _grab_image to other file and setting with __all__ for change to public function.
โ if you import module by :
from module_name import *
private variable , private class and private function are not imported
โ if _ (single underscore) โ variable_name โก๏ธ private variable
โ if _ (single underscore) โ class_name โก๏ธ private class
โ if _ (single underscore) โ function_name โก๏ธ private function
- Edit urls.py in face_api

Download and Import Face Detection Model
- Download : https://github.com/opencv/opencv/tree/master/data/haarcascades
- Import Model :
mkdir cascades
import model to cascades folder and edit code line 14 in file views.py

Test API :
python manage.py runserver

- access to http://127.0.0.1:8000/ or http://localhost:8000/

- Error code [404] because I have not set url path at /
- access to http://localhost:8000/face_detection/detect/

- if api can detect face on your image from HTTP POST, api will send result is true [JSON format]
{ success : true }
