Skip to content

Instantly share code, notes, and snippets.

View heaversm's full-sized avatar

Mike Heavers heaversm

View GitHub Profile
@heaversm
heaversm / motion-face-selfiecam.js
Last active January 20, 2023 00:00
Face Detection Automatic Selfie Cam using React Native and Expo
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Camera, Permissions, FaceDetector, DangerZone } from 'expo';
export default class CameraExample extends React.Component {
static defaultProps = {
countDownSeconds: 5,
motionInterval: 500, //ms between each device motion reading
motionTolerance: 1, //allowed variance in acceleration
cameraType: Camera.Constants.Type.front, //front vs rear facing camera
// Copyright (c) 2018 ml5
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
/* ===
ml5 Example
Creating a regression extracting features of MobileNet. Build with p5js.
=== */
@heaversm
heaversm / trimet-arrivals-by-stop
Created December 13, 2018 23:34
Query the Portland Oregon Trimet Arrivals by Stop
const $arrivals = $('.arrivals');
let arrivalInterval;
window.onload = function(){
getArrivals();
pollForArrivals();
}
pollForArrivals = function(){
arrivalInterval = setInterval(getArrivals,60000);
@heaversm
heaversm / trimet-next-arrival.ino
Created December 14, 2018 00:47
Getting the arrival API data for a specific stop on the Portland Trimet bus network, and lighting up an LED strip with the number of minutes before a bus arrives
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <TimeLib.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <Adafruit_NeoPixel.h>
//WIFI
const char* ssid = "[MY_SSID]";
@heaversm
heaversm / OpenCvCameraManager.h
Created March 6, 2019 19:47
opencvcameramanager header
#import <React/RCTViewManager.h>
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <opencv2/videoio/cap_ios.h>
#import "ChordCodeLocator.hpp"
#import "RNTUIImageView.h"
using namespace cv;
@interface OpenCvCameraManager : RCTViewManager<CvVideoCameraDelegate>
#import "OpenCvCameraManager.h"
#import <React/RCTBridge.h>
#import <opencv2/videoio/cap_ios.h>
using namespace cv;
@implementation OpenCvCameraManager
@synthesize camera, img, cameraId;
@heaversm
heaversm / undoArray.js
Created March 10, 2019 00:05
Undo Array Troubleshooting
let data = {}; // Global object to hold results from the loadJSON call
let shapes = []; // Global array to hold all shape arrays of coords
let mousePressedCoords = [];
let mouseReleasedCoords = [];
let isMousePressed = false;
let marqueeIsActive = false; //true when shift key selected
let closestShapeIndex;
let closestCoordIndex;
let mouseMovedX, mouseMovedY, mouseStartX, mouseStartY;
let selectedPoints = [];
@heaversm
heaversm / openCV-portait-camera-android.java
Last active March 29, 2024 18:30
Renders openCV's camera in portrait mode on android - to be placed in `CameraBridgeViewBase.java`
private final Matrix mMatrix = new Matrix();
private void updateMatrix() {
float mw = this.getWidth();
float mh = this.getHeight();
float hw = this.getWidth() / 2.0f;
float hh = this.getHeight() / 2.0f;
float cw = (float)Resources.getSystem().getDisplayMetrics().widthPixels; //Make sure to import Resources package
@heaversm
heaversm / opencv-contrib-whitebalance.cpp
Created March 20, 2019 00:29
Using OpenCV Contrib White Balancing on a Mat in C++
//install openCV contrib: https://cocoapods.org/pods/OpenCV2-contrib
/*
//in Podfile:
target 'MyProject' do
pod 'OpenCV2-contrib', '~> 3.2'
*/
//pod install
#include <opencv2/core/core.hpp>
#find all videos in a folder and reduce their dimensions and or quality
#-crf lower is higher bitrate (better quality)
# -b 1000000 can be added, where you divide 1 GB by the video length in seconds (e.g. this is a 16m:40s video)
find . -type f -name "*.mp4" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -crf 20 -s 1280x720 -acodec copy -y "${FILE%.mp4}.shrink.mp4";' _ '{}' \;
#optimize an mp4
ffmpeg -i input.mp4 -vcodec h264 output.mp4
#imagemagick: