{"id":13869951,"url":"https://github.com/ekbanasolutions/numpy-using-socket","last_synced_at":"2025-07-15T18:32:34.383Z","repository":{"id":98929659,"uuid":"180294017","full_name":"ekbanasolutions/numpy-using-socket","owner":"ekbanasolutions","description":"Send Python Numpy Array over TCP/IP socket with simple codes. ","archived":false,"fork":false,"pushed_at":"2019-04-09T05:59:25.000Z","size":9,"stargazers_count":16,"open_issues_count":3,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-06T21:22:47.159Z","etag":null,"topics":["numpy","numpy-arrays","opencv","python","socket"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ekbanasolutions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-04-09T05:48:46.000Z","updated_at":"2024-03-22T00:59:37.000Z","dependencies_parsed_at":"2024-01-16T06:14:29.978Z","dependency_job_id":null,"html_url":"https://github.com/ekbanasolutions/numpy-using-socket","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekbanasolutions%2Fnumpy-using-socket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekbanasolutions%2Fnumpy-using-socket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekbanasolutions%2Fnumpy-using-socket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekbanasolutions%2Fnumpy-using-socket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ekbanasolutions","download_url":"https://codeload.github.com/ekbanasolutions/numpy-using-socket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226063154,"owners_count":17567959,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["numpy","numpy-arrays","opencv","python","socket"],"created_at":"2024-08-05T20:01:23.114Z","updated_at":"2024-11-23T15:32:22.346Z","avatar_url":"https://github.com/ekbanasolutions.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# NpSocket\n## About\nThis python module was built to transfer the Numpy array over a TCP/IP socket. There is [Numpy Socket package](https://github.com/sabjorn/NumpySocket)\norginally written by [@sabjorn](https://github.com/sabjorn/) to stream video frames from OpenCV  which only works for python2. But I couldn't find the decent solution for python3. So based on a [thread in stackoverflow](https://stackoverflow.com/questions/30988033/sending-live-video-frame-over-network-in-python-opencv), this module was written to send the numpy array over the TCP/IP sokcet. This module make use of the code sample of the answer given by [@nareddyt](https://stackoverflow.com/users/4402434/nareddyt) in the same stackoverflow thread. \n\nI'm actually using this module to send the video frame captured through opencv, make a prediction on the image, and send\nback the modified image to the Pi client.\n\n## Installation \n1. First clone this repository. \n2. cd into the cloned directory. \n3. Run `python3 setup.py install` in the terminal. \n4. You should have a working NpSocket module. \n5. Varify this by running the following commands in terminal: \n```\n\u003e\u003e\u003e import npsocket\n\u003e\u003e\u003e from npsocket import SocketNumpyArray\n\u003e\u003e\u003e exit() \n\n```\n## Examples:\n1. Initalize the Receiver: \n```\nfrom npsocket import SocketNumpyArray\nsock_receiver = SocketNumpyArray()\nsock_receiver.initalize_receiver(9999) # the 9999 is the port you can change it with your own. \nwhile True:\n    frame = sock_receiver.receive_array()  # Receiving the image as numpy array. \n    # Display\n    cv2.imshow('frame', frame)\n    cv2.waitKey(1)\n```\n2. Intialize the Sender: \n```\nfrom npsocket import SocketNumpyArray\nimport cv2\n\ncap = cv2.VideoCapture(0)\nsock_sender = SocketNumpyArray()\n\nsock_sender.initialize_sender('localhost', 9999)\n\nwhile True:\n    ret, frame = cap.read()\n    frame = cv2.resize(frame, (620, 480))\n    sock_sender.send_numpy_array(frame)\n```\n3. Run the 'reciver' for and the the 'sender'. You should be able to see the frame being sent by the sender and displayed by the receiver in the CV2 window. \n\nIn the same way, you should be able to transfer any Numpy Array. There is an example files in the videostream directory, where the above example is shown. If you simply want to run and see it, then you can first run `python3 receiver.py` and then `python3 sender.py` and see it working. \n\n## Contributors\n1. [Bibek](https://github.com/bbkchdhry)\n2. [Vaghawan](https://github.com/vaghawan)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekbanasolutions%2Fnumpy-using-socket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fekbanasolutions%2Fnumpy-using-socket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekbanasolutions%2Fnumpy-using-socket/lists"}