Added video list page
This commit is contained in:
parent
f82275df71
commit
3d4cf9daa8
@ -2,5 +2,6 @@
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/TV2D" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -23,9 +23,15 @@ class VideoFile(models.Model):
|
||||
video_width = models.IntegerField(default=0, blank=True)
|
||||
video_height = models.IntegerField(default=0, blank=True)
|
||||
status = models.IntegerField(default=VideoFileStatus.NEW.value)
|
||||
output_file = models.FileField(upload_to="", max_length=1024, blank=True)
|
||||
csv_file = models.FileField(upload_to="", max_length=1024, blank=True)
|
||||
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return self.file.url
|
||||
|
||||
|
||||
class WTV2D_data(models.Model):
|
||||
processing = models.BooleanField(default=False, blank=False)
|
||||
|
||||
|
@ -12,6 +12,10 @@
|
||||
<body>
|
||||
<div>
|
||||
<div class="d-flex flex-column min-vh-100 justify-content-center align-items-center">
|
||||
{% if processing %}
|
||||
<h1> Some video is still being processed</h1>
|
||||
<a class="btn btn-primary" href="{% url 'videolist' %}">Video list</a>
|
||||
{% else %}
|
||||
<h1> Submit your video</h1>
|
||||
<form id="form" method="POST" class="mt-4 text-center" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
@ -25,6 +29,8 @@
|
||||
{{ form.file }}
|
||||
<input type="submit" class="btn btn-primary mt-2" value="Upload">
|
||||
</form>
|
||||
<a class="btn btn-primary mt-5" href="{% url 'videolist' %}">Video list</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
53
core/templates/core/video_list.html
Normal file
53
core/templates/core/video_list.html
Normal file
@ -0,0 +1,53 @@
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
||||
<script type="text/javascript" src="/static/js/jquery-3.6.0.min.js"></script>
|
||||
<link rel="stylesheet" href="{% static 'css/main.css' %}">
|
||||
<title>Web-TV2D - Video list</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container my-5">
|
||||
<a class="btn btn-primary" href="{% url 'home' %}">Upload video</a>
|
||||
<a class="btn btn-primary ms-5" href="{% url 'videolist' %}">Refresh</a>
|
||||
<div class="d-flex flex-column justify-content-center align-items-center">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Video original file</th>
|
||||
<th scope="col">Video status</th>
|
||||
<th scope="col">Video processed file</th>
|
||||
<th scope="col">Video CSV file</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for video in videos %}
|
||||
<tr>
|
||||
<th scope="row"> {{ video.pk }}</th>
|
||||
<td><a href="{{ video.file.url }}">{{ video.file }}</a></td>
|
||||
{% if video.status == enum_video_file_status.NEW.value %}
|
||||
<td>NEW</td>
|
||||
{% elif video.status == enum_video_file_status.PROCESSING.value %}
|
||||
<td>PROCESSING</td>
|
||||
{% elif video.status == enum_video_file_status.READY.value %}
|
||||
<td>READY</td>
|
||||
{% endif %}
|
||||
{% if video.output_file and video.csv_file %}
|
||||
<td><a href="{{ video.output_file.url }}">{{ video.output_file }}</a></td>
|
||||
<td><a href="{{ video.csv_file.url }}">{{ video.csv_file }}</a></td>
|
||||
{% else %}
|
||||
<td></td>
|
||||
<td></td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -2,8 +2,7 @@ from django.contrib import admin
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
app_name = "menu"
|
||||
|
||||
urlpatterns = [
|
||||
path('' , views.home, name="home"),
|
||||
path('/', views.home, name="home"),
|
||||
path('videolist/', views.video_list_view, name="videolist"),
|
||||
]
|
||||
|
@ -3,27 +3,70 @@ from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from django.contrib import messages
|
||||
from core.forms import VideoUploadForm
|
||||
from core.models import VideoFile
|
||||
from core.models import VideoFile, WTV2D_data
|
||||
from TV2D import TV2D
|
||||
|
||||
# Create your views here.
|
||||
|
||||
|
||||
def home(request):
|
||||
wtv2d_data = WTV2D_data.objects.first()
|
||||
# For control processing videos some workers should be used like Celery
|
||||
# if wtv2d_data.processing:
|
||||
# context = {'processing': True}
|
||||
# return render(request, 'core/home.html', context)
|
||||
form = VideoUploadForm()
|
||||
if request.method == "POST":
|
||||
form = VideoUploadForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
wtv2d_data.processing = True
|
||||
wtv2d_data.save()
|
||||
video_file = VideoFile(file=request.FILES['file'])
|
||||
video_file.status = VideoFile.VideoFileStatus.NEW.value
|
||||
video_file.save()
|
||||
|
||||
video = cv2.VideoCapture(video_file.file.path)
|
||||
video_file.fps = video.get(cv2.CAP_PROP_FPS)
|
||||
video_file.video_width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
|
||||
video_file.video_height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
||||
video_file.status = VideoFile.VideoFileStatus.PROCESSING.value
|
||||
video_file.save()
|
||||
|
||||
# object_detection_model_path = "COCO-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_3x.yaml"
|
||||
object_detection_model_path = "COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml"
|
||||
# Same as model by for now for config. If you use model from local sotrage you can still use config
|
||||
## from Detectron2 Model Zoo and Baselines.
|
||||
# object_detection_config_path = "COCO-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_3x.yaml"
|
||||
object_detection_config_path = "COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml"
|
||||
homography_keypoint_path = "TV2D/models/FPN_efficientnetb3_0.0001_4.h5"
|
||||
homography_deephomo_path = "TV2D/models/HomographyModel_0.0001_4.h5"
|
||||
deep_sort_model = "TV2D/models/market_bot_R50.pth"
|
||||
deep_sort_model_config = "TV2D/deep_sort_pytorch/thirdparty/fast-reid/configs/Market1501/bagtricks_R50.yml"
|
||||
|
||||
tv2d = TV2D.TV2D(object_detection_model_path, object_detection_config_path=object_detection_config_path,
|
||||
homography_on=True, team_detection_on=True,
|
||||
tracker_on=True, no_gui=True,
|
||||
homography_pretreined=False, homography_deephomo_path=homography_deephomo_path,
|
||||
homography_keypoint_path=homography_keypoint_path,
|
||||
deep_sort_model_path=deep_sort_model, deep_sort_model_config=deep_sort_model_config)
|
||||
output_video_name = ".".join(video_file.file.name.split(".")[:-1]) + "_" + str(video_file.pk) + ".mkv"
|
||||
export_data_file_path = ".".join(video_file.file.name.split(".")[:-1]) + "_" + str(video_file.pk) + ".csv"
|
||||
video_file.output_file = output_video_name
|
||||
video_file.csv_file = export_data_file_path
|
||||
video_file.save()
|
||||
tv2d(TV2D.TV2D.RunOn.VIDEO, video_file.file.path, export_output_path=f"media/{output_video_name}",
|
||||
export_data_file_path=f"media/{export_data_file_path}")
|
||||
video_file.status = VideoFile.VideoFileStatus.READY.value
|
||||
video_file.save()
|
||||
else:
|
||||
messages.error(request, "Something went wrong")
|
||||
|
||||
wtv2d_data.processing = False
|
||||
wtv2d_data.save()
|
||||
context = {'form': form}
|
||||
return render(request, 'core/home.html', context)
|
||||
|
||||
def video_list_view(request):
|
||||
videos = VideoFile.objects.all().order_by("-pk")
|
||||
context = {'videos': videos, 'enum_video_file_status': VideoFile.VideoFileStatus}
|
||||
return render(request, 'core/video_list.html', context)
|
||||
|
Loading…
Reference in New Issue
Block a user