python 3 | HackLAB https://www.geeks3d.com/hacklab 3D Programming, Prototyping and Gamedev with GeeXLab Tue, 09 Jan 2024 12:38:39 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 GeeXLab 0.56 released (*** UPDATED: v0.56.2 + Linux 32-bit ***) https://www.geeks3d.com/hacklab/20231203/geexlab-0-56-released/ https://www.geeks3d.com/hacklab/20231203/geexlab-0-56-released/#respond Sun, 03 Dec 2023 13:35:16 +0000 https://www.geeks3d.com/hacklab/?p=1731 1 – Downloads Downloads GeeXLab 0.56.2 lite (win64) (210MB) GeeXLab 0.56.2 full (win64) (437MB) GeeXLab 0.56.2 (win32) (54MB) GeeXLab 0.56.2 (linux64 / GLIBC 2.31) (187MB) GeeXLab 0.56.2 (linux32 / GLIBC 2.31) (27MB) All GeeXLab Downloads Forum thread Discord server   2 – Release Notes GeeXLab 0.56.0 is available for Windows 32/64-bit. I will update Linux64, macOS (I recently tested GeeXLab 0.49.2 for macOS on the … Continue reading GeeXLab 0.56 released (*** UPDATED: v0.56.2 + Linux 32-bit ***) »

The post GeeXLab 0.56 released (*** UPDATED: v0.56.2 + Linux 32-bit ***) first appeared on HackLAB.]]>

1 – Downloads



Downloads

 

2 – Release Notes

GeeXLab 0.56.0 is available for Windows 32/64-bit. I will update Linux64, macOS (I recently tested GeeXLab 0.49.2 for macOS on the latest macOS 14.1.2 Sonoma and I was surprised to see that GeeXLab still works on the latest iteration of macOS!) and Raspberry Pi later (for the RPi, I’m waiting the for RPi 5…). GeeXLab 0.56 engine is behind latest versions of FurMark 2 and YAFFplayer.

Here are the main changes:

FFmpeg plugin

The detection of the orientation of the video stream has been added to the FFmpeg plugin. This detection is useful with videos taken with a mobile phone in portrait mode.

Dear ImGui

Dear ImGui support has been updated with new imspinner functions. The demo about imspinner is available in the GL 2.1 demopack (geexlab-demopack-gl21/d29-imgui/imgui-imspinner/).

GeeXLab - ImSpinner demo

 

*** UPDATE: GeeXLab 0.56.1 ***

GeeXLab 0.56.1 is a maintenance release and comes with bug fixes and updated librairies (see the changelog for more details).

The Linux 64-bit version is available as well (built with GLIBC 2.31). Usually I build the linux version on a real Linux machine (a Ryzen CPU and a Radeon RX 5500 XT GPU). GeeXLab 0.56.1 has been built on a virtual machine using VirtualBox (host: Win10 64-bit pro, guest: Linux Mint 20.3 with GLIBC 2.31) on my Win10 dev station. That worked fine and I think I will keep building the linux version like that.

GeeXLab - mesa / llvmpipe renderer

 

*** UPDATE: GeeXLab 0.56.2 ***

GeeXLab 0.56.2 is a maintenance release and comes with bug fixes and support for Linux 32-bit.

Linux 32-bit??? Yes, because of FurMark 2 (FurMark 2 is built with GeeXLab engine). Some users need FurMark 2 on Linux 32-bit and thanks to this update, I found and fixed a bug in the Vulkan plugin. GeeXLab for Linux 32-bit is a very lightweight version of GeeXLab: it contains only core dynamic libs as well as four plugins (vulkan, gpu monitoring, artifact scanner and python 3.9).

But it was not easy to build GeeXLab for Linux 32-bit. I had to find a distribution that has a standard interface (I can quikly find what I need), that has GLIBC 2.31 (very important!), that has a recent GCC compiler and that has a 32-bit ISO. After some searches and tests, I found MX-Linux. This distro is available in both 64-bit and 32-bit, has GLIBC 2.31 and has GCC 10.2.1 that is ok to compile GeeXLab. And both versions work fine in VirtualBox.

MX-Linux 21.3 for GeeXLab development

 

3 – Changelog

This changelog is intended for all versions of GeeXLab.

Full changelog from beginning of time is available HERE.

Version 0.56.2.0 - 2024.01.09
+ (2024.01.08) GPU monitoring plugin: added commercial name:
  - ASRock RX 7900 XT Phantom Gaming White
  - YESTON RX 7900 XTX Sakura Sugar 24GD6
+ (2024.01.08) added support for Linux 32-bit platform.
* (2024.01.07) fixed a bug the initialization of the Vulkan plugin (related to VK_KHR_driver_properties). 
  Depending on the platform, this bug could crash GeeXLab.
- (2024.01.06) removed curl support on Linux x32 platforms (does not compile properly). 
- (2024.01.06) removed NativeFileDialog (based on GTK3) support on Linux platforms. 

Version 0.56.1.0 - 2024.01.04
* (2024.01.04) Linux: fixed a bug in Dear ImGui rendering with OpenGL 3.1 renderer
  (MESA/llvmpipe with GL_SHADING_LANGUAGE_VERSION = 1.40).
! (2024.01.02) Python 3.12 plugin updated with latest Python 3.12.1 SDK.
! (2024.01.02) PhysX 5 plugin updated with latest PhysX 5.3.1 SDK.
! (2024.01.02) gh_renderer.wait_for_gpu() implemented in OpenGL.
+ (2023.12.15) GPU monitoring plugin: added VRAM temperature sensor for AMD Radeon RDNA3 GPUs.
+ (2023.12.05) GPU monitoring plugin: added commercial name:
  - ASUS RTX 4060 Ti DUAL OC 8G M.2
  - EVGA RTX 3090 XC3 ULTRA HYBRID GAMING 24G
  - Gigabyte Aorus RTX 2070 Super
  - GIGABYTE RX 7800 XT Gaming OC 16G

Version 0.56.0.0 - 2023.12.03
* (2023.12.03) GPU monitoring plugin: fixed a minor bug in the initialization of the CPU name.
+ (2023.12.01) FFmpeg plugin: added video_get_rotation() to gh_av lib.
+ (2023.11.30) added imspinner_spinner_points_arc_bounce(), imspinner_spinner_herbert_balls_3d()
  and imspinner_spinner_rotate_segments_pulsar() to gh_imgui lib.
! (2023.11.30) updated with latest imspinner lib.
* (2023.11.27) fixed a bug in the artifact scanner in Vulkan.
The post GeeXLab 0.56 released (*** UPDATED: v0.56.2 + Linux 32-bit ***) first appeared on HackLAB.]]>
https://www.geeks3d.com/hacklab/20231203/geexlab-0-56-released/feed/ 0
GeeXLab and Python 3 on Linux https://www.geeks3d.com/hacklab/20200717/geexlab-and-python-3-on-linux/ https://www.geeks3d.com/hacklab/20200717/geexlab-and-python-3-on-linux/#respond Fri, 17 Jul 2020 14:31:58 +0000 https://www.geeks3d.com/hacklab/?p=1545 Here is a short post about how to use the Python 3 plugin on Linux. Depending on the Linux distribution / version, you can have Python 3.5, Python 3.6 or Python 3.8. Each version of Python has its own shared object file stored in /usr/lib/x86_x64-linux-gnu/ . For example with Linux Mint you have: – Python 3.5 with Linux Mint 18.3 (/usr/lib/x86_x64-linux-gnu/libpython3.5m.so.1.0) – Python 3.6 with … Continue reading GeeXLab and Python 3 on Linux »

The post GeeXLab and Python 3 on Linux first appeared on HackLAB.]]>

Python logo

Here is a short post about how to use the Python 3 plugin on Linux. Depending on the Linux distribution / version, you can have Python 3.5, Python 3.6 or Python 3.8. Each version of Python has its own shared object file stored in /usr/lib/x86_x64-linux-gnu/ . For example with Linux Mint you have:

– Python 3.5 with Linux Mint 18.3 (/usr/lib/x86_x64-linux-gnu/libpython3.5m.so.1.0)
– Python 3.6 with Linux Mint 19.3 (/usr/lib/x86_x64-linux-gnu/libpython3.6m.so.1.0)
– Python 3.8 with Linux Mint 20.0 (/usr/lib/x86_x64-linux-gnu/libpython3.8.so.1.0)

GeeXLab is compiled on Linux Mint 18.3 to keep the compatibility with the GLIBC 2.23. And the Python 3 plugin (stored in GeeXLab/dylibs/plugin_gxl_python3_x64.so) is linked with libpython3.5m.so.1.0. On Mint 18.3, the Python 3 plugin works fine. But on the latest Mint 20, it does not work anymore because libpython3.5m.so.1.0 is not found (which is normal). So a quick solution is to add a symbolic link pointing to the real Python lib in the plugins folder of GeeXLab. For example, on Mint 20, we can create a symlink called libpython3.5m.so.1.0 with (open a terminal in GeeXLab folder):

ln -s /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0 dylibs/libpython3.5m.so.1.0

I added in GeeXLab folder three scripts to update the symbolic link depending on your version of Linux / Python 3:
– python3_plugin_update_symlink_for_python35.sh
– python3_plugin_update_symlink_for_python36.sh
– python3_plugin_update_symlink_for_python38.sh

