How to add Picamera2 module in a venv and use it with Opencv in a Pi5

April 10, 2024, 16:27

19440harry

I have a raspberry Pi5 which I have struggled a fair bith with. The system python is 3.11.2 but I want to use 3.9.13 for some basic tf, opencv projects. Simple CNN stuff The issue is managing Picamera2 module in a venv Yesterday I pip installed it in my venv by following this tutorial: https://forums.raspberrypi.com/viewtopic.php?t=361758#:~:text=This%20will%20create%20a%20virtual,existing%20ones%20with%20different%20versions. however there were other issues like PyQt5 not being detected. I tried to build the modules manually with the help of GPT and Gemini. I ended up copying the file from the global python as I couldn't manually build it successfully Now i am able to open the picamera stream using this code: from picamera2 import Picamera2, Preview import time picam2 = Picamera2() picam2.start_preview(Preview.QT) # Use Preview.QT instead of Preview.QTGL preview_config = picam2.create_preview_configuration() picam2.configure(preview_config) picam2.start() time.sleep(5) Preview.Qt is the only way i can open it. I would like to access the data with opencv and would like to see what I can do. Unfortunately Opencv for some reason wont work with Picamera2 Any help would be appreiciated. Even if I have to start from scratch with a new venv I wouldnt mind as long as the method works