Skip to content

Instantly share code, notes, and snippets.

@burrussmp
burrussmp / gist:09e6d7d82cd144d8939675396c5fa753
Created March 30, 2020 05:23
A simple raspberry pi class for controlling the PWM GPIO pins of the Raspberry Pi 3
import pigpio
import RPi.GPIO as GPIO
class PWM:
def __init__(self):
self.pi = pigpio.pi()
self.freq = 100
self.steering = 0
self.acceleration = 0
self.gpioPinAcceleration = 18
@burrussmp
burrussmp / gist:7fcb0bf49c5dd8e0672afe16e733c06a
Last active March 30, 2020 06:36
Sending a csv file remotely to google drive
def sendToGoogleDrive(fileName,filePath,pathToClientSecrets="/PATH/TO/credentials.json"):
gauth = GoogleAuth()
gauth.LoadClientConfigFile(pathToClientSecrets) # <-----
drive = GoogleDrive(gauth)
folder_id = 'XXXX' // example .../folders/XXXX or ..../folders/13vovGVWKWz1KvFmBFwjxIMCT5dE-WFSx
file1 = drive.CreateFile({
'title': 'data.csv',
"mimeType": "text/csv",
@burrussmp
burrussmp / server.py
Last active April 26, 2020 19:38
A simply python server
import http.server
import socketserver
class Handler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/data': # handle any GET requests to /data
pass
elif self.path == '/annotation':# handle any GET requests to /annotation
pass
def do_POST(self): # handle general post event
import cv2
import numpy as np
def calculate_hull(img,sensitivity=0.25):
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
corners = cv2.goodFeaturesToTrack(gray, 100, sensitivity, 10)
corners = np.int0(corners)
hull = cv2.convexHull(corners)
return hull
def create3DFaces(sideHull,frontHull):
sideHull = normalize(sideHull)
frontHull = normalize(frontHull)
sideHull = addZAxis(sideHull)
frontHull = addZAxis(frontHull)
frontHull = rotate_by_90(frontHull)
frontHull,sideHull,hull_back = match_front_face(frontHull,sideHull)
faces = construct_faces(frontHull,hull_back)
faces = scale_down_faces(faces)
return faces
@burrussmp
burrussmp / getMesh.py
Last active April 26, 2020 20:25
A GET handler to stringify a list of faces where each element in the list is a set of points that define the face in a clockwise winding order
def get_mesh(self):
if processor.ready_to_send():
faces = processor.get_faces()
"""Respond to a GET request."""
self.send_response(200)
self.send_header("Content-type", "text")
self.end_headers()
for i in range(len(faces)):
self.wfile.write("N".encode())
self.wfile.write(str(len(faces[i])).encode())
@burrussmp
burrussmp / handleImagePostRequest.py
Created April 26, 2020 20:32
A POST request handler to parse and receive a PNG image
def deal_post_data(self):
ctype, pdict = cgi.parse_header(self.headers['Content-Type'])
pdict['boundary'] = bytes(pdict['boundary'], "utf-8")
pdict['CONTENT-LENGTH'] = int(self.headers['Content-Length'])
if ctype == 'multipart/form-data':
form = cgi.FieldStorage( fp=self.rfile, headers=self.headers, environ={'REQUEST_METHOD':'POST', 'CONTENT_TYPE':self.headers['Content-Type'], })
# typeOfImage = form["Type"].value + '.png'
bbox = {
'x':int(form["x"].value),
'y':int(form["y"].value),
@burrussmp
burrussmp / sendImageServer.cs
Last active April 26, 2020 21:08
c# code to capture image from unity
IEnumerator TakePhoto(string type) // Start this Coroutine on some button click
{
// NOTE - you almost certainly have to do this here:
yield return new WaitForEndOfFrame();
Texture2D tex = new Texture2D(Screen.width, Screen.height,TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
tex.Apply();
@burrussmp
burrussmp / getFaceData.cs
Last active April 26, 2020 21:10
GET face data from server and parse it into a list
UnityWebRequest www = UnityWebRequest.Get("http://SERVERIP:PORT/data");
yield return www.SendWebRequest();
Debug.Log(www.responseCode);
if(www.isNetworkError || www.isHttpError || www.responseCode == 500) {
GameObject myObject = GameObject.Find("ARCamera");
myObject.GetComponent<Buttons>().showError("Need to Capture Front and Side!");
yield return new WaitForSeconds(3);
myObject.GetComponent<Buttons>().clearError();
}
@burrussmp
burrussmp / DetectChanges.cs
Last active April 26, 2020 21:19
Vuforia handle detection of image target
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
Debug.Log("Detected");