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

Portrait Mode (WIP) #18

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft

Portrait Mode (WIP) #18

wants to merge 30 commits into from

Conversation

IzaakBH
Copy link
Collaborator

@IzaakBH IzaakBH commented Jan 12, 2025

Portrait mode with MediaPipe.

473440098_3921037358214522_8119052170283345346_n

472567077_1662751194594328_6371246227974615024_n

}
}

fun Bitmap.saveImage(context: Context): Uri? {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long term will just overwrite the saved image, but for now i wanna compare


class ImageSegmenterHelper(
var currentDelegate: Int = DELEGATE_CPU,
var runningMode: RunningMode = RunningMode.IMAGE,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can set it to process on a live stream instead of images. I wonder if this will be preferable, performance wise, for the live view & how that would tie into the current plugin model?

@ISNIT0 ISNIT0 mentioned this pull request Jan 13, 2025
@ISNIT0 ISNIT0 marked this pull request as draft January 13, 2025 08:43
- Old approach blurred the whole image & then applied the mask which is significantly more computationally expensive
- Also fixing some lint errors
@IzaakBH
Copy link
Collaborator Author

IzaakBH commented Jan 13, 2025

Newly optimised blurring algo takes roughly 700ms on pixel 6a with a large radius of 25 (not including segmentation). Defo further optimisations to be had.

Will focus next on shoving it on a background thread & improving the smoothness of the blur

@IzaakBH
Copy link
Collaborator Author

IzaakBH commented Jan 13, 2025

Newly optimised blurring algo takes roughly 700ms on pixel 6a with a large radius of 25 (not including segmentation). Defo further optimisations to be had.

Will focus next on shoving it on a background thread & improving the smoothness of the blur

Also not 100% happy with the visuals of the blur, but can polish this later after getting the images to save in the correct orientation :D

stoneCameraViewModel: StoneCameraViewModel,
outputFileResults: ImageCapture.OutputFileResults
) {
val portraitModeSetting = stoneCameraViewModel.getSetting<String>("portraitMode") ?: "OFF"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should do this on a "mode" basis?

E.g. extend the Photo Mode plugin? Then there will be a mode option like most other camera apps?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think this would be a good idea. Will make that change

private fun getOriginalImageRotation(contentResolver: ContentResolver, imageUri: Uri): Int {
val exifInputStream = contentResolver.openInputStream(imageUri)
val exif = ExifInterface(exifInputStream!!)
val rotation = when (exif.getAttributeInt(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be more global for all modes? Perhaps I'm mis-understanding

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image was being spat out sideways after blurring for some reason. No objection to making it more global

)
}

// Stolen from https://stackoverflow.com/questions/21418892/understanding-super-fast-blur-algorithm?fbclid=IwZXh0bgNhZW0CMTEAAR1w91ucNtw4nU-Z8Z9RyMYFVUHWxfgt7ivsE7foTkwR2wmdx2losQqQ0sk_aem_Zrf_8344PRxW6SFzutkE7g
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Borrowed from" 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, isn't there a way we can shift this onto a shader?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not aware of shaders. will take a look

import com.google.mediapipe.tasks.vision.imagesegmenter.ImageSegmenterResult

class ImageSegmenterHelper(
var currentDelegate: Int = DELEGATE_CPU,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make sure we use GPU where possible?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having trouble w/ gpu but yes, I agree. Will work on making that happen

}
}

when(currentModel) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all the models included in the build at this stage? How do we strip out the ones we're not using?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not, have made changes to remove references to other models

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

Successfully merging this pull request may close these issues.

2 participants