All scripts will create a symbolic link called libpython3.5m.so.1.0 in the plugins folder of GeeXLab that will make plugin_gxl_python3_x64.so happy!

The post GeeXLab and Python 3 on Linux first appeared on HackLAB.]]>
https://www.geeks3d.com/hacklab/20200717/geexlab-and-python-3-on-linux/feed/ 0
(Demo) How to Read Up-to-Date COVID-19 Data in Python 3 (Updated: 2021.09.14) https://www.geeks3d.com/hacklab/20200409/demo-how-to-read-up-to-date-covid-19-data-in-python-3/ https://www.geeks3d.com/hacklab/20200409/demo-how-to-read-up-to-date-covid-19-data-in-python-3/#respond Thu, 09 Apr 2020 18:05:32 +0000 https://www.geeks3d.com/hacklab/?p=1509 Downloads Python 3 Demopack Download Demo: geexlab-demopack-python3/general/03-covid19/main.xml GeeXLab Downloads Forum thread (EN)   If you wonder how to access to up-to-date data about new Coronavirus (COVID-19 or better, SARS-CoV-2 which is the official codename) cases, I found this simple to use Python package: COVID19Py (the github repository is available HERE). To install it, run the following command in a terminal (the pip executable must be … Continue reading (Demo) How to Read Up-to-Date COVID-19 Data in Python 3 (Updated: 2021.09.14) »

The post (Demo) How to Read Up-to-Date COVID-19 Data in Python 3 (Updated: 2021.09.14) first appeared on HackLAB.]]>

GeeXLab demo - How to Read Up-to-Date COVID-19 Data in Python 3



Downloads

 
If you wonder how to access to up-to-date data about new Coronavirus (COVID-19 or better, SARS-CoV-2 which is the official codename) cases, I found this simple to use Python package: COVID19Py (the github repository is available HERE).

To install it, run the following command in a terminal (the pip executable must be in the bin search path):

pip install COVID19Py

 
Alternatively, you can open a terminal in the C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\Scripts\ folder where the pip executable is stored.

Once installed, this tiny lib is really easy to use. The following code snippet shows how to read all important data in few Python lines:

import COVID19Py

covid19_jhu = COVID19Py.COVID19(data_source="jhu")
latest_jhu = covid19_jhu.getLatest()
locations_ALL = covid19_jhu.getLocations(rank_by='confirmed')

 
The COVID-19 cases data is read from the Johns Hopkins University Center for Systems Science and Engineering (JHU CSSE).

getLatest() returns the following dictionary:

{
'confirmed': 1511104, 
'deaths': 88338, 
'recovered': 0
}

 
getLocations() returns a big list of dictionaries, one dictionary for each location. Currently, 263 locations are returned by getLocations().

Here is the first entry (a dictionary) of the location list (I sorted by confirmed cases, that’s why the US are in top position…):

{
'id': 225, 
'country': 'US', 
'country_code': 'US', 
'country_population': 310232863, 
'province': '', 
'last_updated': '2020-04-09T16:25:21.803522Z', 
'coordinates': {'latitude': '37.0902', 'longitude': '-95.7129'}, 
'latest': {'confirmed': 429052, 'deaths': 14695, 'recovered': 0}
}

 
I coded a demo with GeeXLab that displays all COVID-19 cases data by location. COVID-19 confirmed cases can be visualized in 2D or 3D.

The demo requires the latest GeeXLab 0.30.0 (few bugs have been fixed in the gh_imgui library in the Python plugin).

Download the Python 3 demopack and load the geexlab-demopack-python3/general/03-covid19/main.xml demo in GeeXLab. GeeXLab 0.30+ for Windows comes with the COVID19Py package so you can directly run the demo.

2D view:
GeeXLab demo - How to Read Up-to-Date COVID-19 Data in Python 3

 
3D view:
GeeXLab demo - How to Read Up-to-Date COVID-19 Data in Python 3

 
This demo can be improved by storing COVID-19 data in a SQLite3 database and doing some interesting stats (like changes between days).

 

Update (2020.04.12): 2D mode: XBar and YBar

YBar:
GeeXLab demo - How to Read Up-to-Date COVID-19 Data in Python 3

XBar:
GeeXLab demo - How to Read Up-to-Date COVID-19 Data in Python 3

 

Update (2020.04.17): 2D mode: YBar with ImGui

YBar using ImGui progress bar
gh_imgui.progress_bar() function is used to represent confirmed cases. This solution is simpler to code because text alignment on the progress bar is handled by ImGui.

GeeXLab demo - How to Read Up-to-Date COVID-19 Data in Python 3

 

Update (2021.09.14): graph scaling

Since the first version of the demo, Covid19 cases have exploded. Here is a new version of the demo with a scaling factor you can adjust to display properly the graph bars.

GeeXLab demo - How to Read Up-to-Date COVID-19 Data in Python 3

The post (Demo) How to Read Up-to-Date COVID-19 Data in Python 3 (Updated: 2021.09.14) first appeared on HackLAB.]]>
https://www.geeks3d.com/hacklab/20200409/demo-how-to-read-up-to-date-covid-19-data-in-python-3/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
Python 3 and OpenCV Part 2: How to Load an Image with OpenCV (and render it with GeeXLab) https://www.geeks3d.com/hacklab/20200306/python-3-and-opencv-part-2-how-to-load-an-image-with-opencv-and-render-it-with-geexlab/ https://www.geeks3d.com/hacklab/20200306/python-3-and-opencv-part-2-how-to-load-an-image-with-opencv-and-render-it-with-geexlab/#respond Fri, 06 Mar 2020 17:01:28 +0000 https://www.geeks3d.com/hacklab/?p=1498 Downloads: Python 3 Demopack Download Demo: geexlab-python3-demopack/opencv/02-image/main.xml GeeXLab Downloads Forum thread (EN)   This second tutorial will show you how to load an image with OpenCV and how to convert it to a GeeXLab texture for rendering. An OpenCV image is a NumPy array (numpy.ndarray). NumPy is one of the most important libraries for scientific computing in Python. It provides all you need to work … Continue reading Python 3 and OpenCV Part 2: How to Load an Image with OpenCV (and render it with GeeXLab) »

The post Python 3 and OpenCV Part 2: How to Load an Image with OpenCV (and render it with GeeXLab) first appeared on HackLAB.]]>

GeeXLab - Python 3 - How to load and image with OpenCV


Downloads:


 
This second tutorial will show you how to load an image with OpenCV and how to convert it to a GeeXLab texture for rendering.

An OpenCV image is a NumPy array (numpy.ndarray). NumPy is one of the most important libraries for scientific computing in Python. It provides all you need to work with multidimensional arrays. This article is not a tutorial about NumPy. I added some links about Numpy at the end of the article.

To load an image with OpenCV, we use the imread() function:

import cv2

demo_dir = gh_utils.get_demo_dir() 		
cv_image = cv2.imread(demo_dir + 'data/kool-image.jpg', cv2.IMREAD_COLOR)

The size of the image can be retrieved with:

im_height, img_width = cv_image.shape[0:2]

Now let’s see how to create a regular GeeXLab texture from this OpenCV image.

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
tex_image = gh_texture.create_2d(img_width, img_height, PF_U8_BGR)

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

It’s done! We have now an GeeXLab texture filled with the data of an OpenCV image. It’s a detail but it can save you some time to know that OpenCV stores image pixels in BGR format…

The demo displays two images: the normal image and a smaller version of the same image. The smaller version has been created with the OpenCV resize() function:

img2_width = int(round(img_width/3))
img2_height = int(round(img_height/3))
cv_image2 = cv2.resize(cv_image,(img2_width, img2_height),interpolation=cv2.INTER_LINEAR) 

Another useful function is copyMakeBorder(). This function adds a border to an image. Here is the way to add a red border of 10 pixels:

cv_image2 = cv2.copyMakeBorder(cv_image2,
  top=10,
  bottom=10,
  left=10,
  right=10,
  borderType=cv2.BORDER_CONSTANT,
  value=(0, 0, 255))

For the color value, keep in mind that the pixel format is BGR…

Here is the demo:


GeeXLab - Python 3 - How to load and image with OpenCV

 
Links:

The post Python 3 and OpenCV Part 2: How to Load an Image with OpenCV (and render it with GeeXLab) first appeared on HackLAB.]]>
https://www.geeks3d.com/hacklab/20200306/python-3-and-opencv-part-2-how-to-load-an-image-with-opencv-and-render-it-with-geexlab/feed/ 0
Python 3 and OpenCV Part 1: How to Install OpenCV for Python and How to Display the OpenCV Version https://www.geeks3d.com/hacklab/20200306/python-3-and-opencv-part-1-how-to-install-opencv-for-python-and-how-to-display-the-opencv-version/ https://www.geeks3d.com/hacklab/20200306/python-3-and-opencv-part-1-how-to-install-opencv-for-python-and-how-to-display-the-opencv-version/#respond Fri, 06 Mar 2020 11:52:10 +0000 https://www.geeks3d.com/hacklab/?p=1497 Python 3 Demopack Download Demo: geexlab-demopack-python3/opencv/01-version/main.xml GeeXLab Downloads Forum thread (EN)   Here is the first article of a series a four small tutorials about OpenCV and Python 3 with GeeXlab. What is OpenCV ? OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and … Continue reading Python 3 and OpenCV Part 1: How to Install OpenCV for Python and How to Display the OpenCV Version »

