Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jenorish/crop_calculator
https://github.com/jenorish/crop_calculator
Last synced: 3 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jenorish/crop_calculator
- Owner: jenorish
- License: mit
- Created: 2013-07-30T10:06:04.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-03-26T16:51:17.000Z (over 11 years ago)
- Last Synced: 2023-08-02T15:12:54.000Z (over 1 year ago)
- Language: Ruby
- Size: 68.4 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# CropCalculator
Given a target size and an ROI, calculate crop size. The return values
can be used by RMagick or similar tool to create the actual cropped version.To compute ROI using OpenCV's face detection, [face_ROI] (https://github.com/kreatio-sw/face_ROI).
## Installation
Add this line to your application's Gemfile:
gem 'crop_calculator'
And then execute:
$ bundle
Or install it yourself as:
$ gem install crop_calculator
## Usage
````ruby
offset_x, offset_y, crop_width, crop_height =
CropCalculator.calculate_crop_rect(target_width, target_height, img_width, img_height, roi_x, roi_y, roi_width, roi_height)
````Full sample using RMagick and face_ROI
````ruby
module FaceROI
OPENCV_BASE= '/usr/local'
endrequire 'face_ROI'
require 'crop_calculator'
require 'rmagick'
def test_me(path)
dimensions = [[50,50],[100,100],[400,400],[150,100],[200,300],[400,250]]
f=FaceROI::Finder.new(path, FaceROI::CONFIG1)image=f.image_with_faces
rm_img=Magick::Image.read(path)[0]
img_width=rm_img.columns
img_height=rm_img.rows
roi_x, roi_y, roi_width, roi_height= f.roidimensions.each do |dimension|
target_width, target_height = dimension
# Compute the crop
offset_x, offset_y, crop_width, crop_height =
CropCalculator.calculate_crop_rect(target_width, target_height, img_width, img_height, roi_x, roi_y, roi_width, roi_height)out_path = path.sub(/\./, "-#{target_width}x#{target_height}.")
out_path = "out/#{out_path}"
rm_img.excerpt(offset_x, offset_y, crop_width, crop_height).resize(target_width, target_height).write(out_path)
end
endtest_me 'test/IMG_0465.jpg'
````## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request