How to Detect, Track, and Count Cars in a Video Using Maximo Visual Inspection

May 30, 2022 | Data Science

Have you ever wondered how traffic cameras count cars or how self-driving cars recognize vehicles around them? The secret lies in computer vision technologies! In this guide, we’ll explore how to create a car counting system in a video using Maximo Visual Inspection (formerly known as PowerAI Vision) along with OpenCV and Jupyter Notebook. Whether you’re counting cars on a busy highway or products on a conveyor belt, this method can be applied to various scenarios.

Getting Started: A Bird’s Eye View of the Code Pattern

Picture this: You are a chef in a bustling kitchen. Your job is to prepare a feast (detecting cars) using different ingredients (video frames) and your trusty recipe book (Jupyter Notebook). You’ll follow various steps in the kitchen to assemble your final dish (annotated video). Here’s how the process unfolds:

  • Upload a Video: Start by adding your raw video to the Maximo Visual Inspection tool.
  • Automatic Labeling: Use automatic labeling to kickstart the classification of vehicles within your video frames.
  • Train the Model: With the labeled data ready, you’ll train your model to recognize cars.
  • Run the Notebook: After deploying your model, you will use a Jupyter Notebook to track and count the cars.
  • Create Annotated Video: Finally, output your processed frames into an annotated video.

Required Tools

Before diving in, ensure you have the following tools at your disposal:

Step-by-Step Instructions

1. Create a Dataset in Maximo Visual Inspection

Start your journey by creating a dataset that the tool will use to train the car classifier. Here’s how:

  • Download your training video from here.
  • Open the Maximo Visual Inspection UI and click on the Data Sets tab.
  • Click Create new data set and name your dataset.
  • Upload the training_video.mp4 file by clicking on Import files.
  • Label the objects manually to get started. For instance, frame by frame, draw boxes around each car you see.

2. Train and Deploy the Model

Once your dataset is ready, it’s time to train:

  • Go back to the dataset page and click Train model.
  • Ensure you select Object detection and begin training.
  • Deploy the model and find the API endpoint to use later in your Jupyter Notebook.

3. Automatic Labeling

With the model trained, the next step is automatic labeling:

  • Select your video card and click on Label objects.
  • Set a capture interval of 1 second and initiate Auto label.

4. Running the Notebook

Configure and run your Jupyter Notebook:

  • Start Jupyter Notebook from your cloned directory.
  • Open the counting_cars.ipynb file and update the API URL in the required setup section.
  • Run all cells or execute them step-by-step to observe the results. Watch for classified JSON output indicating successful detection.

5. Create the Annotated Video

Now, it’s time to turn those frames into videos:

  • Use FFmpeg to compile your frames into an MP4 video.
  • Experiment with video processing tools to create GIFs if desired.

Sample Output

Watch your annotated video in action! You can check example outputs and see the results of your hard work. Feel free to visualize your progress within the notebook playback.

Annotated video output

Troubleshooting Tips

Sometimes your journey may encounter bumps in the road. Here are a few troubleshooting ideas:

  • If you notice your model stops adding cars, check if you’re in a trial environment. You may need to deploy the model again after an hour.
  • Ensure the API endpoint is correctly copied in the Jupyter Notebook for successful inference.
  • If errors arise during labeling, revisit the labeling steps in the Maximo Visual Inspection UI.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

Congratulations! You have now created a functional video car counter using advanced computer vision tools. The blending of Maximo Visual Inspection, OpenCV, and Jupyter Notebook not only simplifies the task but also enhances your understanding of object detection. At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox