Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

numpy processor #94

Open
ZCban opened this issue Apr 28, 2024 · 0 comments
Open

numpy processor #94

ZCban opened this issue Apr 28, 2024 · 0 comments

Comments

@ZCban
Copy link

ZCban commented Apr 28, 2024

def process(self, rect, width, height, region, rotation_angle):

pitch = int(rect.Pitch)
if rotation_angle in (0, 180):
    offset = (region[1] if rotation_angle == 0 else height - region[3]) * pitch
    height = region[3] - region[1]
else:
    offset = (region[0] if rotation_angle == 270 else width - region[2]) * pitch
    width = region[2] - region[0]


buffer = (ctypes.c_char * (pitch * height)).from_address(ctypes.addressof(rect.pBits.contents) + offset)
pitch = pitch // 4
if rotation_angle in (0, 180):
    image = np.ndarray((height, pitch, 4), dtype=np.uint8, buffer=buffer)
elif rotation_angle in (90, 270):
    image = np.ndarray((width, pitch, 4), dtype=np.uint8, buffer=buffer)


if rotation_angle == 90:
    image = np.rot90(image, axes=(1, 0))
elif rotation_angle == 180:
    image = np.rot90(image, k=2, axes=(0, 1))
elif rotation_angle == 270:
    image = np.rot90(image, axes=(0, 1))


if rotation_angle in (0, 180):
    image = image[region[1]:region[3], :width, :]
else:
    image = image[:height, region[0]:region[2], :]

# Convert the color of the cropped image only # reduce unnecessary CPU usage
if self.color_mode is not None:
    image = self.process_cvtcolor(image)

return image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant