<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Christian Zigah</title>
    <description>The latest articles on DEV Community by Christian Zigah (@christian_zigah_ee4fcbe3c).</description>
    <link>https://dev.to/christian_zigah_ee4fcbe3c</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3322128%2F4ae91995-e9a4-4060-9e3e-cd6baf6edb58.jpg</url>
      <title>DEV Community: Christian Zigah</title>
      <link>https://dev.to/christian_zigah_ee4fcbe3c</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/christian_zigah_ee4fcbe3c"/>
    <language>en</language>
    <item>
      <title>🚗 Python Yolov8 - Advanced Vehicle Counter</title>
      <dc:creator>Christian Zigah</dc:creator>
      <pubDate>Fri, 04 Jul 2025 10:44:31 +0000</pubDate>
      <link>https://dev.to/christian_zigah_ee4fcbe3c/advanced-vehicle-counter-47om</link>
      <guid>https://dev.to/christian_zigah_ee4fcbe3c/advanced-vehicle-counter-47om</guid>
      <description>&lt;p&gt;A Python-based advanced vehicle counting system using YOLOv8 and OpenCV. Tracks and counts vehicles crossing a virtual line, records output video, and logs detailed count statistics for each class in both directions.&lt;/p&gt;

&lt;p&gt;[🎥 Watch Advance Car Counter - Output Recording on YouTube]&lt;br&gt;
  &lt;iframe src="https://www.youtube.com/embed/ha5XGrtyo9c"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;




&lt;p&gt;&lt;a href="https://youtu.be/ha5XGrtyo9c" rel="noopener noreferrer"&gt;https://youtu.be/ha5XGrtyo9c&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  ✨ Features
&lt;/h2&gt;

&lt;p&gt;✅ YOLO-based object detection&lt;br&gt;&lt;br&gt;
✅ Class-specific counting: cars, trucks, buses, motorcycles&lt;br&gt;&lt;br&gt;
✅ Two-way counting: UP and DOWN directions&lt;br&gt;&lt;br&gt;
✅ Tracks individual vehicles by ID (without displaying ID on screen)&lt;br&gt;&lt;br&gt;
✅ Overlays detection boxes with class &amp;amp; confidence&lt;br&gt;&lt;br&gt;
✅ Video recording of processed output&lt;br&gt;&lt;br&gt;
✅ Detailed text logging with timestamps&lt;br&gt;&lt;br&gt;
✅ Real-time counting statistics panel&lt;br&gt;&lt;br&gt;
✅ Visual indicator for each crossing event&lt;br&gt;&lt;br&gt;
✅ Saves final summary report&lt;/p&gt;


&lt;h2&gt;
  
  
  🚀 Quick Start
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Install dependencies&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;opencv-python ultralytics numpy
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Download a YOLOv8 model&lt;/strong&gt; (if you don't already have one):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The default uses &lt;code&gt;yolov8n.pt&lt;/code&gt;, available from &lt;a href="https://github.com/ultralytics/ultralytics" rel="noopener noreferrer"&gt;Ultralytics YOLOv8 models&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Run the counter&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;python main.py
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;By default, it processes &lt;code&gt;traffic.mp4&lt;/code&gt;, drawing a counting line at 70% height.&lt;/p&gt;


&lt;/li&gt;

&lt;/ol&gt;




&lt;h2&gt;
  
  
  🛠️ Usage
&lt;/h2&gt;

&lt;p&gt;Create an instance of &lt;code&gt;AdvancedVehicleCounter&lt;/code&gt; with your desired parameters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;your_module&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AdvancedVehicleCounter&lt;/span&gt;

&lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AdvancedVehicleCounter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;yolov8n.pt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;             &lt;span class="c1"&gt;# Path to your YOLOv8 model
&lt;/span&gt;    &lt;span class="n"&gt;video_source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;traffic.mp4&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;          &lt;span class="c1"&gt;# Path to your input video
&lt;/span&gt;    &lt;span class="n"&gt;line_position&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                   &lt;span class="c1"&gt;# Vertical position of the counting line (0-1 scale)
&lt;/span&gt;    &lt;span class="n"&gt;output_folder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;monitoring_results&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;   &lt;span class="c1"&gt;# Folder to save logs and processed video
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  📂 Outputs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Processed Video&lt;/strong&gt;: Saved in the output folder with a timestamped filename (e.g., output_20250630_123456.mp4).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;python-replCopyEditTimestamp,Class,Direction,TotalCount2025-06-30 12:34:56.789,car,DOWN,1...&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;python-replCopyEditFINAL SUMMARYClass,DOWN,UP,TOTALcar,10,8,18motorcycle,3,2,5...&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  📈 How It Works
&lt;/h2&gt;

&lt;p&gt;🔹 &lt;strong&gt;Detection&lt;/strong&gt;Uses YOLOv8 to detect vehicles in each frame.&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;Tracking&lt;/strong&gt;Maintains a per-object path using YOLO’s tracker, enabling detection of line crossings.&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;Counting&lt;/strong&gt;When a vehicle crosses the counting line:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;UP&lt;/strong&gt;: moves from below the line to above.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DOWN&lt;/strong&gt;: moves from above the line to below.Counts are updated for the specific class.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔹 &lt;strong&gt;Visualization&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Draws bounding boxes with class name and confidence.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Highlights vehicles that crossed the line.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Displays a real-time panel with UP/DOWN counts for each class.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔹 &lt;strong&gt;Output&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Saves an annotated video to the output folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Logs every crossing event with timestamp, class, direction, and total count.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Appends a final summary at the end.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  ⚙️ Configuration Options
&lt;/h2&gt;

&lt;p&gt;ParameterDescriptionDefaultmodel_pathYOLOv8 model weights file path"yolov8n.pt"video_sourceInput video file path"video2.mp4"line_positionVertical position of counting line (0-1 scale)0.5line_thicknessThickness of counting line in pixels2output_folderDirectory to save video and logs"output"&lt;/p&gt;

&lt;h2&gt;
  
  
  📌 Notes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Requires a GPU or fast CPU for real-time performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tested with YOLOv8 and OpenCV 4.x.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports Linux, macOS, and Windows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Press &lt;strong&gt;Q&lt;/strong&gt; to exit the application early.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  📸 Example
&lt;/h2&gt;

&lt;p&gt;Once running, you will see:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Green detection boxes labeled with class &amp;amp; confidence.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A horizontal counting line at the configured position.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Visual indicators when a crossing happens (colored circles + text).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A panel showing real-time UP/DOWN counts per class.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/zigahchristian/Python_Advance_Car_Counter" rel="noopener noreferrer"&gt;Python Advance Car Counter on GitHub -  Give me Stars&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>yolov8</category>
      <category>ai</category>
      <category>machinelearning</category>
    </item>
  </channel>
</rss>
