Skip to content

Instantly share code, notes, and snippets.

@jeffbass
Created March 24, 2020 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffbass/30f79e3dc87a60b857b7aac3c6562abf to your computer and use it in GitHub Desktop.
Save jeffbass/30f79e3dc87a60b857b7aac3c6562abf to your computer and use it in GitHub Desktop.
imageZMQ test program to check jpg_buffer type, size and dimensions
"""test sending a jpg buffer and check type & size of buffer
A simple test program that creates an image, then converts it to a
jpg_buffer and checks the type(), ndim, size and shape of the jpg_buffer.
This program tests some imports and some OpenCV functions, as well.
Open Source Licensed under MIT License (MIT)
Copyright (c) 2020, Jeff Bass, jeff@yin-yang-ranch.com
"""
import sys
import time
import numpy as np
import cv2
import imagezmq
# Create a sender instance
sender = imagezmq.ImageSender()
# Create a simple image
image = np.zeros((400, 400, 3), dtype='uint8')
green = (0, 255, 0)
cv2.rectangle(image, (50, 50), (300, 300), green, 5)
rpi_name = 'test_name' # need a sending text
jpeg_quality = 95 # 0 to 100, higher is better quality, 95 is cv2 default
ret_code, jpg_buffer = cv2.imencode(
".jpg", image, [int(cv2.IMWRITE_JPEG_QUALITY), jpeg_quality])
print('type of jpg_buffer', type(jpg_buffer))
print('ndim of jpg_buffer', jpg_buffer.ndim)
print('size of jpg_buffer', jpg_buffer.size)
print('shape of jpg_buffer', jpg_buffer.shape)
# any encryption function would go here
# encrypted_buffer = encryption_function(jpg_buffer) # an example
# it should return <class 'numpy.ndarray'> type, as cv2.imencode does
# not sending for now; but this works in my other tests
# sender.send_jpg(rpi_name, encrypted_buffer)
@jeffbass
Copy link
Author

Let me know if you try this and it runs OK. And if you have any questions, of course!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment