app/jobs/maps_ocr_job.rb
#force to force ocr 
#geocode to do the geocoding
force to force ocr
geocode to do the geocoding
force to force ocr geocode to do the geocoding
def perform(map, force=false, geocode=true)
    filename = nil
    if map.mask_status == :masked
      filename = map.masked_src_filename
    else
      filename = map.unwarped_filename
    end
    return if filename.nil?
    if force == false && !map.ocr_result.nil? && geocode
      geocode_map(map)
    else
      processed_img = filename + ".ocr.png"
      resize = "8000x8000\>"
      command = ["convert", "#{filename}[0]", "-resize", resize, "-threshold", "50%", "-trim", "+repage",  processed_img ]
      logger.debug command
      stdout_str, stderr_str, status = Open3::capture3(*command)
      ocr_result = nil
      if stderr_str.blank?
        begin
          response = google_image_annotate(processed_img)
          text = process_text(response)
          text.uniq!
          ocr_result = text.map {|a| a.downcase}.join(" ") 
          logger.debug "ocr result = #{ocr_result}"
          map.ocr_result = ocr_result
          map.save
      rescue StandardError => e
        logger.error "ERROR with Google Image Annotate StandardError " + e.to_s
      end
        geocode_map(map) if geocode && !ocr_result.blank?
      else
        logger.error "ERROR with OCR command out #{stdout_str} err #{stderr_str.inspect} status #{status}"
      end
      File.delete processed_img if File.exists? processed_img
    end
  end
def perform ( map , force = false , geocode = true ) filename = nil if map . mask_status == :masked filename = map . masked_src_filename else filename = map . unwarped_filename end return if filename . nil? if force == false && ! map . ocr_result . nil? && geocode geocode_map ( map ) else processed_img = filename + ".ocr.png" resize = "8000x8000\>" command = [ "convert" , "#{filename}[0]" , "-resize" , resize , "-threshold" , "50%" , "-trim" , "+repage" , processed_img ] logger . debug command stdout_str , stderr_str , status = Open3 :: capture3 ( * command ) ocr_result = nil if stderr_str . blank? begin response = google_image_annotate ( processed_img ) text = process_text ( response ) text . uniq! ocr_result = text . map { | a | a . downcase } . join ( " " ) logger . debug "ocr result = #{ocr_result}" map . ocr_result = ocr_result map . save rescue StandardError => e logger . error "ERROR with Google Image Annotate StandardError " + e . to_s end geocode_map ( map ) if geocode && ! ocr_result . blank? else logger . error "ERROR with OCR command out #{stdout_str} err #{stderr_str.inspect} status #{status}" end File . delete processed_img if File . exists? processed_img end end
force to force ocr
geocode to do the geocoding
force to force ocr geocode to do the geocoding
# Don't ocr this map again if there is already a result, unless the force param is set to true #resize makes it smaller. -threshold black and whites it, -trim and +repage "auto crops it" #delete the ocr images
map
<not_specific>
force
<not_specific>
geocode
<not_specific>