Skip to content

Instantly share code, notes, and snippets.

View christianroman's full-sized avatar

Christian Roman christianroman

  • Mexico
View GitHub Profile
@christianroman
christianroman / test.py
Created May 30, 2013 16:02
Bypass Captcha using 10 lines of code with Python, OpenCV & Tesseract OCR engine
import cv2.cv as cv
import tesseract
gray = cv.LoadImage('captcha.jpeg', cv.CV_LOAD_IMAGE_GRAYSCALE)
cv.Threshold(gray, gray, 231, 255, cv.CV_THRESH_BINARY)
api = tesseract.TessBaseAPI()
api.Init(".","eng",tesseract.OEM_DEFAULT)
api.SetVariable("tessedit_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyz")
api.SetPageSegMode(tesseract.PSM_SINGLE_WORD)
tesseract.SetCvImage(gray,api)
print api.GetUTF8Text()
@christianroman
christianroman / UIImage+ImageEffects.m
Created September 27, 2013 04:23
UIImage+ImageEffects.m
//
// UIImage+ImageEffects.m
// AnimationExamples
//
// Created by Timothy Patrick Johnson on 7/3/13.
// Copyright (c) 2013 Meister. All rights reserved.
//
#import "UIImage+ImageEffects.h"
@christianroman
christianroman / training.sh
Last active October 26, 2021 06:04
Tesseract OCR training new font
#! /bin/bash
# build the environment
mkdir tessenv; cd tessenv
TROOT=`pwd`
mkdir $TROOT/stockfonts; mkdir $TROOT/build; mkdir $TROOT/build/eng
echo "Environment built"
# Get the stock english fonts from Google (old, but they work)
cd $TROOT/stockfonts
GET http://tesseract-ocr.googlecode.com/files/boxtiff-2.01.eng.tar.gz > boxtiff-2.01.eng.tar.gz
@christianroman
christianroman / server.py
Last active June 12, 2021 01:09
Rompiendo Captcha de CURP usando Python, OpenCV, Tesseract OCR y Tornado
import tornado.ioloop
import tornado.web
import urllib2 as urllib
from PIL import Image
from cStringIO import StringIO
import numpy as np
import tesserwrap
import cv2
class MainHandler(tornado.web.RequestHandler):
@christianroman
christianroman / OCR.java
Created May 15, 2012 02:53
Captcha OCR + Tessaract Complex
public class OCR {
private static final String INPUT = "C:/captcha/ex.png";
private static final String OUTPUT = "C:/captcha/captcha-out.png";
private static final String TESSERACT_BIN = "C:/Program Files/Tesseract-OCR/tesseract.exe";
private static final String TESSERACT_OUTPUT = "C:/captcha/out.txt";
private static final int WHITE = 0x00FFFFFF, BLACK = 0x00000000;
public static void main(String... args) throws Exception {
BufferedImage image = ImageIO.read(new FileInputStream(INPUT));
int average = 0;
@christianroman
christianroman / apple-pay-mexico.sh
Created October 20, 2020 15:35
Apple Pay Mexico
#!/bin/bash
#  Country code
CC="MX"
URL="https://smp-device-content.apple.com/static/region/v2/config.json"
HOME_PAGE="https://www.apple.com/mx/apple-pay"
FOUND=false
function check {
RET=$(curl -s $URL | jq .SupportedRegions.$CC)
@christianroman
christianroman / gist:6516864
Last active February 10, 2020 16:28
Install PostgreSQL 9.3.1 + PostGIS + PGRouting on CentOS 6.4
rpm -Uvh http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
yum install postgresql93 postgresql93-server postgresql93-contrib postgresql93-devel postgis2_93 postgis2_93-utils
#Configure PostgreSQL
chkconfig postgresql-9.3 on
service postgresql-9.3 initdb
service postgresql-9.3 start
# Create PostGIS template
@christianroman
christianroman / OCR.java
Created May 15, 2012 01:59
Captcha OCR + Tesseract
public class OCR {
private static final String INPUT = "C:/captcha/ex.png";
private static final String OUTPUT = "C:/captcha/captcha-out.png";
private static final String TESSERACT_BIN = "C:/Program Files/Tesseract-OCR/tesseract.exe";
private static final String TESSERACT_OUTPUT = "C:/captcha/out.txt";
private static final int WHITE = 0x00FFFFFF, BLACK = 0x00000000;
public static void main(String... args) throws Exception {
BufferedImage image = ImageIO.read(new FileInputStream(INPUT));
int average = 0;
@christianroman
christianroman / blur.rb
Created October 11, 2013 18:33
Blurring images in Rails with Paperclip custom processor
module Paperclip
class Blur < Processor
def initialize file, options = {}, attachment = nil
super
@format = File.extname(@file.path)
@basename = File.basename(@file.path, @format)
end
@christianroman
christianroman / NSString+Concatenation.h
Last active January 29, 2018 14:08
NSString+Concatenation
#import <Foundation/Foundation.h>
@interface NSString (Concatenation)
- (NSString *):(NSString *)a;
- (NSString *):(NSString *)a :(NSString *)b;
- (NSString *):(NSString *)a :(NSString *)b :(NSString *)c;
- (NSString *):(NSString *)a :(NSString *)b :(NSString *)c :(NSString *)d;
- (NSString *)concat:(NSString *)strings, ...;