Question: I am currently running Raspberry pi 6 4 - bit OS ( bookworm ) . I am currently doing an object detection project using YOLOv
I am currently running Raspberry pi bit OS bookworm I am currently doing an object detection project using YOLOv in Pycharms using python. This code works well when I connect webcam to raspberry pi but it seems it does not work with raspberry pi camera. Please make this code below that can connect to my raspberry pi camera for object detection. Please take note that the old picamera module does not work anymore with the latest OS of raspberry pi As far as I am aware, it seems picamera or libcamera works fine.
The code so far:
import tkinter as tk
import torch
import picamera
import cv
import numpy as np
from PIL import Image, ImageTk
model torch.hub.loadultralyticsyolov 'custom', path'yolovbestpt forcereloadTrue
model.conf
app tkTk
app.geometryx
app.titleObjectTest
label tkLabelapp text'detectionTest', fontArial
labelpackside'top', pady
vidFrame tkFrameheight width
vidFrame.pack
vid tkLabelvidFrame text
vid.pack
camera picameraPiCamera
def detect:
frame npempty dtypenpuint
camera.captureframebgr usevideoportTrue
results modelframe
outputimage results.render
displayimage Image.fromarrayoutputimage
imgtk ImageTk.PhotoImageimagedisplayimage
vid.imgtk imgtk
vid.configureimageimgtk
vid.after detect
detect
app.mainloop
I will appreciate explanations for the code that you will add and please also let me know if you installed any other packages. Thank you so much
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
