Puyush commited on
Commit
5188893
1 Parent(s): 0a1873d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -16,7 +16,7 @@ smtp_server = "smtp.gmail.com"
16
  subject = "Accident detected"
17
 
18
 
19
- def send_email(accident_type):
20
  body = accident_type
21
 
22
  msg = MIMEMultipart()
@@ -26,11 +26,11 @@ def send_email(accident_type):
26
 
27
  msg.attach(MIMEText(body, 'plain'))
28
 
29
- fullFileName = "./result/res.png"
30
- attachment = open(fullFileName, 'rb')
31
 
32
  attachment_package = MIMEBase('application', 'octet-stream')
33
- attachment_package.set_payload((attachment).read())
34
  encoders.encode_base64(attachment_package)
35
  attachment_package.add_header('Content-Disposition', "attachment; filename= " + filename)
36
  msg.attach(attachment_package)
@@ -88,8 +88,7 @@ def image_predict(image):
88
  annotated_frame = results[0].plot()
89
  if len(res) >0:
90
  annotated_frame_bgr = cv2.cvtColor(annotated_frame, cv2.COLOR_RGB2BGR)
91
- cv2.imwrite("./result/res.png", annotated_frame_bgr)
92
- send_email(res)
93
  return (res, annotated_frame)
94
 
95
  return ("No Class Detected", None)
@@ -119,8 +118,7 @@ def extract_frames(video):
119
 
120
  if len(res) >0:
121
  annotated_frame_bgr = cv2.cvtColor(annotated_frame, cv2.COLOR_RGB2BGR)
122
- cv2.imwrite("./result/res.png", annotated_frame_bgr)
123
- send_email(res)
124
  return (res, annotated_frame)
125
 
126
  frame_no += 1 # Increment frame number
 
16
  subject = "Accident detected"
17
 
18
 
19
+ def send_email(accident_type,image):
20
  body = accident_type
21
 
22
  msg = MIMEMultipart()
 
26
 
27
  msg.attach(MIMEText(body, 'plain'))
28
 
29
+ is_success, buffer = cv2.imencode(".jpg", image)
30
+ attachment = buffer.tobytes()
31
 
32
  attachment_package = MIMEBase('application', 'octet-stream')
33
+ attachment_package.set_payload((attachment)
34
  encoders.encode_base64(attachment_package)
35
  attachment_package.add_header('Content-Disposition', "attachment; filename= " + filename)
36
  msg.attach(attachment_package)
 
88
  annotated_frame = results[0].plot()
89
  if len(res) >0:
90
  annotated_frame_bgr = cv2.cvtColor(annotated_frame, cv2.COLOR_RGB2BGR)
91
+ send_email(res, annotated_frame_bgr)
 
92
  return (res, annotated_frame)
93
 
94
  return ("No Class Detected", None)
 
118
 
119
  if len(res) >0:
120
  annotated_frame_bgr = cv2.cvtColor(annotated_frame, cv2.COLOR_RGB2BGR)
121
+ send_email(res, annotated_frame_bgr)
 
122
  return (res, annotated_frame)
123
 
124
  frame_no += 1 # Increment frame number