{"id":19271182,"url":"https://github.com/mmaarij/parallelized-number-plate-detection-system-using-opencv-openmp","last_synced_at":"2026-05-11T07:45:47.755Z","repository":{"id":89550167,"uuid":"493724672","full_name":"mmaarij/Parallelized-Number-Plate-Detection-System-using-OpenCV-OpenMP","owner":"mmaarij","description":"A Parallelized Number Plate Detection System developed for Windows using Visual Studio. It utilizes OpenCV and OpenMP to efficiently detect number plates in images and recognize characters on them. The primary goal of this system is to speed up the process of detecting and recognizing number plates in images or video frames.","archived":false,"fork":false,"pushed_at":"2023-10-18T13:33:07.000Z","size":34480,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-05T13:23:11.829Z","etag":null,"topics":["character-recognition","cpp","nerual-network","number-plate-detection","number-plate-recognition","opencv","openmp","openmp-optimization","openmp-parallelization","perceptron","python"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mmaarij.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-18T15:37:58.000Z","updated_at":"2024-06-04T10:25:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"0918a467-dbce-4ff1-b7d1-c646aa47e5a3","html_url":"https://github.com/mmaarij/Parallelized-Number-Plate-Detection-System-using-OpenCV-OpenMP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmaarij%2FParallelized-Number-Plate-Detection-System-using-OpenCV-OpenMP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmaarij%2FParallelized-Number-Plate-Detection-System-using-OpenCV-OpenMP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmaarij%2FParallelized-Number-Plate-Detection-System-using-OpenCV-OpenMP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmaarij%2FParallelized-Number-Plate-Detection-System-using-OpenCV-OpenMP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mmaarij","download_url":"https://codeload.github.com/mmaarij/Parallelized-Number-Plate-Detection-System-using-OpenCV-OpenMP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240373396,"owners_count":19791199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["character-recognition","cpp","nerual-network","number-plate-detection","number-plate-recognition","opencv","openmp","openmp-optimization","openmp-parallelization","perceptron","python"],"created_at":"2024-11-09T20:29:29.149Z","updated_at":"2026-05-11T07:45:42.707Z","avatar_url":"https://github.com/mmaarij.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Parallelized Number Plate Detection System using OpenCV and OpenMP\n\nThis project is a Parallelized Number Plate Detection System developed for Windows using Visual Studio. It utilizes OpenCV and OpenMP to efficiently detect number plates in images and recognize characters on them. The primary goal of this system is to speed up the process of detecting and recognizing number plates in images or video frames.\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Objectives](#objectives)\n- [Technology Stack](#technology-stack)\n- [Function Definitions](#function-definitions)\n- [Parallelism Decomposition](#parallelism-decomposition)\n- [Program Flow](#program-flow)\n- [Usage Instructions](#usage-instructions)\n- [Results](#results)\n- [Python Neural Network for Character Recognition](#neural-network-for-character-recognition)\n- [License](#license)\n\n## Introduction\n\nIn today's world, image processing and task automation play a crucial role in law enforcement. A number plate detection system can digitalize this process, providing convenience to law enforcement agencies. This system has various applications, from catching over-speeding drivers to tracking criminal vehicle movements. It can also be integrated into dashboard cameras to detect, recognize, and store number plates during traffic incidents.\n\nConventional (serialized) systems may face efficiency challenges when dealing with a large number of vehicles in a single camera frame. Parallelized systems offer the potential for more efficient and faster results. Additionally, character recognition in traditional systems can be computationally expensive, while using a pre-trained neural network can significantly speed up the process.\n\n## Objectives\n\nThe objectives of this project are as follows:\n\n1. Implement a C++ system capable of detecting multiple number plates from a video stream.\n\n2. Crop the detected number plates from the video frame and individually process them to detect characters.\n\n3. Recognize the characters in the image by employing a recognition engine based on a Neural Net.\n\n4. Output a corresponding string of characters representing the recognized number plate.\n\n5. Store the image and the recognized plate number for future use.\n\nTo ensure the program runs efficiently and provides significant speedups compared to traditional systems, OpenCV is used for image processing, and OpenMP is used to parallelize the entire process.\n\n## Technology Stack\n\n- C++ (Visual Studio)\n- OpenMP library for parallelization\n- OpenCV library for image processing\n- Python (Used to create and train the Neural Net, and invoked to recognize characters using the pre-trained Neural Net)\n\n## Function Definitions\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003eFunction Name\u003c/th\u003e\n    \u003cth\u003eUse\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003evoid main()\u003c/td\u003e\n    \u003ctd\u003e\n      \u003cul\u003e\n        \u003cli\u003eLoad images using a for loop\u003c/li\u003e\n        \u003cli\u003e(Parallelized) For Each Image:\n          \u003cul\u003e\n            \u003cli\u003eLoad Harr-Cascade Number-Plate Classifier.\u003c/li\u003e\n            \u003cli\u003eApply Median Blur to image\u003c/li\u003e\n            \u003cli\u003eConvert to Grayscale\u003c/li\u003e\n            \u003cli\u003eUse Viola-Jones Cascade Method (built into OpenCV) to detect all plates within the current frame\u003c/li\u003e\n            \u003cli\u003eCall processPlatesArray() function\u003c/li\u003e\n          \u003c/ul\u003e\n        \u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003evoid processPlatesArray(Mat\u0026 frame, Mat\u0026 grey, vector \u003cRect\u003e\u0026 plates)\u003c/td\u003e\n    \u003ctd\u003e\n      \u003cul\u003e\n        \u003cli\u003eProcess all plates in an image using a for loop\u003c/li\u003e\n        \u003cli\u003e(Parallelized) For each plate:\n          \u003cul\u003e\n            \u003cli\u003eCall processSinglePlate() function\u003c/li\u003e\n          \u003c/ul\u003e\n        \u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003evoid processSinglePlate(Mat\u0026 croppedPlate)\u003c/td\u003e\n    \u003ctd\u003e\n      \u003cul\u003e\n        \u003cli\u003ePreprocess cropped plate:\n          \u003cul\u003e\n            \u003cli\u003eApply Binary Thresholding\u003c/li\u003e\n            \u003cli\u003eApply Median Blur\u003c/li\u003e\n            \u003cli\u003eErode the lines in the image\u003c/li\u003e\n            \u003cli\u003eDilate the lines in the image\u003c/li\u003e\n            \u003cli\u003eApply Inverse Binary Thresholding\u003c/li\u003e\n            \u003cli\u003eApply Canny Edge Detection\u003c/li\u003e\n          \u003c/ul\u003e\n        \u003c/li\u003e\n        \u003cli\u003eUse the built-in OpenCV findContours() function to find all contours in the image\u003c/li\u003e\n        \u003cli\u003eCall sortContours() function\u003c/li\u003e\n        \u003cli\u003eProcess all contours in the image using a for loop\u003c/li\u003e\n        \u003cli\u003eFor each contour:\n          \u003cul\u003e\n            \u003cli\u003eSelect a bounding rectangle around the contour as the region of interest (ROI)\u003c/li\u003e\n            \u003cli\u003eIf ROI is of acceptable parameters and does not overlap with the previous ROI, add the contour to the selected ROI list\u003c/li\u003e\n          \u003c/ul\u003e\n        \u003c/li\u003e\n        \u003cli\u003eCall postProcessImg() function\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003evoid postProcessImg(Mat\u0026 dilatedImg, vector \u003cvector \u003cPoint\u003e\u003e contours, vector \u003cint\u003e selected_ROI)\u003c/td\u003e\n    \u003ctd\u003e\n      \u003cul\u003e\n        \u003cli\u003eConvert a copy of the image from grayscale to RGB.\u003c/li\u003e\n        \u003cli\u003e(Parallelized) For each character/contour:\n          \u003cul\u003e\n            \u003cli\u003eCrop the character out of the grayscale image\u003c/li\u003e\n            \u003cli\u003eCall recognizeCharacter() function on the cropped character and get the return value\u003c/li\u003e\n            \u003cli\u003eAdd the recognized character to the output string (recognized license plate number)\u003c/li\u003e\n            \u003cli\u003eDraw a bounding rectangle around the character on the colored image copy\u003c/li\u003e\n            \u003cli\u003eLabel the character with recognized text on the colored image copy\u003c/li\u003e\n            \u003cli\u003eSave the processed image in the output directory with a filename set to the output string\u003c/li\u003e\n          \u003c/ul\u003e\n        \u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003estring recognizeCharacter(Mat\u0026 croppedCharacter)\u003c/td\u003e\n    \u003ctd\u003e\n      \u003cul\u003e\n        \u003cli\u003ePreprocess cropped character:\n          \u003cul\u003e\n            \u003cli\u003eDilate lines\u003c/li\u003e\n            \u003cli\u003eAdd a padded border\u003c/li\u003e\n            \u003cli\u003eResize the image to 28x28 pixels\u003c/li\u003e\n          \u003c/ul\u003e\n        \u003c/li\u003e\n        \u003cli\u003eParse a Python command as a string to be run as a system command in the form \"python neuralnet.py p1 p2 p3 …... p784\" where pN denotes pixel values to be passed as arguments to the Python script\u003c/li\u003e\n        \u003cli\u003eCall execSystemCommand() function with the parsed command as a parameter to run the Python script and send the cropped character image to the neural net for recognition\u003c/li\u003e\n        \u003cli\u003eReturn the recognized character obtained as output from the neural net\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003evoid sortContours(vector \u003cvector \u003cPoint\u003e\u003e\u0026 contours)\u003c/td\u003e\n    \u003ctd\u003e\n      \u003cul\u003e\n        \u003cli\u003eSort contours based on x coordinates from left to right using insertion sort\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003estring execSystemCommand(const char* cmd)\u003c/td\u003e\n    \u003ctd\u003e\n      \u003cul\u003e\n        \u003cli\u003eCreate a pipe\u003c/li\u003e\n        \u003cli\u003eExecute a system command and store the output in a result string using the pipe\u003c/li\u003e\n        \u003cli\u003eReturn the result string\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003estring char_to_str(char c)\u003c/td\u003e\n    \u003ctd\u003e\n      \u003cul\u003e\n        \u003cli\u003eConvert a character to a string\u003c/li\u003e\n        \u003cli\u003eReturn the converted string\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\n## Parallelism Decomposition\n![Parallelism Decomposition](Resources/Parallelism%20Decomposition.jpg)\n\n## Program Flow\n![Program Flow](Resources/Program%20Flow.jpg)\n\n## Usage Instructions\n\n### Step 1 - Install OpenCV\n\n1. Go to [OpenCV Releases](https://github.com/opencv/opencv/releases) and download the Latest Release's EXE File.\n2. Create a folder ‘OpenCV’ in the C drive.\n3. Run the downloaded .exe file and select the extraction location as the folder you just created.\n4. Add the bin folder (C:\\OpenCV\\opencv\\build\\x64\\vc15\\bin) to the Environment Variables path.\n   ![Environment Variables Setup](Resources/Environment%20Variables.png)\n6. Restart your computer.\n\n### Step 2 - Install Python\n\n1. Download the installer from [Python Downloads for Windows](https://www.python.org/downloads/windows/).\n2. Run the installer and follow the setup steps.\n3. Make sure the 'Add Python to Path' option is checked during the setup process.\n4. Verify the Python installation by running \"python -V\" in the command line.\n\n### Step 3 – Set Up Project\n\n1. Clone the project from [GitHub](https://github.com/mmaarij/Parallelized-Number-Plate-Detection-System-using-OpenCV-OpenMP).\n2. Run the Visual Studio Solution (.sln) file.\n3. Verify that OpenCV is added to the project properties.\n   - Go to Project \u003e Properties.\n   - In VC++ Directories \u003e Build Directories, add “C:\\OpenCV\\opencv\\build\\include”.\n   - In VC++ Directories \u003e Library Directories, add “C:\\OpenCV\\opencv\\build\\x64\\vc15\\lib”.\n   - In Linker \u003e Input \u003e Additional Dependencies, add “opencv_world455d.lib”.\n4. Enable OpenMP in Visual Studio by going to Project \u003e Properties \u003e C/C++ \u003e Language \u003e OpenMP Support and enabling it to \"Yes\".\n5. Rename a batch of images to be detected in the form \"plate (1)\", \"plate (2)\", and so on.\n6. Go to [Bulk Resize Photos](https://bulkresizephotos.com/en) and bulk resize all images to 960 x 540.\n7. In the project directory, navigate to Resources \u003e Plates \u003e test and paste all the renamed/resized images.\n\n### Step 4 – Run the Program\n\n1. Enter the number of images in the test directory.\n2. The output will be stored inside the \"RecognitionOutput\" folder in the project directory.\n\n## Results\n\nThe test was run on a batch of 10 images, containing 11 number plates. The entire batch was processed for 100 iterations, and the results were averaged out in the end.\n\nFor one single batch, the average time was as follows:\n\n- Serial Execution Time: 57.0827 seconds\n- Parallel Execution Time: 18.1869 seconds\n\nThe parallelized implementation resulted in a speedup of approximately 313.86%.\n\n## Python Neural Network for Character Recognition\n\nCharacter recognition in this project is performed using a Python neural network script. The script uses a Perceptron model for character recognition.\n\nThe Python script reads a saved neural network object from the \"Plates_NN.pickle\" file, which contains the trained model's weights and biases. It then processes the input image and returns a prediction for the recognized character.\n\nHere is an overview of the neuralnet.py script:\n```python\nimport numpy as np\nimport pandas as pd\nimport pickle\nimport sys\n\nclass Perceptron:\n  all_weights = []\n  all_bias = []\n\n  def __init__(self, weights, bias):\n    self.all_weights = weights\n    self.all_bias = bias\n\n# Functions for weighted sum, sigmoid, and prediction\n\ndef get_weighted_sum(feature, weights, bias):\n  # Calculate the weighted sum of features\n  wSum = float(0.0)\n  for i in range(len(feature)):\n    wSum += float(feature[i] * weights[i])\n\n  wSum += float(bias)\n  return wSum\n\ndef sigmoid(w_sum):\n  # Apply sigmoid activation function\n  sig = 1 / (1 + np.exp(-w_sum))\n  return sig\n\ndef get_prediction(image, weights, bias):\n  # Get the prediction for the input image\n  w_sum = get_weighted_sum(image, weights, bias)\n  prediction = sigmoid(w_sum)\n  return prediction\n\ndef main(imgArray):\n  # Load the trained neural network from a file\n  file_to_read = open(\"Plates_NN.pickle\", \"rb\")\n  loaded_object = pickle.load(file_to_read)\n  file_to_read.close()\n\n  image = np.array(imgArray) / 255\n\n  predictions_set = []\n  listOfLabels = ['A', 'B', 'C', ...]  # List of possible characters\n\n  # Get predictions for all characters\n  for j in range(36):\n    prediction = get_prediction(image, loaded_object.all_weights[j], loaded_object.all_bias[j])\n    temp_tup = (listOfLabels[j], prediction)\n    predictions_set.append(temp_tup)\n\n  df = pd.DataFrame.from_records(predictions_set, columns=['Character', 'Prediction'])\n  df['Prediction'] = df['Prediction'].astype(float).round(6)\n  df.sort values(by=['Prediction'], inplace=True, ascending=False)\n\n  # Get the character with the highest prediction\n  topPrediction = str(df.iloc[0][0])\n  print(topPrediction)\n\nmain(list(map(float, sys.argv[1:])))\n```\n\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmaarij%2Fparallelized-number-plate-detection-system-using-opencv-openmp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmaarij%2Fparallelized-number-plate-detection-system-using-opencv-openmp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmaarij%2Fparallelized-number-plate-detection-system-using-opencv-openmp/lists"}