-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
87 lines (77 loc) · 2.7 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import numpy
from django.shortcuts import render,HttpResponse
import documentScanner as ds
import cv2 as cv
import scan_me as sm
import typeCon as tc
from .models import File
from PIL import Image
# Create your views here
def home(request):
n=1
if request.method=='GET':
return render (request,"index1.html")
if request.method=="POST":
fname=request.FILES['image'].read()
npimg=numpy.fromstring(fname,numpy.uint8)
img=cv.imdecode(npimg,cv.IMREAD_UNCHANGED)
height,width= img.shape[:2]
if height==width:
height=width=500
if width>height:
width=550
height=400
if height>width:
height=400
width=300
height=str(height)+'px'
width=str(width)+'px'
cv.imwrite("0.jpg",img)
blurred_threshold = ds.transformation(img)
cleaned_image = ds.final_image(blurred_threshold)
context ={'height' : height,'width':width,'number':n}
print(type(img))
# cv.imwrite('image.jpg',image)
return render(request,'next.html',context)
def display(request):
if request.method=="POST":
height=request.POST['height']
width=request.POST['width']
number=request.POST['number']
number=int(number)+1
if number > 5:
sm.convert('5.jpg')
context={'height' : height+'px','width':width+'px','number':number}
print(height,width)
return render(request,'next.html',context)
def forContrib(request):
if request.method=="GET":
return render(request,'activeContributors.html')
def fortheProject(request):
if request.method=="GET":
return render(request,'theProject.html')
def convert(request):
if request.method=="POST":
fname=request.FILES['image2'].read()
npimg=numpy.fromstring(fname,numpy.uint8)
img=cv.imdecode(npimg,cv.IMREAD_UNCHANGED)
print(img)
cv.imwrite("convert.jpg",img)
return render(request,'convert.html')
return render(request,'convert.html')
def convertPng(request):
if request.method=="POST":
fname=request.FILES['image2'].read()
npimg=numpy.fromstring(fname,numpy.uint8)
img=cv.imdecode(npimg,cv.IMREAD_UNCHANGED)
print(img)
cv.imwrite("pngimg.png",img)
print("written")
return render(request,'convert.html')
return render(request,'convert.html')
def imgTopdf(request):
pdf={'pdf':tc.pngToPdf("convert.jpg")}
return render(request,'convert.html',pdf)
def pngToJpg(request):
jpg={'jpg':tc.pngToJpg("pngimg.png")}
return render(request,'convert.html',jpg)