The post Python 3 and OpenCV Part 1: How to Install OpenCV for Python and How to Display the OpenCV Version first appeared on HackLAB.]]>

GeeXLab - Python 3 - OpenCV version



 
Here is the first article of a series a four small tutorials about OpenCV and Python 3 with GeeXlab.

What is OpenCV ?

OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products. Being a BSD-licensed product, OpenCV makes it easy for businesses to utilize and modify the code.

The library has more than 2500 optimized algorithms, which includes a comprehensive set of both classic and state-of-the-art computer vision and machine learning algorithms. These algorithms can be used to detect and recognize faces, identify objects, classify human actions in videos, track camera movements, track moving objects, extract 3D models of objects, produce 3D point clouds from stereo cameras, stitch images together to produce a high resolution image of an entire scene, find similar images from an image database, remove red eyes from images taken using flash, follow eye movements, recognize scenery and establish markers to overlay it with augmented reality, etc.

source


OpenCV logo

 
The nice thing with OpenCV is that it comes with a complete Python 3 library.

The latest GeeXlab 0.29.17.0 for Windows 64-bit comes with Python 3.8.2 and OpenCV 4.2.0. So if you don’t have Python 3 on your system, you can still run Python 3 demos.

But if you want to use your own Python 3 installation, you can tell GeeXLab to use it. There are two ways:

1/ with a command line option: /python3_home="......". On Windows you should have something like:

GeeXLab /python3_home="C:/Users/YOUR_NAME/AppData/Local/Programs/Python/Python38/"

 
2/ with the python3_home attribute in the init0.xml (in GeeXLab root folder) file:

<glslhacker_init
    demofile=""
    python3_home="C:/Users/YOUR_NAME/AppData/Local/Programs/Python/Python38/"
/>

On Linux and Raspberry Pi, GeeXLab is not shipped with a Python 3 installation. It uses the Python 3 that comes with the system.

If you want to use your own Python 3 installation, let’s see how to install OpenCV for Python.

Before installing OpenCV for Python, be sure to have the pip utility. pip is the package installer for Python. If you don’t have pip, don’t worry, you can easily install it. I shipped the get-pip.py script in the Python 3 demopack. This script can be also downloaded from this page. To install pip, run the following command:

python get-pip.py

Now you should have pip installed. Now let’s install OpenCV for Python.

You can do this in command line with:

pip install opencv-python

OpenCV for Python should be now installed.

The boring task of installing OpenCV for Python is now behind us.

From now on, I supposed that Python 3 and OpenCV are ready to be used by GeeXLab.

The first demo is really simple. The goal is to check that OpenCV is installed and to display the version of OpenCV:


GeeXLab - Python 3 - OpenCV version

 
The first thing to do in a Python / OpenCV demo is to import OpenCV:

import cv2

The version of OpenCV can be read with cv2.__version__:

opencv_version = cv2.__version__
(major, minor, patch) = cv2.__version__.split(".")
opencv_version_major = int(major, base=10)
opencv_version_minor = int(minor, base=10)
opencv_version_patch = int(patch, base=10)

That’s all.

In the FRAME script, OpenCV and Python 3 versions are displayed like this (blue and yellow texts):

...

libfont2_print(font_b, 10, y_offset, 0.2, 0.7, 1.0, 1, "Python version: %d.%d.%d" %(sys.version_info.major, sys.version_info.minor, sys.version_info.micro))

y_offset = y_offset + 30
libfont2_print(font_b, 10, y_offset, 1.0, 1.0, 0.0, 1, "OpenCV version: %d.%d.%d" % (opencv_version_major, opencv_version_minor, opencv_version_patch))

...

Python and OpenCV versions are displayed in the ImGui window with:

...

gh_imgui.text_wrapped("Python " + str(sys.version))
gh_imgui.spacing()
gh_imgui.spacing()
gh_imgui.text_wrapped("OpenCV " + str(cv2.__version__))

...

 
Next article: how to load an image with OpenCV and how to display it with GeeXLab…

