import cv2 from ultralytics import YOLO
আপনার কাস্টম মডেল লোড করুন
model = YOLO(’/media/Data/rasppi/Archive/best.pt’) # আপনার best.pt এর পাথ দিন
ক্যামেরা খুলুন (যে ইনডেক্স কাজ করছে)
cap = cv2.VideoCapture(2) # আপনার কাজ করা ইনডেক্স
if not cap.isOpened(): print(“Cannot open camera”) exit()
print("✅ ক্যামেরা খোলা হয়েছে! ‘q’ চাপলে বন্ধ হবে।")
while True: # ফ্রেম পড়ুন ret, frame = cap.read()
# যদি ফ্রেম সঠিকভাবে পড়া হয়
if ret:
# YOLO ডিটেকশন চালান
results = model(frame)
# ডিটেকশন সহ ফ্রেম আঁকুন
annotated_frame = results[0].plot()
# ফলাফল দেখান
cv2.imshow('HDTV Camera + YOLO Detection', annotated_frame)
# 'q' চাপলে বেরিয়ে যান
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
print("Can't receive frame. Exiting ...")
break
ক্লিনআপ
cap.release() cv2.destroyAllWindows() print("✅ ক্যামেরা বন্ধ করা হয়েছে!")