Skip to content

Commit

Permalink
Updated GUI. Finalizing project.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash2108 committed Dec 22, 2021
1 parent 4bdc270 commit 34cc475
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Capstone-2 Project

Project to create a webapp which detects and counts human in images and videos.
Currently experimenting with ~~2 ML models: Pointrend (ResNet backbone) & OpenCV's HOG descriptor~~ YOLO
Currently experimenting with YOLO ~~2 ML models: Pointrend (ResNet backbone) & OpenCV's HOG descriptor~~

#### Install the dependencies by :

Expand Down
23 changes: 23 additions & 0 deletions humancounter/migrations/0002_auto_20211222_0910.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.1.5 on 2021-12-22 03:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('humancounter', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='train',
name='OutputImage',
field=models.CharField(default='a', max_length=100),
),
migrations.AlterField(
model_name='video',
name='OutputVideo',
field=models.CharField(default='a', max_length=100),
),
]
23 changes: 23 additions & 0 deletions humancounter/migrations/0003_auto_20211222_0922.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.1.5 on 2021-12-22 03:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('humancounter', '0002_auto_20211222_0910'),
]

operations = [
migrations.AlterField(
model_name='train',
name='OutputImage',
field=models.CharField(blank=True, default='a', max_length=100),
),
migrations.AlterField(
model_name='video',
name='OutputVideo',
field=models.CharField(blank=True, default='a', max_length=100),
),
]
4 changes: 2 additions & 2 deletions humancounter/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
class Train(models.Model):

TrainImage = models.ImageField(upload_to ='images/')
OutputImage = models.CharField(max_length = 100)
OutputImage = models.CharField(max_length = 100, default='a', blank=True)

class Video(models.Model):
video=models.FileField(upload_to="video/",validators=[file_size])
OutputVideo = models.CharField(max_length = 100)
OutputVideo = models.CharField(max_length = 100, default='a', blank=True)
13 changes: 8 additions & 5 deletions humancounter/templates/humancounter/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
<div class="jumbotron">
<h1 class="display-4" style="text-align: center;">Human counter</h1>
<p class="lead font-italic" style="text-align:center;">A project for capstone-2</p>

<a href="{% url 'login' %}" class="ml-2" style="align-items: center;"><button type="button" class="btn btn-primary btn-lg">Login</button></a>

<a href="{% url 'register' %}" class="ml-2" style="align-items: center;"><button type="button" class="btn btn-secondary btn-lg">Register</button></a>


{% if logged_in %}
<span ><a class="ml-2" style="align-items: center;" href="{% url 'logout' %}"><button type="button" class="btn btn-primary btn-lg">Logout</button></a></span>
{% else %}
<a href="{% url 'login' %}" class="ml-2" style="align-items: center;"><button type="button" class="btn btn-primary btn-lg">Login</button></a>

<a href="{% url 'register' %}" class="ml-2" style="align-items: center;"><button type="button" class="btn btn-secondary btn-lg">Register</button></a>
{% endif %}
<hr class="my-4"> {% block content %} {% endblock content %}
</div>
</div>
Expand Down
30 changes: 24 additions & 6 deletions humancounter/templates/humancounter/train_log.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
{% extends "humancounter/base.html" %} {% block content %} {% load crispy_forms_tags %}
<span class="d-flex justify-content-center"><a href="/web" class="btn btn-success">
</i> Submit by webcam
</a></span>

