I'm working on a socket data transfer project. I want to watch client screen. I'm using pillow and pickle module both server and client but when I trying to send ImageGrab.grab() object, object size is 3Mb. It's very high data for transferring. Although object size is 3MB, saved size (ImageGrab.grab().save("example.jpg")) is 200 kb. When i save file then read saved photo for transferring, it cause very high cpu usage. Even i try to send bytes of object -> ImageGrab.grab().tobytes() <- , its again 3mb. How can i send only data of image from object without saving file ?
How to decrease Image object size that dumped through pickle in Python
310 views Asked by Ertuğrul Çakıcı At
2
There are 2 answers
3
Epsi95
On
here is a working example
server
import socket
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
plt.figure(1)
host = socket.gethostname()
port = 8080
server_socket = socket.socket()
server_socket.bind((host, port))
server_socket.listen()
conn, address = server_socket.accept()
print("Connection from: " + str(address))
image_data = b''
while True:
data = conn.recv(1024*4) # 4kb data
print('received data')
if(data != 'EOD'.encode()):
image_data+=data
else:
image = Image.frombytes('RGB', (800, 800), image_data, 'raw')
plt.clf()
plt.imshow(np.asarray(image))
plt.pause(1)
#plt.show()
image_data = b''
conn.close()
client
import socket
import pyautogui
import time
host = socket.gethostname()
port = 8080
client_socket = socket.socket()
client_socket.connect((host, port))
while True:
image = pyautogui.screenshot()
print('took screen shot')
image = image.resize(size=(800, 800)) # configure the size using image.size to maintain proper aspect ratio
client_socket.sendall(image.tobytes())
time.sleep(2)
client_socket.send('EOD'.encode())
client_socket.close()
Related Questions in PYTHON
- How to store a date/time in sqlite (or something similar to a date)
- Instagrapi recently showing HTTPError and UnknownError
- How to Retrieve Data from an MySQL Database and Display it in a GUI?
- How to create a regular expression to partition a string that terminates in either ": 45" or ",", without the ": "
- Python Geopandas unable to convert latitude longitude to points
- Influence of Unused FFN on Model Accuracy in PyTorch
- Seeking Python Libraries for Removing Extraneous Characters and Spaces in Text
- Writes to child subprocess.Popen.stdin don't work from within process group?
- Conda has two different python binarys (python and python3) with the same version for a single environment. Why?
- Problem with add new attribute in table with BOTO3 on python
- Can't install packages in python conda environment
- Setting diagonal of a matrix to zero
- List of numbers converted to list of strings to iterate over it. But receiving TypeError messages
- Basic Python Question: Shortening If Statements
- Python and regex, can't understand why some words are left out of the match
Related Questions in SOCKETS
- Node.js Server + Socket.IO + Android Mobile Applicatoin XHR Polling Error...?
- My server TCP doesn't receive messages from the client in C
- how is strncpy able to copy from source to empty destination?
- Python Multicast packet receiver stops receiving multicast packets when computer is connected to WiFi
- Python Client-Server Communication with Protocol
- Reversed TLS re-connection issue
- Android 13 & 14 seem to close WebSocket connection, if i put app in background, after ~20s
- Java SocketException: Connection reset,. What is the cause?
- Multipart/form-data with chunked data transfer (ICAP protocol)
- View Socket View
- Client connection timeout during Android & Windows PC communication via sockets
- Browser connect to raw sockets even possible?
- Protocol 43200 after unpacking received data
- Unity SocketIo using Best http2 plugin want to use in webgl
- How does pre-allocating a pool of SocketAsyncEventArgs objects upfront improve the performance of a server application in c#
Related Questions in PYTHON-IMAGING-LIBRARY
- How to Draw Chinese Characters on a Picture with OpenCV
- Python cv2 imwrite() - RGB or BGR
- Python pillow library text align center
- Python canvas save drawing problem with postscript sizes
- Reading IPTC information Django
- How to Make PNG Remain Transparent in Tkinter?
- Python pyside6 Process finished with exit code 139 (interrupted by signal 11:SIGSEGV)
- I am trying to build an AI image classifier in Python using a youtube guide. When I run my program (unfinished) it does not open up the image
- Is there a way to include a copied image in Python/Tweepy, I can't seem to do it using Pillow
- Trying to convert an image to a Stream for use with Spire.Barcode ScanStream functionality
- How do you create a semi-transaparent image in numpy and saving it in pillows as PNG
- ImportError: cannot import name 'PILLOW_VERSION' from 'PIL'
- How to distort an image with python PIL using an inner quad without cropping out of the quad
- PyInstaller has a PIL directory, but the exe file throws an error "ModuleNotFoundError: No module named 'PIL'"
- Image Wrap in Pillow
Related Questions in PICKLE
- What is 'Invalid Load Key, '\x00'
- How to resolve these Unpickling Errors?
- 1 filenames = [] 2 ----> 3 for file in os.zipfile('images.zip'):
- How to remove the JSON Loads Error at Server Side?
- TypeError: 'str' object cannot be interpreted as an integer when using pickle
- Cookies doesn't work in sub services pages
- AttributeError: Can't pickle local object 'Layer._initializer_tracker.<locals>.<lambda>'
- Can't load pickle with custom preprocessing classes
- Fast open pickle in Python3
- Python2 unable to pickle string
- Why is my python socket connection not receiving all of the data, sometimes...?
- PyTorch and Pickle Error: AttributeError: Can't get attribute "Class_name" on <module '__main__' from '/load_model.py'>
- I am unable to load a keras model using the pickle.load method
- How do I stop celery from converting my custom classes into dictionaries?
- is it possible to pickle mplcursors object annotation to save and display later?
Related Questions in IMAGEGRAB
- Screen resolution according to tkinter and PIL?
- Vs Code saving image in different folder than Pycharm
- Python script using ImageGrab causes intermittent stuttering
- Why am I getting a value error in imagegrab pil?
- Can't manage to get correct area selection for ImageGrab.grab() even when copying online code that is supposed to work. Multiple exemples tried
- Why is image rotated diagonally?
- the fastest method of capturing full screen with python?
- pyscreenshot as ImageGrab doesn't work after compiling with PyInstaller to exe
- How can I save multiple files with python?
- PIL imagegrab().grab().crop(...) crops not the given coordinates
- Can't import imagegrab
- ImageGrab.grab not get widget of tkinter window, but screen area under it
- Why does PIL.ImageGrab.grab of specific window doesn't work properly?
- Selecting Screen 2 from Snipping_Tool in Python
- Why tesseract wont find this easy text in image?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
I solved this problem through IO