Michaelvilleneuve / react-native-perspective-image-cropper

Perform custom crop, resizing and perspective correction 📐🖼
MIT License
305 stars 128 forks source link

Cropping not correct and on head #18

Closed danmoebius closed 5 years ago

danmoebius commented 5 years ago

Hi, i got to implement your package in my react native app. But i get trouble with the output image. If i use the full image size as rectangle coordinates, i will get only a part of the document, but not the full one. Second problem is, that the image will be on head. Have you any idea to solve these troubles? How decide opencv to get only part of the document? If there any properties to handle opencv?

Origin Document: origin

Cropped: cropped

Best regards

danmoebius commented 5 years ago

Could be closed. I found the issue on my own, regarding to wrong rectangle coordinates.

armin23615 commented 4 years ago

How did you solve this? Can you post your code, please?

danmoebius commented 4 years ago

Hi armin,

i solved this problem by pre calculation of the rectangle coordinates.

`getImageCroppingInformations = (imageWidth, imageHeight) => { let ratio = imageHeight / imageWidth; let calculatedWidth = width; let calculatedHeight = calculatedWidth * ratio;

let positionLeft =
  calculatedWidth * DEFAULT_MARGIN_CROPPING_HANDLER_PERCENT;
let positionRight =
  (calculatedWidth - doubleCroppingViewMargin) *
  (1 - DEFAULT_MARGIN_CROPPING_HANDLER_PERCENT);

if (imageHeight > imageWidth) {
  ratio = imageWidth / imageHeight;
  calculatedWidth = height * ratio;
  calculatedHeight = determineHeight(
    DEFAULT_HEADER_HEIGHT + DEFAULT_BOTTOM_CONTROLS_HEIGHT
  );
}

let positionTop =
  calculatedHeight * DEFAULT_MARGIN_CROPPING_HANDLER_PERCENT;
let positionBottom =
  (calculatedHeight - doubleCroppingViewMargin) *
  (1 - DEFAULT_MARGIN_CROPPING_HANDLER_PERCENT);

return {
  positionLeft: positionLeft,
  positionRight: positionRight,
  positionTop: positionTop,
  positionBottom: positionBottom,
  calculatedWidth: calculatedWidth,
  calculatedHeight: calculatedHeight
};

};`

But in fact, we kicked this repository out of our project, because it does not fulfill our expectations. In my humble opinion, in general check your requirements and think about to build by your own for more stability, customizability and update capability. Best regards

cdcharlebois commented 2 years ago

@danmoebius was there an alternative library that you found to provide this perspective-cropping functionality? I'm currently stuck on a similar issue

danmoebius commented 2 years ago

@cdcharlebois i am sorry, I have no alternativ Library. I changed a lot of these library to make it useful for our case. But I think the best method will be a custom solution on your case with opencv. I know it is more work, but you are save in case of updates.

If you find another library. Let us know 😊 Best regards

cdcharlebois commented 2 years ago

please see my PR #64