-
Notifications
You must be signed in to change notification settings - Fork 201
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
[HOW-TO] Using PiCamera 2 with Flutter Without Flask/Web Server #1193
Comments
Hi, I'm afraid I know nothing at all about Flutter, so I probably can't help. However, it sounds like you're running the Picamera2 Python script in a separate process from your Flutter application, is that correct?
|
Hi, thanks for your response! Yes, I am running the Picamera2 Python script as a separate process from my Flutter app. I don’t want to open a built-in GUI window for the preview. Instead, I want to continuously receive frames or a video stream from Picamera2 so that I can display the preview inside my Flutter app wherever I want. I’m looking for a way to get the frames without using the default preview window, and I’d prefer to receive them efficiently (e.g., via a socket, shared memory, or another optimized method). If you have any suggestions or examples, especially for zero-copy buffer passing between Python processes, that would be really helpful. Thanks! |
Picamera2 won't try to open a preview window unless you ask for one, so I don't foresee any problems there. I think the most efficient way to get images across will be the zero-copy technique using file descriptors. You'll probably need a couple of fifos. The first will be for sending file descriptors across (you'll have to "acquire" the completed requests on the Python side to stop them being recycled to the camera), perhaps along with some image format information. The other fifo will be for a receiving thread on the Python side that gets notified by the Flutter app that you're finished with the image, and it can then "release" the request back to the camera. All this happens in the Process class in that example. Though there, of course, it's Python to Python, which maybe makes some things easier, but it should give you some hints. There are certainly other ways to do this. If your images aren't too big and you have a fast Pi (a Pi 5 definitely qualifies!) then simply copying the pixel data into a fifo/socket would be an option. Although less efficient, it would be much easier to get up and running. You could always start like that, and see if the performance is OK. |
I am running Flutter on a Raspberry Pi 5 and trying to use PiCamera 2 (Python) to capture images and display a live preview in my Flutter app. I am currently using subprocess in Dart to run a Python script, but I haven’t been able to get the preview working.
Questions
Device: Raspberry Pi 5
OS: Raspberry Pi OS Desktop
As I am new to PiCamera 2, I would appreciate any guidance on how to get the preview working in Flutter. Any suggestions or example implementations would be very helpful! 🚀
The text was updated successfully, but these errors were encountered: