django-thumb is a simple Django app that contains two models fields , The app generates images from videos and additionally can create write on images.
- Quick Preview for
VideoThumbnailField
(Thumbnail)
pip install django-thumb # try pip3 if it didn't work
- Add "thumb" to your INSTALLED_APPS setting like this::
INSTALLED_APPS = [
...
'thumb',
]
STATIC_ROOT = os.path.join(BASE_DIR, "static")
MEDIA_ROOT = 'media'
MEDIA_URL = '/media/'
....
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from thumb import ImageThumbnailField, VideoThumbnailField
in any app inside models.py
file we will made these two models:
from django.db import models
from thumb import ImageThumbnailField, VideoThumbnailField
class Media(models.Model):
video = models.FileField()
# our Thumbnail
thumbnail = VideoThumbnailField() # should be VideoThumbnailField(video_field_name="video") but "video" is the default
class MediaTwo(models.Model):
thumbnail = ImageThumbnailField()
python manage.py makemigrations
python manage.py migrate
from django.contrib import admin
from .models import Media, MediaTwo
admin.site.register(Media)
admin.site.register(MediaTwo)
now eveything is ready to test let's test make sure you got the same templates as the pictures below
- you can add more cascade choices by adding yours in a folder in the your django project dir then add the xml cascade files their, after you've to add the choices in the
settings.py
:
CASCADE_DATA = (
('eyes', [os.path.join(BASE_DIR, "<your_cascades_folder>/haarcascade_eyes.xml")]),
('human with clear eyes', [os.path.join(BASE_DIR, "<your_cascades_folder>/haarcascade_frontalface.xml"),
os.path.join(BASE_DIR, "<your_cascades_folder>/haarcascade_eyes.xml")]),
)
- by default each cascade has to be at least 0.3 of the hole width and height of the video frame, you can change it by add in the
settings.py
:
CASCADE_RATIO = {
"width": <your_value_has_to_be_from_0_to_1>,
"height": <your_value_has_to_be_from_0_to_1>,
}
- opencv in image processing and text writing
- jscolor in the color field