{"id":1181,"date":"2025-05-31T09:42:49","date_gmt":"2025-05-30T23:42:49","guid":{"rendered":"https:\/\/nickdu.com\/?p=1181"},"modified":"2025-05-31T09:42:55","modified_gmt":"2025-05-30T23:42:55","slug":"real-time-object-detection-and-webcam-live-streaming-on-raspberry-pi","status":"publish","type":"post","link":"https:\/\/nickdu.com\/?p=1181","title":{"rendered":"Real-Time Object Detection and Webcam Live Streaming on Raspberry Pi"},"content":{"rendered":"\n<p>If you&#8217;ve got an old USB webcam lying around and a Raspberry Pi collecting dust, here&#8217;s the perfect weekend project: turn them into a real-time object detection and web livestream system using Python, OpenCV, and the powerful YOLOv8 model!<\/p>\n\n\n\n<p>This project is lightweight, beginner-friendly, and completely open-source. You can find the full code on GitHub here: <a class=\"\" href=\"https:\/\/github.com\/nickdu088\/Webcam-Livestream\">Webcam-Livestream Repository<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What You\u2019ll Need<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Raspberry Pi (any model with a USB port, but Pi 4 is ideal)<\/li>\n\n\n\n<li>A USB webcam<\/li>\n\n\n\n<li>MicroSD card with Raspberry Pi OS<\/li>\n\n\n\n<li>Basic knowledge of Python<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What This Project Does<\/h2>\n\n\n\n<p>This project allows you to:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Capture video from a USB webcam<\/strong> in real-time.<\/li>\n\n\n\n<li><strong>Detect objects in the video feed<\/strong> using YOLOv8 (a fast, accurate deep learning model).<\/li>\n\n\n\n<li><strong>Serve the processed video stream<\/strong> to a browser using a lightweight web server.<\/li>\n\n\n\n<li>View it all live from your local network!<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">What This Project Does<\/h2>\n\n\n\n<p>This project allows you to:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Capture video from a USB webcam<\/strong> in real-time.<\/li>\n\n\n\n<li><strong>Detect objects in the video feed<\/strong> using YOLOv8 (a fast, accurate deep learning model).<\/li>\n\n\n\n<li><strong>Serve the processed video stream<\/strong> to a browser using a lightweight web server.<\/li>\n\n\n\n<li>View it all live from your local network!<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Under the Hood<\/h2>\n\n\n\n<p>Here\u2019s how it works:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Real-Time Video with OpenCV<\/h3>\n\n\n\n<p>OpenCV grabs frames from your USB webcam and sends them for processing.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cap = cv2.VideoCapture(0)\nret, frame = cap.read()<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. YOLOv8 for Object Detection<\/h3>\n\n\n\n<p>I&#8217;m using the <strong>Ultralytics YOLOv8n<\/strong> model\u2014it&#8217;s compact and fast enough for Raspberry Pi:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from ultralytics import YOLO\nmodel = YOLO(\"yolov8n.pt\")\nresults = model(frame)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. Annotate and Stream<\/h3>\n\n\n\n<p>Bounding boxes are drawn on the frame, and the output is streamed using Python&#8217;s <code>aiohttp<\/code> server.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cv2.rectangle(...)\nweb.Response(body=jpeg_frame, content_type=\"image\/jpeg\")<\/code><\/pre>\n\n\n\n<p>For full detailed project: <a href=\"https:\/\/github.com\/nickdu088\/Webcam-Livestream\">https:\/\/github.com\/nickdu088\/Webcam-Livestream<\/a><\/p>\n\n\n\n<p>If you build something with it, let me know or contribute to the repo!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve got an old USB webcam lying around and a Raspberry Pi collecting dust, here&#8217;s the perfect weekend project: turn them into a real-time object detection and web livestream system using Python, OpenCV, and the powerful YOLOv8 model! This project is lightweight, beginner-friendly, and completely open-source. You can find the full code on GitHub &hellip; <a href=\"https:\/\/nickdu.com\/?p=1181\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Real-Time Object Detection and Webcam Live Streaming on Raspberry Pi&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,8],"tags":[],"class_list":["post-1181","post","type-post","status-publish","format-standard","hentry","category-it","category-web"],"_links":{"self":[{"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/posts\/1181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nickdu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1181"}],"version-history":[{"count":1,"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/posts\/1181\/revisions"}],"predecessor-version":[{"id":1182,"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/posts\/1181\/revisions\/1182"}],"wp:attachment":[{"href":"https:\/\/nickdu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nickdu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nickdu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}