Member-only story

OpenCV on Oracle Linux — Recognize cars

Johan Louwers
2 min readJun 12, 2023

--

Toy Cars

In a recent article I described how we can deploy OpenCV on Oracle Linux 9 for Vision AI. In this post we quickly show how we can make use of it with a first example.

In this example, we have a very simple script that will take an image and detect if there is a car in the image. As stated, this is a first step in a series where we will build more and more complex things with OpenCV.

Detecting Cars on the HighWay

The below script takes nothing additional than the installed Python parts from the previous blogpost. This is, with the exception of the haar cascade XML file which will hold the data needed to recognize a car. This can be easily obtained from the OpenCV website and the OpenCV Github page.

import cv2
import sys

def detect_car(image_path):
# Load the Haar Cascade classifier for car detection
cascade_path = "/vagrant/haarcascade_car.xml" # Provide the full path to the classifier file
car_cascade = cv2.CascadeClassifier(cascade_path)

# Read the image file
image = cv2.imread(image_path)

# Convert the image to grayscale for better performance
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Detect cars in the image
cars =…

--

--

Johan Louwers
Johan Louwers

Written by Johan Louwers

Johan Louwers is a technology enthousiasts with a long background in supporting enterprises and startups alike as CTO, Chief Enterprise Architect and developer.

No responses yet