'How to Convert a 2D List of Tuples to a 3D Numpy Array Quickly?

I have a stream of images coming in from a source which is, unfortunately a list of list of tuples of RGB values. I want to perform real-time processing on the image, but that code expects a Numpy array of shape (X,Y,3) where X and Y are the image height and width.

X = [[(R, G, B)...]]
img_arr = np.array([*X])

The above works fine but takes nearly a quarter of a second with my images which is obviously too slow. Interestingly, I also need to go back the other direction after the processing is done, and that code (which seems to work) is not so slow:

imgout = map(tuple, flipped_image)

Some relevant other questions:

why is converting a long 2D list to numpy array so slow?

Convert List of List of Tuples Into 2d Numpy Array



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source