The post Python 3 and OpenCV Part 1: How to Install OpenCV for Python and How to Display the OpenCV Version first appeared on HackLAB.]]>
https://www.geeks3d.com/hacklab/20200306/python-3-and-opencv-part-1-how-to-install-opencv-for-python-and-how-to-display-the-opencv-version/feed/ 0
GeeXLab 0.29.17 released for Windows, Linux and Raspbian https://www.geeks3d.com/hacklab/20200306/geexlab-0-29-17-released-for-windows-linux-and-raspbian/ https://www.geeks3d.com/hacklab/20200306/geexlab-0-29-17-released-for-windows-linux-and-raspbian/#respond Fri, 06 Mar 2020 10:28:26 +0000 https://www.geeks3d.com/hacklab/?p=1496 Downloads GeeXLab for Windows 64-bit GeeXLab for Linux 64-bit GeeXLab for Raspbian Buster+ All GeeXLab Downloads Feedback thread / Forum (EN) 1 – Release Notes GeeXLab 0.29.17 improves the support of Python and comes with a handy function that allows to use a NumPy array (np.array) as a texture. This function is like a bridge between NumPy and GeeXLab. Why NumPy? Because some popular Python … Continue reading GeeXLab 0.29.17 released for Windows, Linux and Raspbian »

The post GeeXLab 0.29.17 released for Windows, Linux and Raspbian first appeared on HackLAB.]]>

GeeXLab: 3D programming and prototyping for Windows, Linux, macOS, RaspberryPi


Downloads


1 – Release Notes

GeeXLab 0.29.17 improves the support of Python and comes with a handy function that allows to use a NumPy array (np.array) as a texture. This function is like a bridge between NumPy and GeeXLab. Why NumPy? Because some popular Python libs like OpenCV, return NumPy images (a 2D numerical array).

In the following example, myTex is a regular GeeXLab texture and npImg is a Numpy image. We can update the texture with the new update_gpu_memory_from_numpy_img() function of the gh_texture lib:

gh_texture.update_gpu_memory_from_numpy_img(myTex, npImg)

I will start a series of Python + OpenCV articles and this function will be the core of some demos.

On Windows, the Python plugin has been updated with Python 3.8.2 that has been released few days ago. And GeeXLab for Windows comes with some popular Python libraries (NumPy, OpenCV, Scapy or feedreader) in the Python 3 site-packages folder.

On Linux, the Python 3 plugin (dylibs/plugin_gxl_python3_x64.so) is now linked to a shared object named libpython_3.so. libpython_3.so is a symlink (symbolic link) and points either to Python 3.5 shared object (on Linux Mint 18.3 for example) or to Python 3.6 (on Linux Mint 19.3). By default, libpython_3.so points to Python 3.5. The libpython_3.so should be deleted before the first launch of GeeXLab. Once deleted, it can be recreated to point to the correct version of Python using one of the following scripts (in GeeXLab folder):

– python3_plugin_update_symlink_for_python35.sh :

#!/bin/bash          
ln -s /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 dylibs/libpython_3.so

– python3_plugin_update_symlink_for_python36.sh :

#!/bin/bash          
ln -s /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0 dylibs/libpython_3.so

You can also link to Python 3.7 or 3.8. That should work. Sorry for that working but Python support on Linux is a bit messy.

Raspbian Buster (Raspberry Pi) is shipped with Python 3.7. So on Raspbian, GeeXLab uses Python 3.7.

 

2 – Changelog

This changelog is intended for all versions of GeeXLab.

Full changelog from beginning of time is available HERE.

Version 0.29.17.0 - 2020.03.05
! (2020.03.05) [Linux] the Python 3 plugin is linked with libpython_3.so, a smylink 
  towards the real Python shared object.
+ (2020.03.04) [Windows] Python 3 plugin updated plugin with Python 3.8.2.
! (2020.03.04) [Python 2/3] fixed a memory leak when a script was in live coding mode.
+ (2020.03.02) added get_num_strings(), get_string_num_chars(), set_string_char_position_offset()
  and set_string_char_color_factor() to gh_font lib.
+ (2020.02.27) [Python 3] added update_gpu_memory_from_numpy_img() to gh_texture lib.
+ (2020.02.27) [Windows] added feedreader, scapy, numpy and OpenCV in the Python 3 distribution 
  that comes with GeeXLab ({GeeXLab}/python3/Lib/site-packages/).
+ (2020.02.25) [Python] added  libfont2 in Python libs ({GeeXLab}/libs/python/libfont/).
! (2020.02.27) updated SMOL-V support with latest version.
+ (2020.02.21) added uniform_3x3f() to gh_gpu_program lib.
+ (2020.02.21) added math_from_to_rotation_matrix3x3() to gh_utils.
+ (2020.02.21) [PRO version] added check_for_new_version() to gh_utils.
The post GeeXLab 0.29.17 released for Windows, Linux and Raspbian first appeared on HackLAB.]]>
https://www.geeks3d.com/hacklab/20200306/geexlab-0-29-17-released-for-windows-linux-and-raspbian/feed/ 0
GeeXLab 0.28.1 Released for Windows, Linux, macOS, Raspberry Pi and Tinker Board https://www.geeks3d.com/hacklab/20190515/geexlab-0-28-1-released-for-windows-linux-macos-raspberry-pi-and-tinker-board/ https://www.geeks3d.com/hacklab/20190515/geexlab-0-28-1-released-for-windows-linux-macos-raspberry-pi-and-tinker-board/#respond Wed, 15 May 2019 13:34:41 +0000 https://www.geeks3d.com/hacklab/?p=1424 GeeXLab Downloads Feedback thread / Forum (EN)   1 – Release Notes Yeah! GeeXLab is finally available on all supported platforms: Windows 64-bit, Linux 64-bit, macOS, Raspberry Pi and Tinker Board. The last time I updated GeeXLab on SBCs (SBC = Single Board Computer like the Raspberry Pi or the Tinker Board) was nearly one year ago, so it was time. GeeXLab 0.28.1 has been … Continue reading GeeXLab 0.28.1 Released for Windows, Linux, macOS, Raspberry Pi and Tinker Board »

The post GeeXLab 0.28.1 Released for Windows, Linux, macOS, Raspberry Pi and Tinker Board first appeared on HackLAB.]]>

GeeXLab 0.28.1 on ASUS Tinker Board



 

1 – Release Notes

Yeah! GeeXLab is finally available on all supported platforms: Windows 64-bit, Linux 64-bit, macOS, Raspberry Pi and Tinker Board. The last time I updated GeeXLab on SBCs (SBC = Single Board Computer like the Raspberry Pi or the Tinker Board) was nearly one year ago, so it was time.

GeeXLab 0.28.1 has been developed on Windows 10 64-bit v1809, Linux Mint 19.1 64-bit MATE edition, macOS 10.14 Mojave, the latest Raspbian (2019-04-08 with kernel 4.14) and on the latest TinkerOS 2.0.8. Then, it should work properly on these environments.

GeeXLab 0.28.1 does not bring new big features, it’s more a maintenance / update release. ImGui and SQLite3 have been updated to their latest versions (respectively 1.70 and 3.28.0).

ImGui 1.70 adds an handy function to set the size of the next item: gh_imgui.set_next_item_width(). This function replaces gh_imgui.push_item_width() and gh_imgui.pop_item_width().

With previous GeeXLab you could set the size of a slider with the following code:

gh_imgui.push_item_width(200)
x = gh_imgui.slider_1f("##x_slider", x,   min_value, max_value,   power)
gh_imgui.pop_item_width()

Now you can do:

gh_imgui.set_next_item_width(200)
x = gh_imgui.slider_1f("##x_slider", x,   min_value, max_value,   power)

 
push_item_width() and pop_item_width() are still useful if you want to set the size of several items. But for one item, set_next_item_width() is there.

 
A new core plugin (a core plugin is a plugin that is embedded in GeeXLab like the Lua one) has been added to load glTF file formats. A new function has been added in gh_model lib to load .glTF directly: create_from_file_loader_gltf(). glTF files can now be loaded by the ASSIMP plugin or by this new plugin.

 
The Python 3 support has been added on Raspberry Pi and Tinker Board. On both platforms, the Python 3 plugin is linked against Python 3.5 libraries. Here is a quick overview of GeeXLab Python 3 support:
– Windows: linked with Python 3.7.3
– Linux: linked with Python 3.6 (shipped with Linux Mint 19.1)
– macOS: linked with Python 3.7.3
– Raspberry Pi: linked with Python 3.5
– Tinker Board: linked with Python 3.5


Python programming language

 
The Bullet3 physics engine has been updated on ALL platforms to its very latest version (2.88 / 2019.05.14). Bullet3 is now identical on all versions of GeeXLab.

 
Simple Bullet3 demo on Raspberry Pi (the demo is available in the Learn Pack):
GeeXLab 0.28.1 on Raspberry Pi - Bullet3 demo

 

2 – Changelog

Full changelog from beginning of time is available HERE.

Version 0.28.1.0 - 2019.05.14
. (2019.05.14) recompilation for all platforms, minor bugs fixed.
! (2019.05.14) updated Bullet3 plugin with latest version 2.88 
  on macOS, Raspberry Pi and Tinker Board.
+ (2019.05.14) added Python 3 support on Raspberry Pi and Tinker Board.
+ (2019.05.13) added create_box_8v() to gh_mesh.
+ (2019.05.12) added create_from_file_loader_gltf() to gh_model.
! (2019.05.09) added automatic call to ImGui terminate function 
  at the end of a demo. Useful if you forget to explicitly call it
  in the TERMINATE script...
