ruby图片处理

 

我们经常要处理图片,比如搞个什么头像缩略图,在所难免要对图片进行裁剪、缩放等操作,下面就来总结一下Ruby中图片裁剪、缩放的类库。

 

ImageScience:
实现图片放缩的库,使用前需安装freeimage和rubyinline。
网址:http://seattlerb.rubyforge.org/ImageScience.html

 

RMagick:
RMagick是Ruby语言跟ImageMagick图形处理程序之间的接口,Ruby程序可以利用RMagick对图像进行缩略、剪裁等等的一系列操作。
网址:http://rmagick.rubyforge.org

 

等比缩放:

800x800 => 60x90  实际结果: 60x60

800x800 => 135x90  实际结果: 90x90

800x800 => 135x900  实际结果: 135x135

400x900 => 60x60  实际结果: 60x26

400x900 => 135x900  实际结果: 308x135

 

 

MiniMagick:
它是RMagick的精简,直接用Ruby包装ImageMagick command line。避免了RMagick的内存问题。
http://rubyforge.org/projects/mini-magick

 

 

 

 

 

 

 

 

 

1.install imagescience
a)install FreeImage
download freeimage from :http://sourceforge.net/projects/freeimage/files/
$unzip  FreeImage3130.zip
$make
$sudo make install
b)install RubyInline
$sudo gem install RubyInline
c)install ImageScience
http://seattlerb.rubyforge.org/ImageScience.html
$sudo apt-get install libfreeimage3 libfreeimage-dev
$sudo gem install image_science
centos 下是安装ImageMagick
download from http://www.imagemagick.org/script/download.php
make & make install



2.install rmagick
a) install imagemagick
$sudo apt-get install imagemagick
$sudo apt-get install libmagickwand-dev
b) install ruby rmagick
download rmagick from http://rmagick.rubyforge.org/
$tar xzvf RMagick-2.12.....
$ruby setup.rb
$ruby setup.rb install





--------------------------------------------------------------------------------


$ sudo apt-get install imagemagick
$ dpkg -l |grep imagemagick
imagemagick                                                 
imagemagick-doc                           

$ convert
$ whereis convert
$ which is convert
$ convert -compress none -depth 8 -alpha off zhejiang.gif zhejiang.tif

enlarge the image can improve ocr accuracy

I believe the real challenge to apply ocr for plate recognition is
that the plate image are "too dirty" comparing to paper documents.
There are frames, skews, un-even shadows, etc. You have to do your own
work to parse the plate into separate chars and feed the ocr engine. I
don't think tesseract itself can handle this automatically given the
raw image. But I believe it will do pretty well once you get the
binarized separate chars. Basically, plate recognition is more a image
processing problem than ocr problem.

You can use the grammar as post-process to make corrections.


to convert the pdf I used Image Magick convert application. bellow the set command that I use.
convert -density 288 src.pdf -colorspace Gray -depth 8 -alpha off tmp.tif
tesseract tmp.tif out.txt

how to eliminate noise

 

 

 

 

 

 

 

 

 

 

  def upload_file(file)
    if !file.original_filename.empty?
      @filename = file.original_filename
      File.open("#{RAILS_ROOT}/public/images/#{@filename}", "wb") do |f|
        f.write(file.read)
      end
      return @filename
    end
  end


  # params[:file] is Tempfile obj from the page
  img = Magick::Image.from_blob(params[:file].read)[0]
  img.write("#{filename}")

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值