<form method="POST" enctype="multipart/form-data">
{%csrf_token%} {{log|crispy}}
<div class="row">
{%csrf_token%}
<table>
<tr>
<td><label>Upload Image:</label></td>
<td>{{log.TrainImage}}</td>
<td>
<button type="submit" class="btn btn-success">
Submit the Image</button>
</td>
<td>
<a href="/web" class="btn btn-success">
</i> Submit by webcam
</a>
</td>
<td>
<a href="{% url 'train_video' %}" class="btn btn-success">
</i> Submit a Video
</a>
</td>
</tr>
</table>
<!-- <div class="row">
<div class="col-md-12">
<button type="submit" class="btn btn-success btn-block btn-lg" id="submit_button"><i class="fas fa-database"></i>
Submit</button>
<a href="/video" class="btn btn-success">
</i> Submit a Video
</a>
</div>
</div> -->
For webcam, an account is necessary.
</div>
</form>
Expand Down
31 changes: 19 additions & 12 deletions humancounter/templates/humancounter/train_video.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
{% extends "humancounter/base.html" %} {% block content %} {% load crispy_forms_tags %}
<span class="d-flex justify-content-center"><a href="/web" class="btn btn-success">
</i> Submit by webcam
</a></span>

<form method="POST" enctype="multipart/form-data">
{%csrf_token%} {{form.as_p}}
<div class="row">
<div class="d-flex justify-content-start">
<button type="submit" class="btn btn-success btn-block btn-lg"><i class="fas fa-database"></i>
Submit the Video</button>
{%csrf_token%}
<table>
<tr>
<td><label>Upload Video:</label></td>
<td>{{form.video}}</td>
<td>
<button type="submit" class="btn btn-success">
Submit the Video</button>
</td>
<td>
<a href="/web" class="btn btn-success">
</i> Submit by webcam
</a>
</td>
<td>
<a href="{% url 'train_insert' %}" class="btn btn-success">
</i> Submit an Image
</a>
</div>


</div>
</td>
</tr>
</table>
</form>

{% endblock content %}
7 changes: 7 additions & 0 deletions humancounter/templates/humancounter/train_web.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@
<span class="hello-msg">Hello, {{request.user}}</span>
<span ><a class="hello-msg" href="{% url 'logout' %}">Logout</a></span>
<br><br>
<a href="{% url 'train_insert' %}" class="btn btn-success">
</i> Submit an Image
</a>
<a href="{% url 'train_video' %}" class="btn btn-success">
</i> Submit a Video
</a>
<br/>
<img src="{% url 'webcam' %}">
{% endblock content %}
31 changes: 17 additions & 14 deletions humancounter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ def train_list(request):
all_videos = Video.objects.all()
context = {
"obj": obj,
"all": all_videos
"all": all_videos,
"logged_in":request.user.is_authenticated
}
return render(request,"humancounter/train_list.html",context)

def loginPage(request):
if request.user.is_authenticated:
return redirect('web')
return redirect('web', {"logged_in":request.user.is_authenticated})
else:
if request.method == 'POST':
username = request.POST.get('username')
Expand All @@ -38,16 +39,16 @@ def loginPage(request):
else:
messages.info(request, 'Username OR password is incorrect')

context = {}
context = {"logged_in":request.user.is_authenticated}
return render(request, 'humancounter/login.html', context)

def logoutUser(request):
logout(request)
return redirect('train_insert')
return render(request, 'humancounter/train_log.html', {"logged_in":request.user.is_authenticated})

def registerPage(request):
if request.user.is_authenticated:
return redirect('web')
return redirect('web', {"logged_in":request.user.is_authenticated})
else:
formreg = CreateUserForm()
if request.method == 'POST':
Expand All @@ -57,10 +58,10 @@ def registerPage(request):
user = formreg.cleaned_data.get('username')
messages.success(request, 'Account was created for ' + user)

return redirect('web')
return redirect('web', {"logged_in":request.user.is_authenticated})


context = {'formreg':formreg}
context = {'formreg':formreg, "logged_in":request.user.is_authenticated}
return render(request, "humancounter/register.html", context)


Expand All @@ -72,10 +73,12 @@ def train_video(request):
obj1=form.save()
obj1.OutputVideo = video_feed(os.getcwd()+obj1.video.url)
obj1.save()
return redirect('/list')
return redirect('/list', {"logged_in":request.user.is_authenticated})
else:
print("Invalid")
else:
form=Video_form()
return render(request,'humancounter/train_video.html',{"form":form,'all':all_videos})
return render(request,'humancounter/train_video.html',{"form":form,'all':all_videos, "logged_in":request.user.is_authenticated})

