Ask Your Question
1

Can OpenCV read images with a different 'byte ordering'?

asked 2018-05-05 00:33:34 -0600

saihv gravatar image

I am working on a highly performance-critical image processing pipeline on a Jetson TX2 (with an ARM processor), which involves reading a set of images and then performing deep learning based object detection through Darknet. Darknet, written in C, has its own representation of how images are stored, which is different from how OpenCV's IplImage or a Python numpy array would store the images. Because of the requirements of my project, I am currently interfacing with this C code by first reading the images through Python (cv2.imread()) and then passing them to Darknet. But I can also call cvLoadImage() from C.

The default way OpenCV is storing the data is as one contiguous block arranged column-wise, then row-wise, then channel-wise. On the other hand, the Darknet format needs to be arranged by channel first, then by column, then by row. The following picture illustrates the difference:

enter image description here

This means I need to reorder the pixels from the OpenCV format to Darknet format, which is some additional overhead I would like to avoid. Is there a way to make OpenCV read the image differently, either through cv2.imread() or the IplImage format in cvLoadImage, so as to directly get the format Darknet is expecting?

edit retag flag offensive close merge delete

Comments

1

you made a nice drawing, but the captions are in reverse, right ?

also note, that opencv by default uses BGR, not RGB ordering

berak gravatar imageberak ( 2018-05-05 02:38:43 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-05-05 02:54:43 -0600

berak gravatar image
  • please NEVER use cvLoadImage(), or anything from opencv's deprecated C-api , it might be gone tomorrow.
  • you don't even have to use anything from opencv there, darknet has it's own image loading routines (stb_image)
  • yes, you have to split your interleaved pixels into seperate color planes, or channels. that's not at all specific to darknet, but common to all dnn's
  • darknet also already has builtin functions to deal with this, please look at src/image.c, there's ipl_into_image() and such
  • opencv has a split() function to seperate the interleaved image into channels.
edit flag offensive delete link more

Comments

it might be gone tomorrow --> actually for people using OpenCV4.x it is gone, or at least badly broken :D

StevenPuttemans gravatar imageStevenPuttemans ( 2018-05-08 08:33:03 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-05-05 00:33:34 -0600

Seen: 2,081 times

Last updated: May 05 '18