Skip to content

Instantly share code, notes, and snippets.

@demogar
Last active March 22, 2017 10:07
Show Gist options
  • Save demogar/5d560c82c886ef50f5aebcda332f32a3 to your computer and use it in GitHub Desktop.
Save demogar/5d560c82c886ef50f5aebcda332f32a3 to your computer and use it in GitHub Desktop.
ManejoAlHombro
function _openCamera() {
Titanium.Media.showCamera({
success : function(event) {
if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
_uploadReport(event.media);
} else {
alert("No es una imagen =" + event.mediaType);
}
},
error : function(error) {
var a = Titanium.UI.createAlertDialog({
title : 'Camera'
});
a.setMessage('Error: ' + error.code);
a.show();
},
saveToPhotoGallery : true,
allowEditing : true,
mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO]
});
}
function _openGallery() {
Ti.Media.openPhotoGallery({
success : function(event) {
if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
_uploadReport(event.media);
} else {
alert("No es una imagen =" + event.mediaType);
}
},
error : function(error) {
var a = Titanium.UI.createAlertDialog({
title : 'Camera'
});
a.setMessage('Unexpected error: ' + error.code);
a.show();
},
allowEditing : true,
allowMultiple : false,
mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO]
});
}
class OpenAlpr
attr_reader :output, :command
def initialize(file)
@file = file
@output = []
begin
@output = JSON.parse(processPhoto(file))
rescue JSON::ParserError
@output = nil
end
end
private
def processPhoto(file)
@command = "alpr -j -n 10 -c pa -p pa #{Shellwords.shellescape file}"
`#{@command}`
end
end
; 30-50, 40-60, 50-70, 60-80
char_analysis_min_pct = 0.30
char_analysis_height_range = 0.20
char_analysis_height_step_size = 0.10
char_analysis_height_num_steps = 4
segmentation_min_speckle_height_percent = 0.3
segmentation_min_box_width_px = 4
segmentation_min_charheight_percent = 0.5;
segmentation_max_segment_width_percent_vs_average = 1.35;
plate_width_mm = 304.8
plate_height_mm = 152.4
multiline = 0
char_height_mm = 70
char_width_mm = 35
char_whitespace_top_mm = 38
char_whitespace_bot_mm = 38
template_max_width_px = 120
template_max_height_px = 60
; Higher sensitivity means less lines
plateline_sensitivity_vertical = 25
plateline_sensitivity_horizontal = 45
; Regions smaller than this will be disqualified
min_plate_size_width_px = 70
min_plate_size_height_px = 35
; Results with fewer or more characters will be discarded
postprocess_min_characters = 5
postprocess_max_characters = 7
detector_file = us.xml
ocr_language = lus
; Override for postprocess letters/numbers regex.
postprocess_regex_letters = [A-Z]
postprocess_regex_numbers = [0-9]
; Whether the plate is always dark letters on light background, light letters on dark background, or both
; value can be either always, never, or auto
invert = auto
pa @@#### // <- las placas nuevas, ej.: AB1234. Aplica también para Metro Bus, ej.: MB0000
pa ###### // <- las placas anteriores, ej.: 123456
pa @##### // <- las placas de Taxi, ej.: T12345
pa #@@##### // <- las placas de Taxi de Ruta Interna, ej.: 8RI12345
# ...
if params[:photo]
# Get the filename
@filename = params[:photo][:filename]
# Write it locally
File.open("public/photos/#{@filename}", "w") do |f|
f.write(params[:photo][:tempfile].read)
end
# Analyze it with openalpr
@search = OpenAlpr.new("public/photos/#{@filename}")
end
# Validate if openalpr returns values
if @search && @search.output && @search.output['results'].size > 0
# Get the better result
@result = @search.output['results'].first
# Get the coordinates for this result (the best)
coordinates = @result['coordinates']
first_coordinate = coordinates.first
third_coordinate = coordinates[2]
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment