onseok / peekaboo

🌄 Kotlin Multiplatform library for Compose Multiplatform, designed for seamless integration of an image picker feature in iOS and Android applications.
Apache License 2.0
211 stars 19 forks source link

Add preview processing capability and crop preview #77

Closed deividasstr closed 5 months ago

deividasstr commented 6 months ago

Hey,

I am working on a KMP compose app where I need a barcode scanner.

For camera preview, I could use this lib. But I need to be able to:

I guess a simpler way would be to expose another callback onFrame, similar to onCapture. Just not sure about a performance. Or some sort of stream of ByteArray (coroutines Flow '<ByteArray'> ?).

2 questions:

Thanks in advance 🙇

l2hyunwoo commented 5 months ago

Hello @deividasstr thanks for good suggestion! 👍🏻

I think it should be needed @onseok's opinion, but I'll answer in terms of mine. Also since I'm Android developer, I can't give you advices of implementation in iOS env.

In this case, Rect(struct that represents area you want to crop) parameter should be passed and onFrame(type that I think is (ImageIntermediateResult(wrapping ImageProxy of camerax)) -> Unit is proper) also should be passed i think.

But this way is too android-istic way so I want to suggest get feedbacks to you or @onseok.

Thanks for suggest good feature one more time 😄

onseok commented 5 months ago

would you accept such contribution?

Hi @deividasstr, your contribution to this library regarding barcode scanning feature would be highly welcome!


any suggestions/pointers on the topic?

In addition to the onFrame callback approach suggested by @l2hyunwoo for enhancing the Android module, I think for Android, leveraging the CameraX is a robust way to implement real-time frame processing for barcode scanning. The use of ImageAnalysis with a custom analyzer allows for processing each frame from the camera feed. This analyzer can be designed to crop the frame if necessary before or during the detection process, depending on the requirements of the barcode scanning algorithm. Implementing this feature within our library, it would be highly beneficial to explore the use of Kotlin's coroutines and Flow for streaming ByteArray data from each frame.

On the iOS side, using AVFoundation to implement a similar feature involves setting up a camera capture session with a AVCaptureVideoDataOutput to process frames in real time. Similar to the Android approach, you would analyze each frame for barcodes. The AVCaptureMetadataOutput class can be particularly useful for barcode detection, as it's designed to process video frames and detect various types of metadata, including QR codes and barcodes.