Skip to content

InputImage.fromMediaImage ignores cropRect #234

Closed
@ivan200

Description

@ivan200

I'm trying to use simplest qr scanning image analyzer.
And I am trying to scan not the entire area of the screen, but only the center bounded by the frame.
In this example, I set the crop rect for MediaImage, which will be converted to the InputImage and then passed to the scanner.
but scanner still scan entire area

override fun analyze(imageProxy: ImageProxy) {
    val mediaImage = imageProxy.image
    if (mediaImage != null) {
        val cropSize = (min(mediaImage.width, mediaImage.height) * 0.6f).toInt()
        val cropRect = Rect(mediaImage.width / 2 - cropSize / 2, mediaImage.height / 2 - cropSize / 2,
            mediaImage.width / 2 + cropSize / 2, mediaImage.height / 2 + cropSize / 2)

        //here i set crop rect
        mediaImage.cropRect = cropRect
        val image = InputImage.fromMediaImage(mediaImage, imageProxy.imageInfo.rotationDegrees)

        //but here scanner wil process whole image instead of small area
        pendingTask = scanner.process(image)
            .addOnSuccessListener { barcodes ->
                //do something
            }
            .addOnCompleteListener {
                imageProxy.close()
            }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions