Question: Using Thonny Application within Raspberry pi 4 6 4 - bit Bullseye system. Picamera 2 seems to be the lastest module in order to use

Using Thonny Application within Raspberry pi 464-bit Bullseye system. Picamera2 seems to be the lastest module in order to use a raspberry pi camera. I am working on a YOLOv5 object detection test witht the use of a raspberry pi camera. This code works well with a webcam before I change the code a bit. Can you please help me make this code to detect with the use of a raspberry pi camera. My only problem is that I am having a hard time make the raspberry pi camara to work with object detection. Thank you so much.
import tkinter as tk
import torch
from picamera2 import Picamera2
import cv2
import numpy as np
from PIL import Image, ImageTk
app = tk.Tk()
app.geometry("700x600")
app.title("ObjectTest")
label1= tk.Label(app, text='detectionTest', font=("Arial",24))
label1.pack(side='top', pady=20)
vidFrame = tk.Frame(height=600, width=600)
vidFrame.pack()
vid = tk.Label(vidFrame, text="")
vid.pack()
picam2= Picamera2()
camera = picam2
def detect():
frame = np.empty((240,320,3), dtype=np.uint8)
camera.capture(frame,'bgr', use_video_port=True)
results = model(frame)
output_image = results.render()
display_image = Image.fromarray(output_image)
imgtk = ImageTk.PhotoImage(image=display_image)
vid.imgtk = imgtk
vid.configure(image=imgtk)
vid.after(10, detect)
detect()
app.mainloop()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!