-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* all qr code scanner files added * final main readme commits * renamed folder
- Loading branch information
1 parent
33ba19f
commit b58dff6
Showing
5 changed files
with
208 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
opencv-python | ||
pyzbar | ||
Pillow | ||
tk |
Oops, something went wrong.