You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
3.8 KiB

from django.http import HttpResponse
from django.shortcuts import render
from APP01.models import IMG
from APP01.models import file_delete
import funs
# Create your views here.
def saveIMG(request):
if request.method == 'POST':
new_img = IMG(
img=request.FILES.get('img'),
name=request.FILES.get('img').name
)
new_img.save()
def test(request):
return render(request, "test.html")
def index(request):
img = IMG.objects.all()
for i in img:
file_delete(instance=i)
i.delete()
IMG.objects.all().delete()
# 每次返回主页清理数据库和本地缓存的文件
return render(request, "index.html")
def RGB(request):
saveIMG(request)
img = IMG.objects.all().last()
content = {
'img': img,
}
img1 = IMG.objects.all()
for i in img1:
print(i.img.path)
funs.Rgb(i.img.path)
return render(request, 'rgb.html', content)
def HSV(request):
saveIMG(request)
img = IMG.objects.all().last()
content = {
'img': img,
}
img1 = IMG.objects.all()
for i in img1:
print(i.img.path)
funs.Hsv(i.img.path)
return render(request, 'hsv.html', content)
def UN(request):
saveIMG(request)
img = IMG.objects.all().last()
content = {
'img': img,
}
img1 = IMG.objects.all()
for i in img1:
print(i.img.path)
funs.Un(i.img.path)
return render(request, 'un.html', content)
def ADD(request):
saveIMG(request)
img = IMG.objects.all()
content = {
'img': img,
}
if len(img) > 1:
paths = []
for i in range(len(img)):
print(img[i].img.path)
paths.append(img[i].img.path)
funs.Add(paths)
return render(request, 'add.html', content)
def SUBTRACT(request):
saveIMG(request)
img = IMG.objects.all()
content = {
'img': img,
}
if len(img) > 1:
paths = []
for i in range(len(img)):
print(img[i].img.path)
paths.append(img[i].img.path)
funs.Subtract(paths)
return render(request, 'subtract.html', content)
def OPANDCL(request):
saveIMG(request)
img = IMG.objects.all().last()
content = {
'img': img,
}
img1 = IMG.objects.all()
for i in img1:
print(i.img.path)
funs.OpenAndClose(i.img.path)
return render(request, 'opandcl.html', content)
def SHARP(request):
saveIMG(request)
img = IMG.objects.all().last()
content = {
'img': img,
}
img1 = IMG.objects.all()
for i in img1:
print(i.img.path)
funs.Sharp(i.img.path)
return render(request, 'sharp.html', content)
def TURN(request):
saveIMG(request)
img = IMG.objects.all().last()
content = {
'img': img,
}
img1 = IMG.objects.all()
for i in img1:
print(i.img.path)
funs.Turn(i.img.path)
return render(request, 'turn.html', content)
def EROSION(request):
saveIMG(request)
img = IMG.objects.all().last()
content = {
'img': img,
}
img1 = IMG.objects.all()
for i in img1:
print(i.img.path)
funs.Erosion(i.img.path)
return render(request, 'erosion.html', content)
def DILATION(request):
saveIMG(request)
img = IMG.objects.all().last()
content = {
'img': img,
}
img1 = IMG.objects.all()
for i in img1:
print(i.img.path)
funs.Dilation(i.img.path)
return render(request, 'dilation.html', content)
def NOISE(request):
saveIMG(request)
img = IMG.objects.all().last()
content = {
'img': img,
}
img1 = IMG.objects.all()
for i in img1:
print(i.img.path)
funs.Noise(i.img.path)
return render(request, 'noise.html', content)