Skip to content

Commit

Permalink
Update stream_server_test.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hamuchiwa authored Aug 9, 2018
1 parent 8838cf4 commit b3dd7c5
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions test/stream_server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,35 @@


class VideoStreamingTest(object):
def __init__(self):
def __init__(self, host, port):

self.server_socket = socket.socket()
self.server_socket.bind(('192.168.1.100', 8000))
self.server_socket.bind((host, port))
self.server_socket.listen(0)
self.connection, self.client_address = self.server_socket.accept()
self.connection = self.connection.makefile('rb')
self.host_name = socket.gethostname()
self.host_ip = socket.gethostbyname(self.host_name)
self.streaming()

def streaming(self):

try:
print "Connection from: ", self.client_address
print "Streaming..."
print "Press 'q' to exit"
print("Host: ", self.host_name + ' ' + self.host_ip)
print("Connection from: ", self.client_address)
print("Streaming...")
print("Press 'q' to exit")

stream_bytes = ' '
# need bytes here
stream_bytes = b' '
while True:
stream_bytes += self.connection.read(1024)
first = stream_bytes.find('\xff\xd8')
last = stream_bytes.find('\xff\xd9')
first = stream_bytes.find(b'\xff\xd8')
last = stream_bytes.find(b'\xff\xd9')
if first != -1 and last != -1:
jpg = stream_bytes[first:last + 2]
stream_bytes = stream_bytes[last + 2:]
#image = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8), cv2.CV_LOAD_IMAGE_GRAYSCALE)
image = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8), cv2.CV_LOAD_IMAGE_UNCHANGED)
image = cv2.imdecode(np.frombuffer(jpg, dtype=np.uint8), cv2.IMREAD_COLOR)
cv2.imshow('image', image)

if cv2.waitKey(1) & 0xFF == ord('q'):
Expand All @@ -40,5 +43,8 @@ def streaming(self):
self.connection.close()
self.server_socket.close()


if __name__ == '__main__':
VideoStreamingTest()
# host, port
h, p = "192.168.1.100", 8000
VideoStreamingTest(h, p)

0 comments on commit b3dd7c5

Please sign in to comment.