Introduction: traffic accidents cause more than one million deaths per year worldwide and many injuries. Early detection of crashes can drastically reduce emergency services response times, save lives, and minimize damage.
In this article, I explain in detail how to build an accident detection system powered by artificial intelligence using Java for preprocessing, cloud integration, and prediction calls, and Google Cloud Vertex AI to train and deploy a custom object detection model.
This project is not just a technical exercise; it also has real social impact and aligns with public safety goals, AI research, and technological development applicable to companies and government agencies.
Architecture and general flow: video capture from dashcams, frame extraction with OpenCV in Java, annotation and coordinate conversion, upload to cloud storage, import to Vertex AI, object detection model training, deployment to an endpoint, and consumption of predictions from a Java application in production.
Key technologies used: Java for preprocessing utilities and production client, OpenCV Java API for frame extraction, makesense.ai for manual labeling with bounding boxes, Google Cloud Storage for storing images and annotated CSV, Vertex AI AutoML to train and evaluate the model, and PredictionServiceClient to integrate predictions in Java.
Dataset preparation: public and openly licensed dashcam videos were collected. Each video was processed using a Java utility that iterates through frames with OpenCV and saves each frame as a JPG image, generating hundreds of images per video to be used in training.
Image annotation: the extracted images were annotated in makesense.ai, creating two main labels: accident for scenes with accidents and normal for scenes without accidents. Annotations include bounding boxes and are initially exported in pixel format with x, y, width, height.
Annotation conversion: Vertex AI requires normalized coordinates between 0 and 1. A Java converter was developed that reads the CSV exported by makesense.ai and calculates normalized xmin, ymin, xmax, ymax using the formulas xmin equals x divided by imageWidth, ymin equals y divided by imageHeight, xmax equals x plus width divided by imageWidth, and ymax equals y plus height divided by imageHeight. The result is a CSV compatible with Vertex AI AutoML.
Cloud upload: the images and normalized CSV were organized in a Google Cloud Storage bucket with images and annotations folders. A GCS utility in Java was implemented to upload files in bulk using Google Cloud client libraries. Before uploading, a service account with appropriate permissions was created.
Import to Vertex AI: from the Google Cloud console, an image dataset was created, and data was imported by pointing to the annotated CSV in GCS. Vertex AI automatically linked each image with its annotations and allowed visual verification that boxes and labels matched the expected scenes.
Model training: a custom object detection model was trained in Vertex AI by selecting the imported dataset and setting a training budget in node hours according to the dataset size. Upon completion, evaluation metrics such as precision and recall were obtained, allowing validation of the model's behavior.
Deployment: the trained model was deployed to a Vertex AI endpoint, configuring resources for real-time prediction. Tests were performed from the console with test images to verify that the endpoint returned bounding boxes, labels, and confidence scores in real time.
Java integration: in the application layer, PredictionServiceClient was used to send images in bytes to the endpoint and parse the response. The application logic extracts box coordinates, detected labels, and confidence scores to make decisions: trigger alerts, store events, or feed reporting systems.
Results: the model demonstrated good capability to detect frames with accidents and generate bounding boxes consistent with impact zones. Output examples showed detections with high confidence levels and a low false positive rate in controlled test scenarios.
Social impact and alignment with national priorities: solutions like this enable faster emergency response, improve traffic monitoring in smart cities, and provide evidence for forensic analysis of crashes. Furthermore, projects combining AI and public safety contribute to innovation prioritized by initiatives seeking national benefits.
Future improvements: real-time streaming integration from dashcams, expansion and diversification of the dataset for greater robustness, incorporation of automated pipelines with Pub/Sub for real-time alerts, and deployment on edge devices for in-vehicle detection.
About Q2BSTUDIO: Q2BSTUDIO is a software development company specialized in custom applications and custom software. We are experts in artificial intelligence, cybersecurity, and AWS and Azure cloud services. We offer business intelligence services, AI solutions for companies, AI agent development, and Power BI dashboards to support decision-making. Our team designs custom solutions that combine security, scalability, and performance for clients across various sectors.
How Q2BSTUDIO can help in similar projects: from data pipeline integration and cloud services to AI model development and production deployment, Q2BSTUDIO supports the entire lifecycle. We implement cybersecurity practices, business intelligence solutions, and managed services on AWS and Azure to ensure continuity and compliance.
Keywords for positioning: custom applications, custom software, artificial intelligence, cybersecurity, AWS and Azure cloud services, business intelligence services, AI for companies, AI agents, Power BI.
Conclusion: this project illustrates how to combine Java and Google Cloud Vertex AI to go from raw video to a deployed accident detection model. Beyond the technical aspect, the initiative shows the potential of artificial intelligence applied to the common good, and how companies like Q2BSTUDIO can turn ideas into productive, secure solutions adapted to each client's needs.


