Skip to content

Commit

Permalink
Revert using numpy for conversion of BGRA->BGR/RGB. Numpy was faster …
Browse files Browse the repository at this point in the history
…but it was producing a non-contiguous array, which changes the behavior of the library
  • Loading branch information
Agade09 committed Apr 17, 2023
1 parent bf02b69 commit 204a558
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions dxcam/processor/numpy_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ def process_cvtcolor(self, image):

# only one time process
if self.cvtcolor is None:
if self.color_mode=="BGR":
self.cvtcolor = lambda image: image[:,:,:3] #BGRA -> BGR conversion
elif self.color_mode=='RGB':
self.cvtcolor = lambda image: np.flip(image[:,:,:3],axis=-1) #BGRA -> RGB conversion
elif self.color_mode=='RGBA':
self.cvtcolor = lambda image: cv2.cvtColor(image, cv2.COLOR_BGRA2RGBA)
color_mapping = {
"RGB": cv2.COLOR_BGRA2RGB,
"RGBA": cv2.COLOR_BGRA2RGBA,
"BGR": cv2.COLOR_BGRA2BGR,
"GRAY": cv2.COLOR_BGRA2GRAY
}
cv2_code = color_mapping[self.color_mode]
if cv2_code != cv2.COLOR_BGRA2GRAY:
self.cvtcolor = lambda image: cv2.cvtColor(image, cv2_code)
else:
self.cvtcolor = lambda image: cv2.cvtColor(image, cv2.COLOR_BGRA2GRAY)[
self.cvtcolor = lambda image: cv2.cvtColor(image, cv2_code)[
..., np.newaxis
]
return self.cvtcolor(image)
Expand Down

0 comments on commit 204a558

Please sign in to comment.