Skip to content

Commit

Permalink
Added Qr Code Scanner script (#361)
Browse files Browse the repository at this point in the history
* all qr code scanner files added

* final main readme commits

* renamed folder
  • Loading branch information
thechiranjeevvyas authored Oct 30, 2024
1 parent 33ba19f commit b58dff6
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 115 deletions.
52 changes: 52 additions & 0 deletions QR Code Scanner/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# QR Code Scanner Script

This script enables users to scan and decode QR codes from image files (PNG and JPG formats). It uses OpenCV and Pyzbar for decoding QR codes and provides a simple file dialog for selecting images on your local machine.

## Requirements

To run this script, you'll need Python 3.x installed on your machine. The required libraries are listed in `requirements.txt`, including:

- **opencv-python**: For image processing.
- **pyzbar**: For decoding QR codes.
- **Pillow**: Required for handling image formats.
- **tk**: Provides a file dialog for image selection.

## Installation

1. **Clone the repository** (or download the script and `requirements.txt` directly):
```bash
git clone <repository_url>
cd <repository_directory>
```
2. **Install dependencies:**(Run the following command to install the necessary libraries from `requirements.txt`:)

```bash
pip install -r requirements.txt
```

## Usage

1. **Run the script** (Execute the QR code scanner script using:)
```bash
python qr_code_scanner.py
```
2. **Select an Image**
- A file dialog will open, allowing you to select a PNG or JPG image containing a QR code.
- Once an image is selected, the script will attempt to decode any QR code present in the image.
3. **View the Output**
- If a QR code is detected, its contents will be displayed in the terminal.

## Requirements.txt File

The `requirements.txt` file lists all dependencies for the QR code scanner script. This file ensures that the correct versions of each library are installed to avoid compatibility issues. Libraries in `requirements.txt` include:

```bash
opencv-python
pyzbar
Pillow
tk
```

Make sure to install these libraries by running pip install -r `requirements.txt` before using the script.

## License
Binary file added QR Code Scanner/qr_code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions QR Code Scanner/qr_scanner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import cv2
from pyzbar.pyzbar import decode
from tkinter import filedialog
from tkinter import Tk
from PIL import Image

def scan_qrcode(image_path):
# Load the image using OpenCV
img = cv2.imread(image_path)

# Decode the QR code in the image
decoded_objects = decode(img)

# Check if any QR code is found
if decoded_objects:
for obj in decoded_objects:
print(f"QR Code Detected: {obj.data.decode('utf-8')}")
else:
print("No QR code detected in the image.")

def open_file():
# Open a file dialog to allow the user to select an image file (PNG or JPG)
root = Tk()
root.withdraw() # Hide the main tkinter window
file_path = filedialog.askopenfilename(
title="Select Image",
filetypes=[("Image files", "*.png;*.jpg;*.jpeg")]
)

if file_path:
print(f"Selected file: {file_path}")
scan_qrcode(file_path)
else:
print("No file selected.")

if __name__ == "__main__":
open_file()
4 changes: 4 additions & 0 deletions QR Code Scanner/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
opencv-python
pyzbar
Pillow
tk
Loading

0 comments on commit b58dff6

Please sign in to comment.