Open gordinmitya opened 4 years ago
Same issue.
Looking for ImageAnalyzer's ImageProxy.image to RGB conversion solution. Spent some days on this, still nothing..
@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()
}
}
but implementation in this repo is not correct, look at #5
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.