## crop and deskew based on coordinates only?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
dannyler
Posts: 1
Joined: 2019-08-09T01:43:15-07:00
Authentication code: 1152

### crop and deskew based on coordinates only?

hi all!

i have to preface as a first time poster, that in the last years I have only used imagemagick to convert, resize, annotate images. quite a lot, but never to do anything more sophisticated with it. and now i'm failing to comprehend what to do completely.

i'm trying to get an image deskewed, but based on coordinates. and I don't know if i use the wrong keywords to search in google or if I need a whole different approach, but this is what I have:

step 1: detect books on images
step 2: identify the corners of the book
step 3: create a new image that is only the book, but deskewed, meaning as a rectangle

I've made my way up to step 2, but utterly fail on step 3.

is it multiple commands in a row, is it one?
is it possible with ImageMagick at all?
can somepoint point me in the right direction?

example image annotated: https://imgur.com/a/DhrwErL
edit: desired target output: https://imgur.com/a/4Njw3rU

much appreciated, thank you!
Dan

snibgo
Posts: 12697
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

### Re: crop and deskew based on coordinates only?

You know the coordinates of four points (this is 8 numbers). You want to move those four points to some other coordinates (another 8 numbers). For that, use "-distort perspective". Give that 16 numbers, in this order:

x,y coords of first input point
x,y coords for desired location of first point
x,y coords of second input point
x,y coords for desired location of second point
x,y coords of third input point
x,y coords for desired location of third point
x,y coords of fourth input point
x,y coords for desired location of fourth point

See http://www.imagemagick.org/script/comma ... hp#distort
snibgo's IM pages: im.snibgo.com