update
swadhinbiswas committed 2 years ago
c59a6c2
1 parent f5f0447
commit c59a6c2
6 files changed
+33 -24
Showing 6 changed files+33-24
▼backend/app/admin/handelars.py
+1-4
| @@ -81,10 +81,7 @@ async def uploadimage(img:UploadFile=File(...)): | ||
81 | 81 | return {"message":str(e)} |
82 | 82 | finally: |
83 | 83 | file.close() |
84 | -@db_add.get("/encoding") | |
85 | -async def encoding(): | |
86 | - x=EndcodeGenarator().findencoding() | |
87 | - return x | |
84 | + | |
88 | 85 | |
89 | 86 | |
90 | 87 | |
91 | 88 | |
▼backend/app/functions/encodeGenarator.py
+4-8
| @@ -2,6 +2,7 @@ import os | ||
2 | 2 | import pickle |
3 | 3 | import face_recognition |
4 | 4 | import cv2 |
5 | +import asyncio | |
5 | 6 | from app.settings.connectdb import Firebase |
6 | 7 | |
7 | 8 | |
| @@ -21,15 +22,12 @@ class EndcodeGenarator: | ||
21 | 22 | self.ref = Firebase().ref |
22 | 23 | self.bucket = Firebase().bucket |
23 | 24 | self.idsref = Firebase().idsref |
24 | - imagepath=self.imagepath | |
25 | - picklepath=self.picklepath | |
26 | - pathlist=self.pathlist | |
27 | 25 | |
28 | - def findencoding(self): | |
26 | + async def findencoding(self): | |
29 | 27 | imageList=self.pathlist |
30 | 28 | for img in imageList: |
31 | 29 | bucket=self.bucket |
32 | - ref=self.ref | |
30 | + ref=self.ref | |
33 | 31 | if not bucket.get_blob(f"faceappimage/{img}"): |
34 | 32 | with open(f"{self.imagepath}/{img}","rb") as file: |
35 | 33 | bucket.blob(f"faceappimage/{img}").upload_from_file(file) |
| @@ -41,9 +39,7 @@ class EndcodeGenarator: | ||
41 | 39 | img=cv2.cvtColor(cv2img,cv2.COLOR_BGR2RGB) |
42 | 40 | encode=face_recognition.face_encodings(img)[0] |
43 | 41 | self.encodings.append(encode) |
44 | - self.idsref.child(id).set(encode.tolist()) | |
45 | - | |
46 | - | |
42 | + self.idsref.child(id).set(encode) | |
47 | 43 | encodeKnowlist=[self.encodings,self.studentids] |
48 | 44 | file=open(self.picklepath,"wb") |
49 | 45 | pickle.dump(encodeKnowlist,file) |
50 | 46 | |
▼backend/app/functions/encodings.pickle
+0-0
Binary file not shown.
▼backend/app/functions/face.py
+10-5
| @@ -25,6 +25,7 @@ class Face: | ||
25 | 25 | matches=compare_faces(encodeListKnown,encodeFace) |
26 | 26 | faceDis=face_distance(encodeListKnown,encodeFace) |
27 | 27 | matchIndex=np.argmin(faceDis) |
28 | + self.ids.append(studentIds[matchIndex]) | |
28 | 29 | if matches[matchIndex]: |
29 | 30 | x=matches[matchIndex] |
30 | 31 | y1,x2,y2,x1=faceLoc |
| @@ -33,11 +34,15 @@ class Face: | ||
33 | 34 | cv2.rectangle(frame,(x1,y1),(x2,y2),(0,255,0),2) |
34 | 35 | cv2.rectangle(frame,(x1,y2-35),(x2,y2),(0,255,0),cv2.FILLED) |
35 | 36 | cv2.putText(frame,studentIds[matchIndex],(x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX,1,(255,255,255),2) |
36 | - self.ids.append(studentIds[matchIndex]) | |
37 | - print(self.ids) | |
38 | - | |
39 | - | |
40 | - return frame | |
37 | + else: | |
38 | + y1,x2,y2,x1=faceLoc | |
39 | + y1,x2,y2,x1=y1*4,x2*4,y2*4,x1*4 | |
40 | + bbox=55+x1,162+y1,x2-x1,y2-y1 | |
41 | + cv2.rectangle(frame,(x1,y1),(x2,y2),(0,0,255),2) | |
42 | + cv2.rectangle(frame,(x1,y2-35),(x2,y2),(0,0,255),cv2.FILLED) | |
43 | + cv2.putText(frame,"Unknown",(x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX,1,(255,255,255),2) | |
44 | + | |
45 | + return frame | |
41 | 46 | |
42 | 47 | |
43 | 48 | |
44 | 49 | |
▼backend/app/functions/videoapp.py
+18-7
| @@ -3,10 +3,11 @@ import numpy as np | ||
3 | 3 | from fastapi import APIRouter |
4 | 4 | from fastapi.responses import StreamingResponse |
5 | 5 | from app.functions.face import Face |
6 | -import streamlit as st | |
6 | +import streamlit as st | |
7 | +from app.functions.encodeGenarator import EndcodeGenarator | |
7 | 8 | # from app.settings import setting |
8 | 9 | # camip=setting.CAM_IP |
9 | -camip="192.168.0.100" | |
10 | +camip="192.168.0.103" | |
10 | 11 | |
11 | 12 | |
12 | 13 | |
| @@ -16,7 +17,8 @@ videorouter = APIRouter() | ||
16 | 17 | |
17 | 18 | |
18 | 19 | def video_feed(): |
19 | - cap = cv2.VideoCapture("http://"+camip+":8080/video") | |
20 | + | |
21 | + cap = cv2.VideoCapture("http://"+camip+":3030/video") | |
20 | 22 | cap.set(3, 640) |
21 | 23 | cap.set(4, 480) |
22 | 24 | |
| @@ -35,10 +37,19 @@ def video_feed(): | ||
35 | 37 | |
36 | 38 | |
37 | 39 | @videorouter.get("/video_feed") |
38 | -def stream(): | |
40 | +async def stream(): | |
41 | + | |
39 | 42 | return StreamingResponse(video_feed(), media_type="multipart/x-mixed-replace; boundary=frame") |
40 | -def fetch(): | |
41 | - st.write("hello") | |
42 | - return "hello" | |
43 | + | |
44 | + | |
45 | +@videorouter.get("/encode") | |
46 | +def encode(): | |
47 | + x=EndcodeGenarator() | |
48 | + y= x.findencoding() | |
49 | + return y | |
50 | + | |
51 | +@videorouter.get("/video") | |
52 | +def video(): | |
53 | + return st.markdown(f'<iframe width="560" height="315" src="http://{camip}:3030/video" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>', unsafe_allow_html=True) | |
43 | 54 | |
44 | 55 | |
45 | 56 | |
▼photos/faceapp.png
+0-0
Binary file not shown.