jeffbass / imagezmq

A set of Python classes that transport OpenCV images from one computer to another using PyZMQ messaging.
MIT License
1.01k stars 160 forks source link

Can I change the image size? #46

Open endlessboy opened 3 years ago

endlessboy commented 3 years ago

Hello @jeffbass !

I saved the image after adding cv2.imwrite.

The saved image size is 320x240 which is too small for my project.

cv2.resize code makes the image blur.

My camera module can save the image clean with camera.resolution = (2560,1936) code but I can't figure out how to change image size in imagezmq libary...

Can I resize the image without blurring issue?

Thank you

jeffbass commented 3 years ago

Hi @endlessboy, Yes, you can change the image size, but it needs to be done in the sending program. The sending program is not part of imageZMQ. The imageZMQ classes are just an image transport mechanism and do not choose the image size. The test programs provided in this repository are very simple examples of image sending and image receiving programs. The sending programs in the test folder use a PiCamera through the imutils.VideoSteam class. As an example, here is how you would modify the test_2_rpi_send_images.py program to set the resolution of the PiCamera:

import sys

import socket
import time
import cv2
from imutils.video import VideoStream
import imagezmq

# use either of the formats below to specifiy address of display computer
sender = imagezmq.ImageSender(connect_to='tcp://jeff-macbook:5555')
# sender = imagezmq.ImageSender(connect_to='tcp://192.168.1.190:5555')

rpi_name = socket.gethostname()  # send RPi hostname with each image
picam = VideoStream(usePiCamera=True,resolution=(640, 480)).start()  # sets PiCamera resolution to (640,480)
time.sleep(2.0)  # allow camera sensor to warm up
while True:  # send images as stream until Ctrl-C
    image = picam.read()
    sender.send_image(rpi_name, image)

You will need to set your image resolution in your own sending program in a similar way. The image sending and image receiving programs in the test folder are examples for testing imageZMQ, but are not actually part of (or called by) the imageZMQ classes. I hope this helps, Jeff (P.S. imutils is a helpful collection of Python classes on GitHub here. imutils is an open source project authored by Adrian Rosebrock, and is not a part of imageZMQ.)