Categories
code ffmpeg python video

Transcribing Videos with Google Cloud Speech-to-Text

Got an hour-long video and not really into manually creating subtitles? not plans to put it on YouTube for their automated transcription services? then – try Google Cloud Speech-to-Text! In this post I’ll share some scripts for automating the process and creating an .str file to go along your video for displaying the subtitles.

Categories
graphics opencv python

Packing Better Montages than ImageMagick with Python Rect Packer

ImageMagick has a built in Montage creating tool. It’s good enough for casual montaging, but it’s definitely suboptimal for packing varying size images.

Categories
graphics opencv programming python vision

Cylindrical Image Warping for Panorama Stitching


Hey-o
Just sharing a code snippet to warp images to cylindrical coordinates, in case you’re stitching panoramas in Python OpenCV…
This is an improved version from what I had in class some time ago…
It runs VERY fast. No loops involved, all matrix operations. In C++ this code would look gnarly.. Thanks Numpy!
Enjoy!
Roy

Categories
code machine learning python

Take a SWIG out of the Gesture Recognition Toolkit (GRT)

Reporting on a project I worked on for the last few weeks – porting the excellent Gesture Recognition Toolkit (GRT) to Python.
Right now it’s still a pull request: https://github.com/nickgillian/grt/pull/151.
Not exactly porting, rather I’ve simply added Python bindings to GRT that allow you to access the GRT C++ APIs from Python.
Did it using the wonderful SWIG project. Such a wondrous tool, SWIG is. Magical.
Here are the deets

Categories
code machine learning opencv programming python vision

Aligning faces with py opencv-dlib combo

This is my first trial at using Jupyter notebook to write a post, hope it makes sense.
I’ve recently taught a class on generative models: http://hi.cs.stonybrook.edu/teaching/cdt450
In class we’ve manipulated face images with neural networks.
One important thing I found that helped is to align the images so the facial features overlap.
It helps the nets learn the variance in faces better, rather than waste their “representation power” on the shift between faces.
The following is some code to align face images using the excellent Dlib (python bindings) http://dlib.net. First I’m just using a standard face detector, and then using the facial fatures extractor I’m using that information for a complete alignment of the face.
After the alignment – I’m just having fun with the aligned dataset 🙂

Categories
code linux machine learning python

Build your AWS Lambda Machine Learning Function with Docker

I’ve recently made a tutorial on using Docker for machine learning purposes, and I thought also to publish it in here: http://hi.cs.stonybrook.edu/teaching/docker4ml
It includes videos, slides and code, with hands-on demonstrations in class.
A GitHub repo holds the code: https://github.com/royshil/Docker4MLTutorial
I made several scripts to make it easy to upload python code that performs an ML inference (“prediction”) operation on AWS Lambda.
Enjoy!
Roy.

Categories
linux machine learning python

An automatic Tensorflow-CUDA-Docker-Jupyter machine on Google Cloud Platform


For a class I’m teaching (on deep learning and art) I had to create a machine that auto starts a jupyter notebook with tensorflow and GPU support. Just create an instance and presto – Jupyter notebook with TF and GPU!
How awesome is that?
Well… building it wasn’t that simple.
So for your enjoyment – here’s my recipe:

Categories
3d Augmented Reality code graphics opencv python video vision

Projector-Camera Calibration – the "easy" way

First let me open by saying projector-camera calibration is NOT EASY. But it’s technically not complicated too.
It is however, an amalgamation of optimizations that accrue and accumulate error with each step, so that the end product is not far from a random guess.
So 3D reconstructions I was able to get from my calibrated pro-cam were just a distorted mess of points.
Nevertheless, here come the deets.

Categories
code graphics opencv python vision work

Revisiting graph-cut segmentation with SLIC and color histograms [w/Python]

As part of the computer vision class I’m teaching at SBU I asked students to implement a segmentation method based on SLIC superpixels. Here is my boilerplate implementation.
This follows the work I’ve done a very long time ago (2010) on the same subject.
For graph-cut I’ve used PyMaxflow: https://github.com/pmneila/PyMaxflow, which is very easily installed by just pip install PyMaxflow
The method is simple:

  • Calculate SLIC superpixels (the SKImage implementation)
  • Use markings to determine the foreground and background color histograms (from the superpixels under the markings)
  • Setup a graph with a straightforward energy model: Smoothness term = K-L-Div between superpix histogram and neighbor superpix histogram, and Match term = inf if marked as BG or FG, or K-L-Div between SuperPix histogram and FG and BG.
  • To find neighbors I’ve used Delaunay tessellation (from scipy.spatial), for simplicity. But a full neighbor finding could be implemented by looking at all the neighbors on the superpix’s boundary.
  • Color histograms are 2D over H-S (from the HSV)

Result

Categories
code programming python Solutions Web

A script to scrape PDFs from a page using Python+Mechanize

A friend asked me for a way to download all the PDFs from a page, and I made this simple script with Python and Mechanize. It’s very straightforward…
It does hack the user agent, which is not nice. So use at your discretion.