Skip to content

Instantly share code, notes, and snippets.

View yushulx's full-sized avatar

Xiao Ling yushulx

View GitHub Profile
@yushulx
yushulx / app.py
Created August 24, 2022 07:18
OpenCV Python: rotate and draw a barcode QR code image over a background image
# pip install python-barcode pylibdmtx opencv-python
from PIL import Image
from pylibdmtx.pylibdmtx import encode, decode
import cv2
import numpy
from barcode import UPCA
from barcode.writer import ImageWriter
number = 10000000000
@yushulx
yushulx / barcode_scanning.py
Created December 17, 2020 07:45
Barcode Scanning with OpenCV, Webcam and Dynamsoft Barcode Reader
#!/usr/bin/env python3
'''
Usage:
barcode_scanning.py <license.txt>
Keyboard shortcuts:
ESC - exit
'''
from dbr import *
# Initialize Dynamsoft Barcode Reader
reader = BarcodeReader()
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
license_key = "LICENSE KEY"
reader.init_license(license_key)
def decodeframe(frame, left, top, right, bottom):
settings = reader.reset_runtime_settings()
def postprocess(frame, outs):
frameHeight, frameWidth = frame.shape[:2]
classIds = []
confidences = []
boxes = []
for out in outs:
for detection in out:
scores = detection[5:]
void decode_barcode_buffer(void* barcodeReader, const unsigned char *data, int width, int height, int channel, boolean has_region, int left, int right, int top, int bottom)
{
if (has_region)
{
PublicRuntimeSettings settings;
char errorMessage[256];
int errorCode = DBR_GetRuntimeSettings(barcodeReader, &amp;settings);
settings.region.regionLeft = left;
settings.region.regionRight = right;
settings.region.regionTop = top;
try:
text_results = reader.decode_file(self.filePath)
if text_results != None:
for text_result in text_results:
print("Barcode Format :")
print(text_result.barcode_format_string)
self.prevLabelText = text_result.barcode_format_string
print("Barcode Text :")
print(text_result.barcode_text)
print("Localization Points : ")
from google_images_download import google_images_download
import argparse
ap = argparse.ArgumentParser()
ap.add_argument("-k", "--keywords", required=True,
help="The keywords/key phrases you want to search for.")
ap.add_argument("-l", "--limit", required=True,
help="The number of images that you want to download.")
args = vars(ap.parse_args())
overlay.addEventListener('mouseup', e => {
if (isDrawing) {
isDrawing = false;
mousePosition.innerHTML = "Cursor: (" + e.offsetX + ", " + e.offsetY + ")";
region.innerHTML = "Decode a region: (" + startX + ", " + startY + ", " + e.offsetX + ", " + e.offsetY + "). ";
overlay.style.cursor = "default";
// Decode a region of the barcode image
(async () => {
(async () => {
await barcodereader.resetRuntimeSettings();
await barcodereader.updateRuntimeSettings('coverage'); // Mode: speed, balance, coverage
try {
await barcodereader.decode(name.files[0]).then((results) => {
let txts = [];
try {
for (let i = 0; i < results.length; ++i) {
txts.push(results[i].BarcodeText);
}
function clearOverlay() {
overlayCtx.clearRect(0, 0, overlay.width, overlay.height);
overlayCtx.strokeStyle = '#ff0000';
overlayCtx.lineWidth = 5;
}
overlay.addEventListener('mousedown', e => {
startX = e.offsetX;
startY = e.offsetY;
isDrawing = true;