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

CameraX support #4

Open
gordinmitya opened this issue Apr 2, 2020 · 3 comments
Open

CameraX support #4

gordinmitya opened this issue Apr 2, 2020 · 3 comments

Comments

@gordinmitya
Copy link

CameraX api has ImageProxy class which you obtain from ImageAnalyzer. It has the same api as usual Image. So adding support is just duplicating several constructors. And I would create pull request, but…
The difficult part, I think, this feature should be in separate package. If someone don't use CameraX in his/her project won't have to download it.

@AlexanderMatveev
Copy link

Same issue.

Looking for ImageAnalyzer's ImageProxy.image to RGB conversion solution. Spent some days on this, still nothing..

@gordinmitya
Copy link
Author

@AlexanderMatveev

just add two extra constructors

data class Yuv(
    val resource: AutoCloseable? = null,
    val width: Int,
    val height: Int,
    val y: Plane,
    val u: Plane,
    val v: Plane) : YuvPlanes, AutoCloseable {

    constructor(image: Image) : this(
        resource = image,
        width = image.width,
        height = image.height,
        y = Plane(image.planes[0]),
        u = Plane(image.planes[1]),
        v = Plane(image.planes[2])) {
        require(image.format == ImageFormat.YUV_420_888)
        require(image.width % 2 == 0)
        require(image.height % 2 == 0)
    }

    // here
    constructor(image: ImageProxy) : this(
        resource = image,
        width = image.width,
        height = image.height,
        y = Plane(image.planes[0]),
        u = Plane(image.planes[1]),
        v = Plane(image.planes[2])) {
        require(image.format == ImageFormat.YUV_420_888)
        require(image.width % 2 == 0)
        require(image.height % 2 == 0)
    }

    data class Plane(
        val buffer: ByteBuffer,
        val pixelStride: Int,
        val rowStride: Int) {

        constructor(plane: Image.Plane) : this(
            buffer = plane.buffer,
            pixelStride = plane.pixelStride,
            rowStride = plane.rowStride)

         // and here
        constructor(plane: ImageProxy.PlaneProxy) : this(
            buffer = plane.buffer,
            pixelStride = plane.pixelStride,
            rowStride = plane.rowStride)
    }


    override fun close() {
        resource?.close()
    }

    val rows = this.height
    val cols = this.width


    /**
     * For java API call site
     */
    companion object {
        @JvmStatic
        fun rgb(image: Image) = image.rgb()

        @JvmStatic
        fun rgb(image: ImageProxy) = image.rgb()
    }
}

@gordinmitya
Copy link
Author

but implementation in this repo is not correct, look at #5

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

2 participants