Problem with Texturing from RGB array

Hey,

I am trying to apply a Texture from a JPG in python. The problem is that after I loaded and processed the Image via PIL, openCV and numpy, the Texture seems to be off in Colors. This only happens in Panda3d, when i display the same Array with for example matplotlib, it shows the original JPG with correct colors. I already tried switching the RGB channels before converting it to a bytestring. What could I be doing wrong?
Here a picture for comparison (upper right is obviously not glossmap, its the same array as the texture array, displayed on a tkinter canvas):

Here my code (or atleast the important parts, cant run like this):

from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
import tkinter
from tkinter.filedialog import askopenfilename
import numpy as np
from PIL import Image,ImageTk

class TextureMapGenerator(ShowBase):
	def __init__(self,*args,**kwargs):
		ShowBase.__init__(self,*args,**kwargs)
        self.RGB_tex = Texture()
        self.cm = CardMaker()
                '''.....'''

    def open_new_image(self):
		'''opens filedialog and stores the opened image in self.image, calls show_texture_card function afterwards to show the image as texture'''
		dir = askopenfilename(filetypes = self.file_types)
		if dir == None or dir == '':
			return
		print(dir)
		img = Image.open(dir)
		self.image = np.array(img)
		self.texture_img = Image.fromarray(np.flipud(self.image)).resize((256,256),Image.BILINEAR)
		self.texture_img = ImageTk.PhotoImage(image=self.texture_img)
		self.glossmap_canvas.create_image(int(self.thumbnail_res/2),int(self.thumbnail_res/2),image=self.texture_img)
		self.resolution = self.image.shape
		self.show_texture_card()

    def show_texture_card(self):
		self.nodepath = self.render.attachNewNode(self.cm.generate())

		self.RGB_tex.setup2dTexture(self.resolution[1],self.resolution[0], Texture.T_unsigned_byte, Texture.F_rgb8)
		RGB_buff = self.image.astype(np.uint8).tobytes()
		self.RGB_tex.setRamImage(RGB_buff)

		self.nodepath.setTexture(self.RGB_tex)

Panda3D uses BGR ordering when storing the image in RAM. Use setRamImageAs(RGB_buff, "RGB") to specify the data ordering explicitly.

perfect, thank you. It’s interesting that swapping the channels in the array to BGR won’t to the same thing. Why is that?

I don’t see a reason why that wouldn’t work; perhaps you have made a mistake in the way you implemented that?

Well, i simply copied the channels via
“R = Image[:, :, 0]”
And then threw it into the New Positions of the array
“Image[:, :, 3] = R”