Elif
Elif

Reputation: 21

Converting JPG to TIFF using Opencv

I want to convert a jpg image to tiff.

I tried to do it with opencv with python.

import cv2
image = cv2.imread("image.jpg")

retval, buf = cv2.imencode(".tiff", image)
cv2.imwrite("out.tiff")

And I have this:
Process finished with exit code 136 (interrupted by signal 8: SIGFPE) I referred this link

But I couldn't make it work. Any help would be appreciated.

Upvotes: 1

Views: 4398

Answers (1)

Andris
Andris

Reputation: 973

For me this version worked without errors:

import cv2
image = cv2.imread("image.jpg")

cv2.imwrite("out.tiff", image)

Why do you need the imencode? Using that gives the same resulting file for me, just creates a temporary memory buffered, already TIFF-compressed version of the image:

retval, buf = cv2.imencode(".tiff", image)
with open('out2.tiff', 'wb') as fout:
    fout.write(buf.tostring())

Upvotes: 2

Related Questions