Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement image transfer #5

Open
mkristofic opened this issue Dec 19, 2019 · 1 comment
Open

Implement image transfer #5

mkristofic opened this issue Dec 19, 2019 · 1 comment
Assignees

Comments

@mkristofic
Copy link
Collaborator

mkristofic commented Dec 19, 2019

Implement a class that enables sending images from the client (Raspberry PI) to the server (GCP VM Instance).
Class name: "Streamer".
Store the class source code inside the "modules" folder.

@mkristofic mkristofic self-assigned this Dec 19, 2019
mkristofic added a commit that referenced this issue Dec 30, 2019
Created the Streamer class for the TCP image transfer.
@mkristofic
Copy link
Collaborator Author

mkristofic commented Dec 30, 2019

The Streamer class was created. The class was tested with the server and client scripts:

# server.py

import socket
import numpy as np
import cv2

host = "localhost"
port = 5000
server_address = (host, port)

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(server_address)
print('starting up on %s:%s' % server_address)

while True:
    data, address = sock.recvfrom(65535)
    nparr = np.frombuffer(data, np.uint8)
    img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
    cv2.imshow('Server feed',img)
    # print(data)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
# client.py

import socket
from modules.Streamer import Streamer

streamer = Streamer("localhost", 5000, 0)
streamer.send_to_server()

The class uses TCP to send the image data to the server. While testing, a problem was discovered. Size of a image that is sent over the TCP tends to exceed the maximal size of 65535 bytes. The problem can be avioded by slightly changing the Recorder class to output JPEGs with lower quality. For example, in the get_frame() method:

success, image = self.video.read()
encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 75]
ret, jpeg = cv2.imencode('.jpg', image, encode_param)

mkristofic added a commit that referenced this issue Jan 4, 2020
Added the destructor method to the Streamer class which closes the opened socket.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant