top of page

QR Code Access Control with Pyzbar and OpenCV

  • Writer: Sairam Penjarla
    Sairam Penjarla
  • Jun 25, 2024
  • 2 min read

Secure Your Space with a Python QR Code Access Control System!

This blog post explores a Python project that implements a QR code-based access control system, perfect for adding a layer of security to your physical space.


Python Meets Security:

This project leverages the power of OpenCV and the pyzbar library to create a QR code access control system. Say goodbye to traditional keys or codes - authorization is granted through the scan of a QR code!


Project Breakdown:

The project consists of two main parts:

  • qr_code_access.py: This script acts as the brain of the system. It handles capturing webcam input, detecting QR codes, decoding the data they contain, and displaying access control messages based on the decoded value.

  • requirements.txt: This file lists all the external libraries required to run the project smoothly.


Setting Up Your Security System:

Here's a step-by-step guide to get your QR code access control system up and running:

1. Grab the Code: Clone the repository using the following command:

Bash

git clone https://github.com/sairam-penjarla/QR-Code.git

2. Install Dependencies: The project relies on external libraries. Install them using the following command in your terminal:

Bash

pip install -r requirements.txt

3. Run the Script: Now that everything is set up, launch the script using:

Bash

python qr_code_access.py

Granting or Denying Access:

  1. Launch and Position:  Running the script will activate your webcam and display the video feed on your screen. A blue square will appear in the center of the feed. This is your target zone!

  2. Scan the Code:  Hold your QR code within the blue square for optimal detection. The script will attempt to decode the data from the QR code.

  3. Access Granted or Denied:  If the decoded data matches one of the predefined access codes stored in the script, "Access Granted" will be displayed along with the decoded value. A green bounding box will also appear around the QR code for confirmation. On the other hand, if there's no match, "Access Denied" will be displayed, and a red bounding box will surround the QR code.

  4. Exit the System:  Press the "q" key on your keyboard to stop the webcam feed and close the program.


Customizing Your Access Codes:

The script comes with a predefined list of authorized access codes. You can modify this list within the script itself to suit your specific needs. By default, the script includes these example codes:

Python

access_codes = ["12345", "67890", "ABCDE"]

Technical Requirements:

  • OpenCV and pyzbar: These libraries are the backbone of the project's functionality and are included in the requirements.txt file. You can install them using the mentioned pip command in step 2 of the setup process.

  • Webcam: Ensure you have a working webcam connected to your computer for the script to function.


Exploring Further:

This blog post equips you with the knowledge to set up and run your own Python-based QR code access control system. The project offers potential for further development, such as:

  • Logging access attempts for record-keeping purposes.

  • Integrating the system with a database for more sophisticated access control management.

  • Implementing more advanced QR code detection and decoding techniques.

The provided references offer valuable resources for delving deeper into OpenCV and pyzbar:

With a little customization, this Python project can be a valuable addition to your security measures! 



Happy Coding and Happy Securing!

Sign up for more like this.

Thanks for submitting!

bottom of page