2

I have an opencv image:

img = cv2.imread(filename)
img = cv2.GaussianBlur(img, (5, 5), 0.15)

now I want to write it directly into zip

zipf = zipfile.ZipFile('out.zip', 'w', zipfile.ZIP_DEFLATED)
zipf.write(...)

Guess it's something to do with cv2.imencode() but not sure.
Can you help? Thanks

2 Answers 2

2

Found the answer:

zipf = zipfile.ZipFile('out.zip', 'w', zipfile.ZIP_DEFLATED)
retval, buf = cv2.imencode('.png', img)
zipf.writestr(name_in_zip, buf)

works like a charm.

Sign up to request clarification or add additional context in comments.

Comments

0

It seems that you can find answers to your question under this link: stackoverflow.com/questions/30049201/how-to-compress-a-file-with-shutil-make-archive-in-python/45711390

1 Comment

it's for the general case, but i wanted to know how to do it for opencv images specifically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.