zolodickk commited on
Commit
bc05896
·
verified ·
1 Parent(s): c4173dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -1,20 +1,16 @@
1
  from flask import Flask, render_template, request, jsonify
2
  import cv2
3
  import numpy as np
 
4
  from flask_socketio import SocketIO
5
 
6
  app = Flask(__name__)
7
  socketio = SocketIO(app)
8
 
9
- # Function to perform object detection
10
- def perform_detection(image):
11
- # Convert the frame to grayscale
12
  gray_frame = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
13
-
14
- # Perform your object detection on the grayscale frame
15
- # Replace this with your object detection code
16
- # For demonstration, we'll just return a dummy result
17
- return {"objects_detected": ["car", "person"], "frame": gray_frame}
18
 
19
  # Route to render index.html
20
  @app.route('/')
@@ -30,14 +26,21 @@ def detect():
30
  # Read the image
31
  image = cv2.imdecode(np.fromstring(image_file.read(), np.uint8), cv2.IMREAD_COLOR)
32
 
33
- # Perform detection
34
- detection_results = perform_detection(image)
 
 
 
 
35
 
36
- # Emit detection results using socket
37
- socketio.emit('detection_results', detection_results)
38
 
39
  # Return a response to the client
40
- return 'Detection complete'
 
 
 
41
 
42
 
43
 
 
1
  from flask import Flask, render_template, request, jsonify
2
  import cv2
3
  import numpy as np
4
+ import base64
5
  from flask_socketio import SocketIO
6
 
7
  app = Flask(__name__)
8
  socketio = SocketIO(app)
9
 
10
+ # Function to perform grayscale conversion
11
+ def convert_to_grayscale(image):
 
12
  gray_frame = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
13
+ return gray_frame
 
 
 
 
14
 
15
  # Route to render index.html
16
  @app.route('/')
 
26
  # Read the image
27
  image = cv2.imdecode(np.fromstring(image_file.read(), np.uint8), cv2.IMREAD_COLOR)
28
 
29
+ # Perform grayscale conversion
30
+ gray_image = convert_to_grayscale(image)
31
+
32
+ # Encode grayscale image to base64
33
+ retval, buffer = cv2.imencode('.jpg', gray_image)
34
+ gray_image_str = base64.b64encode(buffer).decode('utf-8')
35
 
36
+ # Emit grayscale image using socket
37
+ socketio.emit('grayscale_image', {'image': gray_image_str})
38
 
39
  # Return a response to the client
40
+ return 'Grayscale conversion complete'
41
+
42
+ if __name__ == '__main__':
43
+ socketio.run(app, debug=True)
44
 
45
 
46