0

I have four images, each slices of a larger image. If I string them together horizontally, then I get the larger image. To complete this task, I'm using python 2.7 and the OpenCV library, specifically the hconcat() function. Here is the code:

with open("tempfds.jpg", 'ab+') as f:
            f.write(cv2.hconcat(cv2.hconcat(cv2.imread("491411.jpg"),cv2.imread("491412.jpg")),cv2.hconcat(cv2.imread("491413.jpg"),cv2.imread("491414.jpg"))))

When I run it, everything works fine. But when I try to open the image itself, I get an error: Error interpreting JPEG image file (Not a JPEG file: starts with 0x86 0x7e). All the images I'm using are jpg's, so I don't understand why this error is occurring. Any insight is appreciated.

2
  • The error message is correct. JPEGs start with 0xff 0xd8. Commented May 10, 2020 at 21:13
  • You can also use cv2.vconcat() and cv2.hconcat(), see here: stackoverflow.com/questions/14579541/… Commented May 9, 2022 at 19:19

1 Answer 1

2

If you want to write a JPEG, you need:

cv2.imwrite('lovely.jpg', image)

where image is all your images concatenated together.

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

Comments

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.