+ (2019.05.08) added set_next_item_width() to gh_imgui lib.
! (2019.05.08) updated ImGui with latest version 1.70.
! (2019.05.08) updated SQLite3 with latest version 3.28.0.
The post GeeXLab 0.28.1 Released for Windows, Linux, macOS, Raspberry Pi and Tinker Board first appeared on HackLAB.]]>
https://www.geeks3d.com/hacklab/20190515/geexlab-0-28-1-released-for-windows-linux-macos-raspberry-pi-and-tinker-board/feed/ 0
How to use feedparser and Atoma to read RSS feeds in Python 3 https://www.geeks3d.com/hacklab/20190118/how-to-use-feedparser-and-atoma-to-read-rss-feeds-in-python-3/ https://www.geeks3d.com/hacklab/20190118/how-to-use-feedparser-and-atoma-to-read-rss-feeds-in-python-3/#respond Fri, 18 Jan 2019 07:48:12 +0000 https://www.geeks3d.com/hacklab/?p=1406 How to use feedparser and Atoma to read RSS feeds in Python 3

The post How to use feedparser and Atoma to read RSS feeds in Python 3 first appeared on HackLAB.]]>

GeeXLab demo - RSS feed reader with Python 3 and feedparser and Atoma



Today, let’s see how to parse an RSS feed in Python 3 with two RSS feed parser libraries:
feedparser
Atoma

Two GeeXLab demos (one with feedparser, and another one with Atoma) are available in the Python 3 demopack in the rss-reader/01-rss-reader-feedparser/ and rss-reader/02-rss-reader-atoma/ folders.

I tested both libraries on Windows 10 64-bit (v1809) with latest Python 3.7.2. These demos should also work on Linux but I didn’t tested that aspect. Feel free to post a comment here or in the forum if you encounter a problem on Linux (as well as on Windows…).

 

1 – feedparser


GeeXLab demo - RSS feed reader with Python 3 and feedparser

 
feedparser seems to be the most popular feed parser library. feedparser can parse Atom and RSS feeds in Python 3. You can download feedparser from THIS REPO.

To install feedparser, unzip the repo, open a terminal in the repo folder and type:

python setup.py install

 
Now that feedparser is installed, here is a basic use of that library:

import feedparser
url= "https://feeds2.feedburner.com/TheGeeksOf3d"
feed = feedparser.parse(url)

We have parsed Geeks3D RSS feed!

Now let’s display it by looping over all feed entries. In this code snippet, are displayed only the date, title and link of a feed entry:

for post in feed.entries:
  date = "(%d/%02d/%02d)" % (post.published_parsed.tm_year,\
    post.published_parsed.tm_mon, \
    post.published_parsed.tm_mday)
  print("post date: " + date)
  print("post title: " + post.title)
  print("post link: " + post.link)

 
feedparser documentation is available HERE.





 

2 – Atoma


GeeXLab demo - RSS feed reader with Python 3 and Atoma

 
Atoma is another library for Python 3 that deals with RSS feed parsing. Like feedparser, Atoma is simple to install and use. You can download Atoma from THIS REPOSITORY.

To install Atoma, unzip the repo, open a terminal in the repo folder and type:

python setup.py install

An optional but useful library to install alongside Atoma is Requests. Requests can be downloaded from THIS REPO.

As for other libs, unzip the repo, open a terminal in the repo folder and type:

python setup.py install

 

Now that Atoma and Requests are installed, let’s look at how to read the RSS feed of GeeXLab blog:

import atoma, requests
feed_name = "GeeXLab blog"
url = "https://www.geeks3d.com/hacklab/?feed=rss2"
response = requests.get(url)
feed = atoma.parse_rss_bytes(response.content)

We have parsed GeeXLab RSS feed! We are the best!

Now let’s see how to display the feeds:

for post in feed.items:
  date = post.pub_date.strftime('(%Y/%m/%d)')
  print("post date: " + date)
  print("post title: " + post.title)
  print("post link: " + post.link)

As you can see, displaying feeds with Atoma is pretty similar to feedparser. We are fortunate!


A note on GeeXLab demos on Windows. GeeXLab for Windows comes with a Python 3 installation. If you want to use your Python 3 installation (usually in C:/Users/YOUR_NAME/AppData/Local/Programs/Python/Python37/) with GeeXLab, you have to specify where is located the Python home. You can start GeeXLab with the /python3_home command line option:

start GeeXLab /python3_home="C:/Users/YOUR_NAME/AppData/Local/Programs/Python/Python37/"

A .bat file is available in GeeXLab root folder (start_set_python_home.bat). Edit the Python 3 home path and run it.

The post How to use feedparser and Atoma to read RSS feeds in Python 3 first appeared on HackLAB.]]>
https://www.geeks3d.com/hacklab/20190118/how-to-use-feedparser-and-atoma-to-read-rss-feeds-in-python-3/feed/ 0