Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is "-deskew threshold{%}" implemented? #42

Closed
dcolley opened this issue Jan 24, 2017 · 5 comments
Closed

Is "-deskew threshold{%}" implemented? #42

dcolley opened this issue Jan 24, 2017 · 5 comments

Comments

@dcolley
Copy link

dcolley commented Jan 24, 2017

https://www.imagemagick.org/script/command-line-options.php#deskew

I could write my img to file and wrap a system command, then read the result back into R, but that would be really slow...

Could you suggest a method of calling imagemagick with -deskew?

@dcolley
Copy link
Author

dcolley commented Jan 24, 2017

This is what I am trying to avoid:

my_image_deskew <- function(img,level=40) {
  d = ''
  if( level!=0 ) {
    d = paste('-deskew ',level,'%',sep = '') 
  }
  tf = tempfile(pattern = "file", tmpdir = tempdir())
  tfi = paste(tf,'-in.png',sep='')
  save.image(img,tfi)
  tfo = paste(tf,'-out',sep='')
  cmd = paste("convert",tfi,d,tfo,sep=' ')
  system( cmd , intern = FALSE, ignore.stderr = FALSE,
          wait = TRUE, input = NULL
          #,show.output.on.console = TRUE
          #,minimized = FALSE
          #,invisible = TRUE
  )
  im = load.image(tfo)
  return( im )
}

@jeroen
Copy link
Member

jeroen commented Jan 25, 2017

It was not implemented yet so I have just added this in 4f4a1fe. Can you please test it:

devtools::install_github("ropensci/magick")

The method is called image_deskew.

@jeroen
Copy link
Member

jeroen commented Jan 25, 2017

Actually this seems to be a recent feature which is not available on older versions of libimagemagick. What OS do you use?

@dcolley
Copy link
Author

dcolley commented Jan 25, 2017

This is why I love open source!!

Ok, here is my experience, from RStudio I tried

> devtools::install_github("ropensci/magick")
Downloading GitHub repo ropensci/magick@master
from URL https://api.github.com/repos/ropensci/magick/zipball/master
Installing magick
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore  \
  --quiet CMD INSTALL  \
  '/private/var/folders/m_/0376qqx90450ny76ygk517z40000gn/T/RtmpqO6cGr/devtoolsa8e1a559004/ropensci-magick-da07942'  \
  --library='/Library/Frameworks/R.framework/Versions/3.3/Resources/library' --install-tests 

* installing *source* package ‘magick’ ...
Package Magick++ was not found in the pkg-config search path.
Perhaps you should add the directory containing `Magick++.pc'
to the PKG_CONFIG_PATH environment variable
No package 'Magick++' found
Using PKG_CFLAGS=-I/usr/local/opt/imagemagick/include/* -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_HDRI_ENABLE=0
Using PKG_LIBS=-L/usr/local/opt/imagemagick/lib -lMagick++-6.Q16
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because Magick++ was not found. Try installing:
 * deb: libmagick++-dev (Debian, Ubuntu)
 * rpm: ImageMagick-c++-devel (Fedora, CentOS, RHEL)
 * csw: imagemagick_dev (Solaris)
 * brew: imagemagick (OSX)
If Magick++ is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a Magick++.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------
ERROR: configuration failed for package ‘magick’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/magick’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/magick’
Error: Command failed (1)

I searched for the error and found : elad/node-imagemagick-native#4

I switched to command line:

export PGK_CONFIG_PATH=/opt/local/lib/pkgconfig
r

R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> devtools::install_github("ropensci/magick")
Skipping install of 'magick' from a github remote, the SHA1 (da079423) has not changed since last install.
  Use `force = TRUE` to force installation

NOTE: I forced the installation, but others may want to solve the SHA1 problem..?

> devtools::install_github("ropensci/magick",force=TRUE)
Downloading GitHub repo ropensci/magick@master
from URL https://api.github.com/repos/ropensci/magick/zipball/master
Installing magick
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ  \
  --no-save --no-restore --quiet CMD INSTALL  \
  '/private/var/folders/m_/0376qqx90450ny76ygk517z40000gn/T/RtmpMqDboo/devtools1d5d1023710d/ropensci-magick-da07942'  \
  --library='/Library/Frameworks/R.framework/Versions/3.3/Resources/library'  \
  --install-tests 

* installing *source* package ‘magick’ ...

[snip...]

installing to /Library/Frameworks/R.framework/Versions/3.3/Resources/library/magick/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (magick)

I'm still testing it, and I'll report if there are any errors.

@dcolley
Copy link
Author

dcolley commented Jan 26, 2017

It's working for me, thanks. Looking forward to seeing this in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants