Skip to content

Instantly share code, notes, and snippets.

View pdeutsch's full-sized avatar

PDeutsch pdeutsch

  • MN
View GitHub Profile
@pdeutsch
pdeutsch / show_green_rect.py
Last active March 3, 2020 02:54
Show green blobs with rectangles around three quadrants of target
import cv2
import numpy as np
import math
import argparse
res = np.array([0])
# the following will:
# - find a green blob
# - find a contour around it
@pdeutsch
pdeutsch / show_green.py
Created January 31, 2020 16:32
Show green in video
import cv2
import numpy as np
def show_frame(img, mask, cntr):
cv2.imshow('orig', img)
cv2.imshow('mask', mask)
ch = cv2.waitKey(5) & 0xff
if ch == ord('s'):
cv2.imwrite(f"frame_{cntr:03d}.png", img)
if ch == 27:
import cv2
import numpy as np
import math
# create an array of points in the shape of a hexagon
def make_hex_shape():
pts = []
for ang in range(0, 355, 60):
ang_r = math.radians(ang)
@pdeutsch
pdeutsch / DoubleFormatting.java
Created March 19, 2019 18:01
A test to determine the fastest way to format strings and doubles for logging. See the JavaDoc below for more details.
import com.google.common.base.Stopwatch;
import java.io.*;
import java.text.DecimalFormat;
import java.util.concurrent.TimeUnit;
/**
* This code attempts several different methods of creating and printing a string similar to:
* test1: 4379747.584; test2: 4379747.684; test3: 4379747.784
*
@pdeutsch
pdeutsch / DeleteOldFiles.java
Created March 2, 2019 18:12
Deletes old *.bag files, keeps the last 3
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
class DeleteOldFiles {
public static void main(String[] args) {
deleteFiles();
}
@pdeutsch
pdeutsch / ThreadedFlask.py
Last active February 28, 2019 23:15
Example of running OpenCV camera processing in one thread and Flask in another
# This application requires that you install Flask (pip install Flask)
# and OpenCV.
# It will start the OpenCV image processing in the background thread,
# and start then start the Flask app. The OpenCV thread will read from
# the camera and populate the img variable with the latest image capture.
#
# Opening http://localhost:7070 in your browser should show the latest
# image capture. Refreshing the page will show the newest image.
import cv2

I installed pyv4l2 on the Rasperry Pi. https://pypi.org/project/pyv4l2/

It failed at first, but I did a pip3 install Cython first and then pip3 install pyv4l2 installed correctly.

There are four methods available on the Control object, as shown below. I also executed the get_controls() method and you can see that this dumps out a data structure containing all the possible settings, their names, values, default values, control ID, and other configuration parameters.

>>> from pyv4l2.control import Control
@pdeutsch
pdeutsch / keybase.md
Last active November 21, 2018 01:20
Keybase Gist

Keybase proof

I hereby claim:

  • I am pdeutsch on github.
  • I am pete_deutsch (https://keybase.io/pete_deutsch) on keybase.
  • I have a public key ASCg24tH9OKcmkzx6T0eQGxZmWoRWaMjht2-fnAXNGZvIAo

To claim this, I am signing this object:

public class PPosTest {
private static final double MIN_TURN_SPEED = 0.1;
private static final double kP_TURN = -0.01; //todo: tune value
public static void main(String[] args) {
PPosTest test = new PPosTest();
for (double targetVelocity = 0.15; targetVelocity < 0.31; targetVelocity += 0.1) {
for (int i = 0; i < 10; i++) {
test.execute(targetVelocity, 0.0, (double)i * 3.0);
import java.util.ArrayList;
import java.util.List;
public class MatrixTest {
static class Point {
double x, y;
Point(double x, double y) { this.x = x; this.y = y; }
double[] asArray() { return new double[] { x, y }; }
public String toString() { return String.format("[%.2f, %.2f]", x, y); }
}