AkshatJain1402 commited on
Commit
bc0621e
1 Parent(s): c0a3be3

updating files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
client.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import cv2
2
+ # import socket
3
+ # import io
4
+ # import struct
5
+
6
+ # # Define connection details (replace with your actual values)
7
+ # HOST = '144.126.254.143' # IP address of the receiving device
8
+ # PORT = 5555 # Port number for communication
9
+
10
+ # # Create a socket connection
11
+ # connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
12
+ # connection.connect((HOST, PORT))
13
+
14
+ # print("Starting camera using OpenCV...")
15
+
16
+ # # Initialize video capture using OpenCV
17
+ # cap = cv2.VideoCapture(0) # Change 0 to the video source index if needed
18
+
19
+ # while True:
20
+ # # Capture frame-by-frame
21
+ # ret, frame = cap.read()
22
+
23
+ # # Check if frame capture is successful
24
+ # if not ret:
25
+ # print("Error: Frame not captured")
26
+ # break
27
+
28
+ # # Encode frame as JPEG
29
+ # _, jpeg_buffer = cv2.imencode('.jpg', frame)
30
+
31
+ # # Create a stream-like object from the JPEG buffer
32
+ # stream = io.BytesIO(jpeg_buffer.tobytes())
33
+
34
+ # # Get the stream's current position (similar to stream.tell())
35
+ # stream_length = stream.tell()
36
+
37
+ # # Send frame size (4 bytes) in little-endian format
38
+ # connection.sendall(struct.pack('<L', stream_length))
39
+
40
+ # # Reset the stream position (similar to stream.seek(0))
41
+ # stream.seek(0)
42
+
43
+ # # Send the entire JPEG frame
44
+ # connection.sendall(stream.read())
45
+
46
+ # # Reset the stream for the next frame
47
+ # stream.seek(0)
48
+ # stream.truncate()
49
+
50
+ # # Display the frame for preview (optional)
51
+ # cv2.imshow('Frame', frame)
52
+
53
+ # # Exit on 'q' key press
54
+ # if cv2.waitKey(1) == ord('q'):
55
+ # break
56
+
57
+ # # Release resources
58
+ # cap.release()
59
+ # connection.close()
60
+ # cv2.destroyAllWindows()
61
+
62
+ # print("Camera and connection closed")
63
+ import struct
64
+ import time
65
+ import socket
66
+ import cv2
67
+
68
+ SERVER_PORT=5555
69
+ SERVER_IP='192.168.137.1'
70
+
71
+ # Define the codec using VideoWriter_fourcc and create a VideoWriter object
72
+ fourcc = cv2.VideoWriter_fourcc(*'H264')
73
+ out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (640, 480))
74
+
75
+ cap=cv2.VideoCapture(0)
76
+ client_socket=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
77
+ client_socket.connect((SERVER_IP,SERVER_PORT))
78
+ count=0
79
+ while True:
80
+ time.sleep(0.05)
81
+ count += 1
82
+ print('sending frame', count)
83
+ ret, frame = cap.read()
84
+ if ret:
85
+ # Write the frame into the file 'output.mp4'
86
+ out.write(frame)
87
+
88
+ # Convert the frame to bytes
89
+ frame_encoded = cv2.imencode('.jpg', frame)[1].tostring()
90
+
91
+ # Send the size of the frame
92
+ client_socket.sendall(len(frame_encoded).to_bytes(4, 'big'))
93
+
94
+ # Send the frame
95
+ client_socket.sendall(frame_encoded)
96
+ else:
97
+ break
98
+
99
+
100
+ if cv2.waitKey(1)==ord('q'):
101
+ break
102
+ cap.release()
103
+ client_socket.close()
104
+ cv2.destroyAllWindows( )
flaskServer.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy
3
+ from flask import Flask, render_template, Response, stream_with_context, request
4
+ app=Flask('__name__')
5
+
6
+ video=cv2.VideoCapture(0)
7
+ global fps
8
+ fps=0
9
+ while True:
10
+
11
+ ret,frame=video.read()
12
+ if not ret:
13
+ break
14
+ fps=fps+1
15
+ output_filePath=f'/home/kali/liveStream/demo{fps}.jpg'
16
+ #try:
17
+ # cv2.imwrite(output_filePath,frame)
18
+ # print('done')
19
+ #except Exception as e:
20
+ # print('error',e)
21
+ if not ret:
22
+ print('not ret')
23
+ break
24
+ else:
25
+ ret,buffer=cv2.imencode('.jpeg',frame)
26
+ frame=buffer.tobytes()
27
+ yield (b' --frame\r\n' b'Content-type: imgae/jpeg\r\n\r\n' + frame +b'\r\n')
28
+
29
+ @app.route('/camera')
30
+ def camera():
31
+ return render_template('camera.html')
32
+
33
+ @app.route('video_feed')
34
+ def video_feed():
35
+ return Response(video_stream(),mimetype='multipart.x-mixed-replace; boundary=frame$')
36
+
37
+ app.run(host='0.0.0.0',port='5000', debug=False)
38
+
39
+ # cv2.imshow('video',frame)
harshServer.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import socket
2
+ import cv2
3
+ import struct
4
+ import numpy as np
5
+
6
+ # Import library for H.265 decoding (choose one)
7
+ # Option 1: Using OpenCV with FFmpeg backend (if FFmpeg is installed)
8
+ # cv2.h264decode is a wrapper for FFmpeg's H.265 decoder
9
+ # Make sure FFmpeg is installed and the environment variable (e.g., PATH) is set correctly
10
+
11
+ # Option 2: Using a dedicated H.265 decoder library (e.g., gstreamer)
12
+ # You'll need to install and configure the chosen library following its documentation
13
+
14
+ # Port to listen on
15
+ SERVER_PORT = 5555
16
+
17
+ # Create a TCP socket
18
+ server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
19
+ server_socket.bind(("", SERVER_PORT))
20
+ server_socket.listen(1)
21
+
22
+ # Accept client connection
23
+ client_socket, client_address = server_socket.accept()
24
+ print(f"Connected to client {client_address}")
25
+ count = 0
26
+
27
+ while True:
28
+ print('Receiving')
29
+ # Receive frame size (4 bytes integer)
30
+ data = client_socket.recv(4)
31
+ if not data:
32
+ break
33
+ frame_size = int.from_bytes(data, byteorder='big')
34
+
35
+ # Receive the frame data (based on size)
36
+ data = b''
37
+ while len(data) < frame_size:
38
+ packet = client_socket.recv(4096)
39
+ if not packet:
40
+ break
41
+ data += packet
42
+
43
+ # Decode the received H.265 data
44
+ # Option 1: Using OpenCV with FFmpeg backend
45
+ frame = cv2.imdecode(np.frombuffer(data, dtype=np.uint8), cv2.IMREAD_COLOR)
46
+
47
+ # Option 2: Using a dedicated H.265 decoder library
48
+ # Replace this with the appropriate decoding function from your chosen library
49
+ # frame = ... (decode the data using your library)
50
+
51
+ # Process the frame here (optional)
52
+ # You can display the frame, save it, or perform further analysis
53
+
54
+ # Display the frame (optional)
55
+ cv2.imshow('Received Frame', frame)
56
+ cv2.imwrite(f'./imagesMQZ/frame{count}.jpeg', frame)
57
+ if cv2.waitKey(1) & 0xFF == ord('q'):
58
+ break
59
+
60
+ # Check for client disconnect
61
+ if not frame:
62
+ break
63
+
64
+ server_socket.close()
65
+ cv2.destroyAllWindows()
imageMCQServer.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import the necessary packages
2
+ from imutils import build_montages
3
+ from datetime import datetime
4
+ import numpy as np
5
+ import imagezmq
6
+ import argparse
7
+ import imutils
8
+ import cv2
9
+ mW=1
10
+
11
+
12
+ mH=1
13
+
14
+ # initialize the ImageHub object
15
+ imageHub= imagezmq.ImageHub()
16
+ frameDict = {}
17
+ print("[INFO] connecting to server...")
18
+ count=0
19
+ while True:
20
+ count+=1
21
+ try:
22
+
23
+ (rpiName, frame) = imageHub.recv_image()
24
+ imageHub.send_reply(b'OK')
25
+ frame=imutils.resize(frame,width=400)
26
+ (H,W)=frame.shape[:2]
27
+
28
+ #save the frame locally
29
+ cv2.imwrite(f'./imagesMQZ/frame{count}.jpeg',frame)
30
+ #read frame from local storage
31
+ cv2.imshow('Frame', frame)
32
+ if cv2.waitKey(1) & 0xFF == ord('q'):
33
+ break
34
+
35
+
36
+
37
+ except Exception as e:
38
+ print('error',e)
39
+ continue
40
+ cv2.destroyAllWindows()
imagesMQZ/frame0.jpeg ADDED
imagesMQZ/frame1.jpeg ADDED
imagesMQZ/frame10.jpeg ADDED
imagesMQZ/frame100.jpeg ADDED
imagesMQZ/frame101.jpeg ADDED
imagesMQZ/frame102.jpeg ADDED
imagesMQZ/frame103.jpeg ADDED
imagesMQZ/frame104.jpeg ADDED
imagesMQZ/frame105.jpeg ADDED
imagesMQZ/frame106.jpeg ADDED
imagesMQZ/frame107.jpeg ADDED
imagesMQZ/frame108.jpeg ADDED
imagesMQZ/frame109.jpeg ADDED
imagesMQZ/frame11.jpeg ADDED
imagesMQZ/frame110.jpeg ADDED
imagesMQZ/frame111.jpeg ADDED
imagesMQZ/frame112.jpeg ADDED
imagesMQZ/frame113.jpeg ADDED
imagesMQZ/frame114.jpeg ADDED
imagesMQZ/frame115.jpeg ADDED
imagesMQZ/frame116.jpeg ADDED
imagesMQZ/frame117.jpeg ADDED
imagesMQZ/frame118.jpeg ADDED
imagesMQZ/frame119.jpeg ADDED
imagesMQZ/frame12.jpeg ADDED
imagesMQZ/frame120.jpeg ADDED
imagesMQZ/frame121.jpeg ADDED
imagesMQZ/frame122.jpeg ADDED
imagesMQZ/frame123.jpeg ADDED
imagesMQZ/frame124.jpeg ADDED
imagesMQZ/frame125.jpeg ADDED
imagesMQZ/frame126.jpeg ADDED
imagesMQZ/frame127.jpeg ADDED
imagesMQZ/frame128.jpeg ADDED
imagesMQZ/frame129.jpeg ADDED
imagesMQZ/frame13.jpeg ADDED
imagesMQZ/frame130.jpeg ADDED
imagesMQZ/frame131.jpeg ADDED
imagesMQZ/frame132.jpeg ADDED
imagesMQZ/frame133.jpeg ADDED
imagesMQZ/frame134.jpeg ADDED
imagesMQZ/frame135.jpeg ADDED
imagesMQZ/frame136.jpeg ADDED
imagesMQZ/frame137.jpeg ADDED
imagesMQZ/frame138.jpeg ADDED
imagesMQZ/frame139.jpeg ADDED