rapidsai / rapidsai/cucim

[FEA] Provide a utility function to convert OpenCV image to CuPy array

Open
#331 0 comments 0 reactions 1 assignee View on GitHub

@gigony is already working on this.

Since Jul 16, 2022.

feature request
Dominant language
Jupyter Notebook
Stars
467
Forks
92
Avg merge
1d 1h
Merged PRs (30d)
11

Description

Is your feature request related to a problem? Please describe.
It would be nice to have a utility function in cuCIM Python module so that OpenCV object can be easily converted to CuPy array.

Describe the solution you'd like

Like this(https://github.com/rapidsai/cucim/issues/329#issuecomment-1186088451), provide a utility method/class to handle/exchange OpenCV image data.

class CudaArrayInterface:
    def __init__(self, gpu_mat):
        w, h = gpu_mat.size()
        type_map = {
            cv2.CV_8U: "u1",
            cv2.CV_8UC1: "u1",
            cv2.CV_8UC2: "u1",
            cv2.CV_8UC3: "u1",
            cv2.CV_8UC4: "u1",
            cv2.CV_8S: "i1",
            cv2.CV_16U: "u2", cv2.CV_16S: "i2",
            cv2.CV_32S: "i4",
            cv2.CV_32F: "f4", cv2.CV_64F: "f8",
        }
        self.__cuda_array_interface__ = {
            "version": 3,
            "shape": (h, w, gpu_mat.channels()),
            "typestr": type_map[gpu_mat.type()],
            "descr": [("", type_map[gpu_mat.type()])],
            "stream": 1,
            "strides": (gpu_mat.step, gpu_mat.elemSize(), gpu_mat.elemSize1()),
            "data": (gpu_mat.cudaPtr(), False),
        }

Describe alternatives you've considered

  • Can be implemented at C++ level but providing it at Python level is easy to implement.

Additional context

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.