Skip to content

Instantly share code, notes, and snippets.

View omiq's full-sized avatar

Chris Garrett omiq

View GitHub Profile
@omiq
omiq / qt-viewer.py
Created June 11, 2018 21:51
Image viewer desktop app in python
import os
import glob
import sys
import subprocess
from PySide2.QtWidgets import*
from PySide2.QtGui import*
from PySide2 import QtCore, QtGui
# initialise variables
@omiq
omiq / mouse.py
Created June 9, 2018 22:03
emulate a mouse using the circuit playground express accelerometer and HID over USB
# for delay
import time
# for mouse emulation
from adafruit_hid.mouse import Mouse
# the cpx
import board
# buttons
@omiq
omiq / recognise.py
Created June 8, 2018 20:04
Image recognition demo. Set filename as first parameter.
import sys
import numpy as np
from keras.preprocessing import image
from keras.applications import resnet50
# Load the Keras image database
model = resnet50.ResNet50()
# Load the picture as 224x224 (maximum size this model can cope with)
picture = image.load_img(sys.argv[1], target_size=(224, 224))
@omiq
omiq / select.py
Created May 31, 2018 22:41
Example of selecting files in the filemanager of mac, windows and linux
import sys
import subprocess
def select_file(path):
if sys.platform == 'darwin':
subprocess.run(['open', '-R', path])
elif sys.platform == 'linux':
subprocess.run(['nautilus', path])
@omiq
omiq / qt-example.py
Created May 31, 2018 18:16
example of Python PySide2 Qt viewing an image
import sys
from PySide2.QtWidgets import*
from PySide2.QtGui import*
from PySide2 import QtCore
# example event handler
def quit_app():
global application
print("Quit!")
@omiq
omiq / cpx-motors.py
Created May 30, 2018 18:27
Motors on CPX with Python
from busio import I2C
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import motor
import board
import time
# seesaw object
i2c = I2C(board.SCL, board.SDA)
seesaw = Seesaw(i2c)
@omiq
omiq / viewer.py
Created May 28, 2018 18:26
Basic Python image viewer
import os
from PIL import Image
import glob
import tkinter
from PIL import ImageTk
# process the interaction
def event_action(event):
print(repr(event))
@omiq
omiq / gif-text.py
Created May 25, 2018 17:12
generate animated gif with python
# OS modules
import os
import shutil
# Image modules
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
# create/delete our temp files folder
@omiq
omiq / joy-camera.py
Created April 13, 2018 19:47
Controlling pan-tilt with game pad on Raspberry Pi with Python
from evdev import InputDevice
import pigpio
pi = pigpio.pi()
tilt = 17
pan = 27
x = 1250
@omiq
omiq / joy-camera.py
Created April 13, 2018 19:31
Controlling pan-tilt with game pad
import pigpio
# servo/gpio control
pi = pigpio.pi()
# choose your pins
tilt = 17
pan = 27
# center the servos