Git Product home page Git Product logo

Comments (6)

PaulTR avatar PaulTR commented on July 30, 2024

Hey, this isn't being ignored - I've been talking to eng to figure out what's going on to normalize the probability (getting [0,1] instead of the positive/negative large numbers). Waiting for someone to get back next week to dig deeper into the issue.

Thanks!

from mediapipe-samples.

tryanbot avatar tryanbot commented on July 30, 2024

Splendid!... waiting for the answer soon :)

from mediapipe-samples.

PaulTR avatar PaulTR commented on July 30, 2024

So this API is going to change a little bit for the next preview release (nothing significant, but we'll have an updated sample when it's ready), but if you're just trying to make confidence masks work for 0.1.0-alpha-6, this is what I did to make it work:

Helper:

in setupImageSegmenter() - same thing you did
.setOutputType(ImageSegmenter.ImageSegmenterOptions.OutputType.CONFIDENCE_MASK)

I changed the ResultBundle to accept a FloatBuffer

My returnSegmentationResult(...) function looks like:

        val mpImage = result.segmentations().first()

        imageSegmenterListener?.onResults(
            ResultBundle(
                ByteBufferExtractor.extract(mpImage).asFloatBuffer(),
                mpImage.width,
                mpImage.height,
                inferenceTime
            )
        )

I commented a lot of stuff out (label colors, the adapter) to just make it work in a not-the-most-pretty way

In the OverlayView I changed setResults to the following (again, some artifacts from the existing sample - I didn't exactly clean anything up):

    fun setResults(
        byteBuffer: FloatBuffer,
        outputWidth: Int,
        outputHeight: Int
    ) {
        val colorLabel = HashSet<Pair<String, Int>>()
        // Create the mask bitmap with colors and the set of detected labels.
        val pixels = IntArray(byteBuffer.capacity())
        for (i in pixels.indices) {
            val confidence = byteBuffer.get()

            val color =
                Color.argb(255 * if( (1.0f - confidence) >= 0.5f ) 0.0f else { confidence }, 0.0f, 0.0f, 128.0f)
            pixels[i] = color
        }
        val image = Bitmap.createBitmap(
            pixels,
            outputWidth,
            outputHeight,
            Bitmap.Config.ARGB_8888
        )

        val scaleFactor = when (runningMode) {
            RunningMode.IMAGE,
            RunningMode.VIDEO -> {
                min(width * 1f / outputWidth, height * 1f / outputHeight)
            }
            RunningMode.LIVE_STREAM -> {
                // PreviewView is in FILL_START mode. So we need to scale up the
                // landmarks to match with the size that the captured images will be
                // displayed.
                max(width * 1f / outputWidth, height * 1f / outputHeight)
            }
        }

        val scaleWidth = (outputWidth * scaleFactor).toInt()
        val scaleHeight = (outputHeight * scaleFactor).toInt()

        scaleBitmap = Bitmap.createScaledBitmap(
            image, scaleWidth, scaleHeight, false
        )
        invalidate()
        listener?.onLabels(colorLabel.toList())
    }

There's probably a few steps in there I missed (GalleryFragment had to change a placeholder resultsbundle, for example), but that should give you the general idea that led me to this:

https://photos.app.goo.gl/8g2Ea549NMhsbt7k7

from mediapipe-samples.

PaulTR avatar PaulTR commented on July 30, 2024

Hey, going to close this out since it's been a few days. Let me know if you have other questions though! :)

from mediapipe-samples.

tryanbot avatar tryanbot commented on July 30, 2024

havent try the solution you offer, will respond once I tried it

from mediapipe-samples.

tryanbot avatar tryanbot commented on July 30, 2024

Splendid!, it works, thanks

from mediapipe-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.