def train_log(request, id=0):
if request.method == "GET":
Expand All @@ -84,7 +87,7 @@ def train_log(request, id=0):
else:
train = Train.objects.get(pk=id)
log = Trainlog(instance=train)
return render(request,"humancounter/train_log.html", {'log':log})
return render(request,"humancounter/train_log.html", {'log':log, "logged_in":request.user.is_authenticated})
else:
if id==0:
log = Trainlog(request.POST, request.FILES)
Expand All @@ -101,17 +104,17 @@ def train_log(request, id=0):
# print(os.getcwd())
obj.OutputImage = image_feed(os.getcwd()+obj.TrainImage.url)
obj.save()
return redirect('/list')
return redirect('/list', {"logged_in":request.user.is_authenticated})


def train_delete(request, id=0):
train = Train.objects.get(pk=id)
train.delete()
return redirect('/list')
return redirect('/list', {"logged_in":request.user.is_authenticated})
def video_delete(request, id=0):
x=Video.objects.get(pk=id)
x.delete()
return redirect('/list')
return redirect('/list', {"logged_in":request.user.is_authenticated})

# @login_required(login_url='login')
# def train_web(request):
Expand Down Expand Up @@ -160,4 +163,4 @@ def train_web_cam(request):

@login_required(login_url='login')
def train_web(request):
return render(request,"humancounter/train_web.html")
return render(request,"humancounter/train_web.html", {"logged_in":request.user.is_authenticated})
10 changes: 4 additions & 6 deletions humancounter/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import time
import os


net = cv2.dnn.readNet(os.getcwd()+"/humancounter/yolov3.weights", os.getcwd()+"/humancounter/yolov3.cfg")
classes = []
with open(os.getcwd()+"/humancounter/coco.names", "r") as f:
classes = [line.strip() for line in f.readlines()]
layer_names = net.getLayerNames()
output_layers = [layer_names[i - 1] for i in net.getUnconnectedOutLayers()]
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
colors = np.random.uniform(0, 255, size=(len(classes), 3))

def live_feed(img):
Expand All @@ -18,7 +17,7 @@ def live_feed(img):
with open(os.getcwd()+"/humancounter/coco.names", "r") as f:
classes = [line.strip() for line in f.readlines()]
layer_names = net.getLayerNames()
output_layers = [layer_names[i - 1] for i in net.getUnconnectedOutLayers()]
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
colors = np.random.uniform(0, 255, size=(len(classes), 3))
#instantiate a variable 'p' to keep count of persons
p=0
Expand Down Expand Up @@ -185,7 +184,7 @@ def video_feed(video_path):
with open(os.getcwd()+"/humancounter/coco.names", "r") as f:
classes = [line.strip() for line in f.readlines()]
layer_names = net.getLayerNames()
output_layers = [layer_names[i - 1] for i in net.getUnconnectedOutLayers()]
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
colors = np.random.uniform(0, 255, size=(len(classes), 3))

#load input video stream
Expand Down Expand Up @@ -276,14 +275,13 @@ def video_feed(video_path):
cv2.destroyAllWindows()
return "/media/video/output_"+video_path.split('/')[-1].split(".")[0]+".webm"


def image_feed(image_path):
net = cv2.dnn.readNet(os.getcwd()+"/humancounter/yolov3.weights", os.getcwd()+"/humancounter/yolov3.cfg")
classes = []
with open(os.getcwd()+"/humancounter/coco.names", "r") as f:
classes = [line.strip() for line in f.readlines()]
layer_names = net.getLayerNames()
output_layers = [layer_names[i - 1] for i in net.getUnconnectedOutLayers()]
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
colors = np.random.uniform(0, 255, size=(len(classes), 3))
#instantiate a variable 'p' to keep count of persons
p=0
Expand Down

0 comments on commit 34cc475

Please sign in to comment.