webcam | HackLAB https://www.geeks3d.com/hacklab 3D Programming, Prototyping and Gamedev with GeeXLab Tue, 14 Sep 2021 16:31:38 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 EU Covid-19 Vaccine Certificate (Health Pass) QR Code Reader in Python 3 https://www.geeks3d.com/hacklab/20210914/eu-covid-19-vaccine-certificate-health-pass-qr-code-reader-in-python-3/ https://www.geeks3d.com/hacklab/20210914/eu-covid-19-vaccine-certificate-health-pass-qr-code-reader-in-python-3/#comments Tue, 14 Sep 2021 16:31:38 +0000 https://www.geeks3d.com/hacklab/?p=1614 Downloads Python 3 Demopack Demo: geexlab-demopack-python3/qr-code/eu_health_pass_qrcode_reader/ GeeXLab full with Python3 (win64) How to run the demo? Download and unzip GeeXLab where you want, launch GeeXLab and drop the demo (main.xml) in GeeXLab. The full version of GeeXLab for Windows is recommended for this demo. The EU health pass (or Covid-19 vaccine certificate) is a document that contains some information about you (essentially your name and … Continue reading EU Covid-19 Vaccine Certificate (Health Pass) QR Code Reader in Python 3 »

The post EU Covid-19 Vaccine Certificate (Health Pass) QR Code Reader in Python 3 first appeared on HackLAB.]]>

GeeXLab - Health Pass / Covid-19 vaccine certificate QR Code Reader in Python 3



Downloads

How to run the demo?
Download and unzip GeeXLab where you want, launch GeeXLab and drop the demo (main.xml) in GeeXLab. The full version of GeeXLab for Windows is recommended for this demo.

The EU health pass (or Covid-19 vaccine certificate) is a document that contains some information about you (essentially your name and date of birth) as well as your current vaccine status (number of doses) and a big QR code that gathers all data. Here is a small demo coded in Python 3 that scans the QR code of the EU vaccine certificate, decodes it and shows you the data hidden behind this QR code.

The demo works on Windows only because of the built-in webcam functions I used for scanning QR codes. If necessary, the demo can be updated later to bypass the webcam and scan the image of a QR code you dropped in. You will be able then to run the demo on Linux too.

Moreover, the full GeeXLab for Windows contains all Python3 packages required by the demo. Just download the full version of GeeXLab, unzip it, run GeeXLab and drop the QR code demo in GeeXLab. A serious webcam is also required. A webcam that can do a clear focus on very close objects like your health pass QR code (on your mobile phone or on paper). Some tries (on the button SCAN a QR Code) will be likely necessary to read the QR code.

The core of the QR code decoding step has been adapted from this source and can be summed up to this:

– the QR code is a string starting with HC1:
– the string following HC1: is base45 encoded.
– the decoded base45 string leads to zlib-compressed data.
– the decompression leads to a CBOR Web Token structure.

To decode the QR code, you need the following Python 3 packages:
– base45
– cbor2
– zlib
– pprint

base45 and cbor2 packages be installed using pip:

pip install base45
pip install cbor2

base45 and cbor2 are already shipped with the full version of GeeXLab so don’t worry about installing them.

zlib and pprint are shipped with Python 3.

Here is the decoding function of the demo you can find in the frame.py file:

def DecodeHealthPass(payload):
  # The HC1: prefix nust be removed before decoding.
  s = payload.replace("HC1:", "")

  # decode Base45
  b45payload = base45.b45decode(s)

  # decompress using zlib
  cbordata = zlib.decompress(b45payload)
  
  # load the CBOR structure
  decoded = cbor2.loads(cbordata)
  decoded_qrcode = cbor2.loads(decoded.value[2])

  # prepare the CBOR structure in a readable way (newlines are added). 
  decoded_qrcode_str = pprint.pformat(decoded_qrcode)
  return decoded_qrcode_str

 
The demo:
GeeXLab - Health Pass / Covid-19 vaccine certificate QR Code Reader in Python 3

 
Here are the two steps to display the decoded QR code:

1/ click on SCAN a QR Code
This first step will show you the content (payload) of the QR code that must start with HC1: to be a valid health pass. You can now copy the payload to the clipboard if you need it.

2/ click on the Show decoded health pass button
This second step will decode the payload and display it in a small window. You can also copy to the clipboard the decoded health pass.

The decoded health pass contains information about the number of doses, the type of vaccin and its manufacturer. Here is a little help to decrypt these fields:

Field: ci --> "Unique Certificate Identifier, UVCI"
Field: co --> "Country of Test"
Field: is --> "Certificate Issuer"

Field: dob --> "Date of Birth, ISO 8601"

Field: dn --> "dose number"
Field: sd --> "Number of doses"

Field: mp  (medicinal product)
  EU/1/20/1528 --> Comirnaty
  EU/1/20/1507 --> COVID-19 Vaccine Moderna
  EU/1/21/1529 --> Vaxzevria
  EU/1/20/1525 --> COVID-19 Vaccine Janssen
 
Field: ma (vaccine manufacturer)
  ORG-100030215 --> Biontech Manufacturing GmbH
  ORG-100001699 --> AstraZeneca AB
  ORG-100001417 --> Janssen-Cilag International
  ORG-100031184 --> Moderna Biotech Spain S.L.
  ORG-100006270 --> Curevac AG

I added a PDF file in the demo folder that contains the specifications of the EU Covid-19 vaccine certificate.

The post EU Covid-19 Vaccine Certificate (Health Pass) QR Code Reader in Python 3 first appeared on HackLAB.]]>
https://www.geeks3d.com/hacklab/20210914/eu-covid-19-vaccine-certificate-health-pass-qr-code-reader-in-python-3/feed/ 2
(Demo) QR Code Generator and Reader https://www.geeks3d.com/hacklab/20200801/demo-qr-code-generator-and-reader/ https://www.geeks3d.com/hacklab/20200801/demo-qr-code-generator-and-reader/#respond Sat, 01 Aug 2020 16:23:34 +0000 https://www.geeks3d.com/hacklab/?p=1552 Downloads (APP) QR Code Generator for win64 (APP) QR Code Reader for win64 OpenGL 2.1 Demopack Demo: geexlab-demopack-gl-21/d55-qr-code/ Forum thread (EN) GeeXLab 0.35 comes with the support of QR Codes (or Quick Response codes). We can now read a QR code (from an image or using the webcam) and we can generate a QR code with any reasonable (not too big) payload. The payload is … Continue reading (Demo) QR Code Generator and Reader »

The post (Demo) QR Code Generator and Reader first appeared on HackLAB.]]>

GeeXLab - QR Code Reader and Generator demo



Downloads

GeeXLab 0.35 comes with the support of QR Codes (or Quick Response codes). We can now read a QR code (from an image or using the webcam) and we can generate a QR code with any reasonable (not too big) payload. The payload is the real content of the QR code. For example a web link. Wikipedia has a detailed page about QR codes HERE.

QR code support is available on Windows, Linux and Raspberry Pi. I prepared two small standalone utilities (generator and scanner) for Windows. For Linux / RPi, the generator is available in the OpenGL 2.1 demopack (geexlab-demopack-gl-21/d55-qr-code/ folder). The QR code scanner does not work on Linux / RPi because there is no built-in webcam support in GeeXLab for those platforms. But you can hack the demo to load (or drag and drop) any QR code texture. You can also use OpenCV to drive the webcam (see THIS DEMO).

 

QR Code Generator

This QR code generator allows to create a QR code from a payload (a string). You can type any payload or copy and paste it (few hundred of characters max otherwise nothing is generated). Then just click on the GENERATE QR CODE button, and a QR code image (.png) will be saved in the qrcodes/ folder.

 
– Example with a web link:
GeeXLab - QR Code Generator

 
– Example with a text:
GeeXLab - QR Code Generator

 

QR Code Scanner

The QR Code Scanner is a simple QR code reader that uses a webcam. Once the webcam is reading the QR code, click on [SCAN QR CODE]. If the QR code is correctly detected and is valid, the QR code payload is displayed as well as the corners coordinates of the bounding square. If the payload is an url (starting with http), a button is displayed to open the url in the default browser.

GeeXLab - QR Code Scanner with a webcam

The post (Demo) QR Code Generator and Reader first appeared on HackLAB.]]>
https://www.geeks3d.com/hacklab/20200801/demo-qr-code-generator-and-reader/feed/ 0
Python 3 and OpenCV Part 4: Face Detection (Webcam or Static Image) https://www.geeks3d.com/hacklab/20200310/python-3-and-opencv-part-4-face-detection-webcam-or-static-image/ https://www.geeks3d.com/hacklab/20200310/python-3-and-opencv-part-4-face-detection-webcam-or-static-image/#respond Tue, 10 Mar 2020 13:34:53 +0000 https://www.geeks3d.com/hacklab/?p=1501 Downloads: Python 3 Demopack Download Demo: geexlab-demopack-python3/opencv/04-webcam-face-detection/main.xml GeeXLab Downloads Forum thread (EN) For the fourth and last article (previous articles are here, here and here), we’re going to look at face detection using OpenCV. So far, the OpenCV functions we used (image reading, webcam output) are basic functions we find in many softwares inlcuding GeeXLab. What makes OpenCV interesting is the availability of some computer … Continue reading Python 3 and OpenCV Part 4: Face Detection (Webcam or Static Image) »

The post Python 3 and OpenCV Part 4: Face Detection (Webcam or Static Image) first appeared on HackLAB.]]>

GeeXLab - Python 3 - Webcam - face detection with OpenCV


Downloads:


For the fourth and last article (previous articles are here, here and here), we’re going to look at face detection using OpenCV. So far, the OpenCV functions we used (image reading, webcam output) are basic functions we find in many softwares inlcuding GeeXLab. What makes OpenCV interesting is the availability of some computer vision algorithms such as face detection (or face recognition).

The face detection method used in the demo is based on the Haar Cascades. If, like me, you are not an expert of Haar cascades, here is what you need to know:

Object Detection using Haar feature-based cascade classifiers is an effective method proposed by Paul Viola and Michael Jones in the 2001 paper, “Rapid Object Detection using a Boosted Cascade of Simple Features”. It is a machine learning based approach in which a cascade function is trained from a lot of positive images (images of faces) and negative images (images without faces). It is then used to detect objects in other images.

More about Haar cascades can be found HERE.

OpenCV comes with pre-trained classifiers for faces and eyes we can use in our demo. These pre-trained classifiers are XML files stored in opencv/data/haarcascades/ folder. In the demo, the classifiers are stored in the demo/data/ folder:

– data/haarcascade_frontalface_default.xml
– data/haarcascade_eye.xml
– data/haarcascade_eye_tree_eyeglasses.xml

haarcascade_eye_tree_eyeglasses.xml is an eye detector with better handling of eyeglasses.

Once the classifiers (one classifier for faces, one for eyes) are initialized with XML files, they are used in detectMultiScale() function, that performs the detection.

Let see how to initialize the face and eyes classifiers and how to detect faces and eyes on a static image:

import cv2

demo_dir = gh_utils.get_demo_dir() 		
image = cv2.imread(demo_dir + 'data/pexels-people-03.jpg', cv2.IMREAD_COLOR)

# Parameter specifying how much the image size is reduced at each image scale.
fd_scaleFactor  = 1.1 

# Parameter specifying how many neighbors each candidate rectangle should have to retain it.
fd_minNeighbors  = 3 

# Initializes classifiers
face_cascade = cv2.CascadeClassifier(demo_dir + 'data/haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier(demo_dir + 'data/haarcascade_eye_tree_eyeglasses.xml')

# detectMultiScale requires an CV_U8 image (gray).
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Detects objects of different sizes in the input image. 
# The detected objects are returned as a list of rectangles.
image_faces = face_cascade.detectMultiScale(gray_image, fd_scaleFactor, fd_minNeighbors, minSize=(80, 80))

# detect eyes for each face.
for (x,y,w,h) in image_faces:
  roi_gray = gray_image[y:y+h, x:x+w]
  eyes = eye_cascade.detectMultiScale(roi_gray)
  for (ex,ey,ew,eh) in eyes:
    e = (x+ex, y+ey, ew, eh)
    image_eyes.append(e)

image_faces is a list of rectangles for all faces. image_eyes is a list of lists: list of all face eyes lists (for each face, there is a list of eyes rectangles).



In the FRAME script, faces and eyes rectangles can be rendered as follows for the static image (face and eyes detection is done once for a static image):

num_faces_detected = len(image_faces)
if (num_faces_detected > 0):
  gh_renderer.set_line_width(4.0)
  gh_gpu_program.bind(color_prog)

  # Face rectangles ---------------------
  #
  for (x,y,w,h) in image_faces:
    gh_gpu_program.uniform4f(color_prog, "color", 0.2, 0.5, 1.0, 1)
    draw_rectangle(x-texture_width/2, texture_height/2-y, w, h) 

    if (enable_eyes_detection == 1):
      num_eyes_detected = len(webcam_eyes)
      gh_gpu_program.uniform4f(color_prog, "color", 0, 1, 0, 1)

  # Eye rectangles ---------------------
  #
  for e in image_eyes:
    draw_rectangle(e[0]-texture_width/2, texture_height/2-e[1], e[2], e[3]) 

  gh_renderer.set_line_width(1.0)

 
For a dynamic image like the webcam, faces and eyes detection works in a similar way. The only difference is that detection is launched for every new webcam image.

 
I prepared a demo that shows faces + eyes detection on a static image and on the webcam output. I also added the possibility to add a hat on detected faces…

Remark: on my system, the demo takes more than 10 seconds to start. The guilty is the webcam initialization step (OpenCV)…

GeeXLab - Python 3 - Webcam - face detection with OpenCV

 
The OpenCV face detector works also with masks:

GeeXLab - Python 3 - Webcam - face detection with OpenCV

The post Python 3 and OpenCV Part 4: Face Detection (Webcam or Static Image) first appeared on HackLAB.]]>
https://www.geeks3d.com/hacklab/20200310/python-3-and-opencv-part-4-face-detection-webcam-or-static-image/feed/ 0
Python 3 and OpenCV Part 3: How to Read the Webcam with OpenCV (cv2) https://www.geeks3d.com/hacklab/20200308/python-3-and-opencv-part-3-how-to-read-the-webcam-with-opencv-cv2/ https://www.geeks3d.com/hacklab/20200308/python-3-and-opencv-part-3-how-to-read-the-webcam-with-opencv-cv2/#comments Sun, 08 Mar 2020 10:36:57 +0000 https://www.geeks3d.com/hacklab/?p=1500 Downloads: Python 3 Demopack Download Demo: geexlab-python3-demopack/opencv/03-webcam/main.xml GeeXLab Downloads Forum thread (EN) For this third tutorial (part 1, part 2) about OpenCV in Python 3, we’re going to look at how to read the webcam output. OpenCV has an object for video capturing from video files, image sequences or cameras: VideoCapture. Let’s see how to create a VideoCapture object and use it to grab a … Continue reading Python 3 and OpenCV Part 3: How to Read the Webcam with OpenCV (cv2) »

The post Python 3 and OpenCV Part 3: How to Read the Webcam with OpenCV (cv2) first appeared on HackLAB.]]>

GeeXLab - Python 3 - Webcam video capture with OpenCV


Downloads:


For this third tutorial (part 1, part 2) about OpenCV in Python 3, we’re going to look at how to read the webcam output.

OpenCV has an object for video capturing from video files, image sequences or cameras: VideoCapture. Let’s see how to create a VideoCapture object and use it to grab a frame from the webcam.

INIT script:

import cv2

video_capture_device_index = 0
webcam = cv2.VideoCapture(video_capture_device_index)

ret, video_frame = webcam.read()

 
That’s all.

If you have several webcams, you can specify the webcam by its index. Most users have only one webcam, therefore the video_capture_device_index is set to 0.

The read() grabs, decodes and returns a video frame. The video_frame is an NumPy array and, thanks to the part 2 we know how to convert it in a GeeXLab texture and how to display it. But before creating the texture, we need to know the size of the video frame. One way to do it is to read the video capture properties:

frame_width = int(round(webcam.get(cv2.CAP_PROP_FRAME_WIDTH)))
frame_height = int(round(webcam.get(cv2.CAP_PROP_FRAME_HEIGHT)))

 
We can now create the texture and update it with the video frame:

PF_U8_RGB = 1
PF_U8_BGR = 2
PF_U8_RGBA = 3

# BGR U8 is the default pixel format of OpenCV images.
# We create an empty texture
frame_texture = gh_texture.create_2d(frame_width, frame_height, PF_U8_BGR)

# and we update the texture pixmap with the OpenCV image.
gh_texture.update_gpu_memory_from_numpy_img(frame_texture, video_frame)

 
In the FRAME script, we can update the the texture every 50 ms and display it every frame:

dt = gh_utils.get_time_step()

gh_texture.bind(frame_texture, 0)

video_dt = video_dt + dt
if (video_dt > 0.05):
  video_dt = 0
  ret, frame = webcam.read()
  gh_texture.update_gpu_memory_from_numpy_img(frame_texture, frame)

gh_camera.bind(camera_ortho)
gh_gpu_program.bind(texture_prog)
gh_object.render(quad)

 
Here is the demo:
GeeXLab - Python 3 - Webcam video capture with OpenCV

 
Keep in mind that frame_texture is a regular 2D texture you can map on any object (torus, sphere, …):

Webcam output mapped on a sphere:
GeeXLab - Python 3 - Webcam video capture with OpenCV

 
Webcam output mapped on a donut:
GeeXLab - Python 3 - Webcam video capture with OpenCV

 
The demo shows how to save a file with OpenCV too. At the end of the FRAME script there is the following piece of code:

if (gh_imgui.button("Screenshot", 100, 20) == 1):
  demo_dir = gh_utils.get_demo_dir() 	
  screenshot_counter = screenshot_counter + 1	
  cv_img_filename = "%s/webcam_frame_%.2d.jpg" % (demo_dir, screenshot_counter)
  cv2.imwrite(filename=cv_img_filename, img=frame)

You can easily save an OpenCV image on disk using cv2.imwrite().

The post Python 3 and OpenCV Part 3: How to Read the Webcam with OpenCV (cv2) first appeared on HackLAB.]]>
https://www.geeks3d.com/hacklab/20200308/python-3-and-opencv-part-3-how-to-read-the-webcam-with-opencv-cv2/feed/ 1