react-native-perspective-image-cropper icon indicating copy to clipboard operation
react-native-perspective-image-cropper copied to clipboard

could not invoke CustomCropManager.crop

Open Sride opened this issue 5 years ago • 42 comments

on cropping image, shows error.

Screenshot_20190621-174920

Sride avatar Jun 21 '19 12:06 Sride

@Michaelvilleneuve any idea?, I have linked manually, here is the code.

import com.facebook.react.ReactApplication;
import com.horcrux.svg.SvgPackage;
//import org.opencv.RNCustomCropPackage;
import fr.michaelvilleneuve.customcrop.RNCustomCropPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

Sride avatar Jun 25 '19 05:06 Sride

Have you properly installed OpenCV as suggested in the Readme ? This step needs to be done manually

Michaelvilleneuve avatar Jun 25 '19 07:06 Michaelvilleneuve

Thanks for the quick response, followed the same steps in read me, the cropper shows on clicking on the crop text in example, it shows error. opencv is configured in project.

include ':openCVLibrary310'
project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-perspective-image-cropper/android/openCVLibrary310')

Sride avatar Jun 25 '19 07:06 Sride

same problem here, any sugestion?

vitornsp2 avatar Jun 25 '19 20:06 vitornsp2

@Michaelvilleneuve any suggestions?

Sride avatar Jun 26 '19 07:06 Sride

Ok, obviously there seem to be a documentation problem, I am not sure which step I missed in the doc but I'll try to list the changes made to our project :

Here is our settings.gradle :

include ':react-native-perspective-image-cropper'
project(':react-native-perspective-image-cropper').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-perspective-image-cropper/android')
include ':openCVLibrary310'
project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-document-scanner/android/openCVLibrary310')

Since we are using OpenCV with react-native-document-scanner the openCV step is done once but you should be able to have the following :

package.json

"react-native-perspective-image-cropper": "^0.4.3",
 "react-native-svg": "^9.4.0",

settings.gradle :

include ':react-native-perspective-image-cropper'
project(':react-native-perspective-image-cropper').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-perspective-image-cropper/android')
include ':openCVLibrary310'
project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-perspective-image-cropper/android/openCVLibrary310')

notice the path change

build.gradle

implementation project(':react-native-perspective-image-cropper')
implementation project(':react-native-svg')

MainAplication.java

import fr.michaelvilleneuve.customcrop.RNCustomCropPackage;
import com.horcrux.svg.SvgPackage;


and then ...

new RNCustomCropPackage(),
new SvgPackage(),

Thing to note, though I seriously doubt this has anything to do with this error : We changed our manifest to make it look like this :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   // The below line was added
    xmlns:tools="http://schemas.android.com/tools">

    <application
   // The below line was added
      tools:replace="android:allowBackup"
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"

If you have followed exactly this, it may have something to do with the fact that we use openCV from my other lib react-native-document-scanner. In that case, you can try to install the android branch of react-native-document-scanner:

"react-native-document-scanner": "Michaelvilleneuve/react-native-document-scanner#android",

and use this OpenCV in settings.gradle

include ':openCVLibrary310'
project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-document-scanner/android/openCVLibrary310')

If it helped please tell me so I can update the code or documentation

Michaelvilleneuve avatar Jun 26 '19 14:06 Michaelvilleneuve

@Michaelvilleneuve same issue exits,i have followed the steps once again, let us find the exact problem. I have my source in this Dropbox link. Please check the source, it seems everyone has this issue, let's solve this issue.

Sride avatar Jun 26 '19 17:06 Sride

Have you tried using react-native-document-scanner as source for open CV lib ? I’ll take a look at your source code tomorrow

Michaelvilleneuve avatar Jun 26 '19 18:06 Michaelvilleneuve

No, let me check that. Thanks

Sride avatar Jun 26 '19 18:06 Sride

i think we should pass uri using react-native-camera package , cause our uri should look like this . -> file:///data/data/com.lastscan/cache/Camera/a72a0abe-0dec-4bf1-9d54-30a5321f7e53.jpg

cause Imgcodecs.imread(imageUri.replace("file://", ""), Imgproc.COLOR_BGR2RGB) ,that type of function written in the bridge RNCustomCropModule.java ,

check crop method in RNCustomCropModule.java

my assumptions -_-

zahidahmed024 avatar Jun 26 '19 19:06 zahidahmed024

Ok, obviously there seem to be a documentation problem, I am not sure which step I missed in the doc but I'll try to list the changes made to our project :

Here is our settings.gradle :

include ':react-native-perspective-image-cropper'
project(':react-native-perspective-image-cropper').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-perspective-image-cropper/android')
include ':openCVLibrary310'
project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-document-scanner/android/openCVLibrary310')

Since we are using OpenCV with react-native-document-scanner the openCV step is done once but you should be able to have the following :

package.json

"react-native-perspective-image-cropper": "^0.4.3",
 "react-native-svg": "^9.4.0",

settings.gradle :

include ':react-native-perspective-image-cropper'
project(':react-native-perspective-image-cropper').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-perspective-image-cropper/android')
include ':openCVLibrary310'
project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-perspective-image-cropper/android/openCVLibrary310')

notice the path change

build.gradle

implementation project(':react-native-perspective-image-cropper')
implementation project(':react-native-svg')

MainAplication.java

import fr.michaelvilleneuve.customcrop.RNCustomCropPackage;
import com.horcrux.svg.SvgPackage;


and then ...

new RNCustomCropPackage(),
new SvgPackage(),

Thing to note, though I seriously doubt this has anything to do with this error : We changed our manifest to make it look like this :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   // The below line was added
    xmlns:tools="http://schemas.android.com/tools">

    <application
   // The below line was added
      tools:replace="android:allowBackup"
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"

If you have followed exactly this, it may have something to do with the fact that we use openCV from my other lib react-native-document-scanner. In that case, you can try to install the android branch of react-native-document-scanner:

"react-native-document-scanner": "Michaelvilleneuve/react-native-document-scanner#android",

and use this OpenCV in settings.gradle

include ':openCVLibrary310'
project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-document-scanner/android/openCVLibrary310')

If it helped please tell me so I can update the code or documentation

Tried this, but facing same issue

manchi17 avatar Jun 27 '19 06:06 manchi17

Have you tried using react-native-document-scanner as source for open CV lib ? I’ll take a look at your source code tomorrow Tried react-native-document-scanner as source for open CV lib, same issue @Michaelvilleneuve

Sride avatar Jun 27 '19 06:06 Sride

@zahidahmed024, may i know, how you have linked opencv manually, which you have mentioned in this link does crop works?

Sride avatar Jun 27 '19 09:06 Sride

actually i used https://www.npmjs.com/package/react-native-opencv3 this package and used index.js as component pspp

,and paste the crop method and imports in RNOpencv3Module.java file op

check my code https://drive.google.com/open?id=1sR21BRm_X1Z_vid8GSLJ2F_zMa0bV79l

take photo using camera in updateImage method you will get cropped base64 image then use it where you want to .

i dont know weather it is right way or wrong -- opencv is a pain -- .

zahidahmed024 avatar Jun 27 '19 14:06 zahidahmed024

@zahidahmed024, after cropping image , crop() function can't return any values, it's return error.

Screenshot_20190628_125539_com re

any idea about this?

ElangoPrince avatar Jun 28 '19 07:06 ElangoPrince

capture image from camera , and check in console.log that u are getting uri like -> file:///data/data/com.lastscan/cache/Camera/a72a0abe-0dec-4bf1-9d54-30a5321f7e53.jpg . i had that issue see the crop method. Imgcodecs.imread() taking uri that start with file:/// fucntion https://github.com/Michaelvilleneuve/react-native-perspective-image-cropper/blob/master/android/src/main/java/fr/michaelvilleneuve/customcrop/RNCustomCropModule.java pppp

zahidahmed024 avatar Jun 28 '19 10:06 zahidahmed024

@zahidahmed024 my log url is

content://com.re.provider/root/storage/emulated/0/Pictures/image-62b82ef6-8d2f-4822-943e-13c9dbbfc9c1.jpg

tried with replace "content" to "file" manually, throws same error, any suggestions

Sride avatar Jul 01 '19 06:07 Sride

Have you tried using react-native-document-scanner as source for open CV lib ? I’ll take a look at your source code tomorrow

@Michaelvilleneuve any suggestions regarding this issue.

Sride avatar Jul 01 '19 09:07 Sride

@Sride hey i solved that issue by providing image path ,, imgcodecs.imread() function can read original path . see the changes , cpath

cimage

c2image

c3image

c4image in update function u will get your cropped image in base64 .

*sometimes imagepicker package gives uri like file:/// sometimes like content:// ,also uri changes when u put your phone on usb , i donno if u faced this situation too -_-

zahidahmed024 avatar Jul 01 '19 18:07 zahidahmed024

@zahidahmed024 Thanks a lot, it works like a charm..

Sride avatar Jul 02 '19 05:07 Sride

@Sride actually this library is beautifully written by @Michaelvilleneuve . but installing opencv in native android or react native is always a pain and image picker uri problem -_-

zahidahmed024 avatar Jul 02 '19 08:07 zahidahmed024

Yes @zahidahmed024 this is unique library, thanks for giving such a library @Michaelvilleneuve, really opencv integration is a pain.

Sride avatar Jul 02 '19 10:07 Sride

@zahidahmed024 I tried with your proposed solution, but it does not work :(

DavitVosk avatar Jul 04 '19 07:07 DavitVosk

@DavitVosk

I found the solution. in the CustomCropModule.java

public RNCustomCropModule(ReactApplicationContext reactContext) {
  super(reactContext);
 OpenCVLoader.initDebug();
  this.reactContext = reactContext;
}

you also have to install opencv using this script

wget https://sourceforge.net/projects/opencvlibrary/files/opencv-android/3.4.1/opencv-3.4.1-android-sdk.zip
unzip opencv-3.4.1-android-sdk.zip
cd android/app/src/main
mkdir jniLibs
cp -r ./../../../../OpenCV-android-sdk/sdk/native/libs/ ./jniLibs
cd ../../../../
rm -rf opencv-3.4.1-android-sdk.zip
rm -rf OpenCV-android-sdk/

ethienneroy avatar Aug 05 '19 21:08 ethienneroy

Okay. After struggle fof 2days,here is how i solve the issue completely.

  1. Install opencv310 manually and import the modules
  2. Copy the lib file to jnilibs folder inside android main. 3.install react native opencv3
  3. Edit the build gradle to implement your imported opencv module.

jackyleehong avatar Aug 09 '19 00:08 jackyleehong

I'm getting issue when scanning is done the area in which scanning is done but the image is croppping somewhere else.

Macrew avatar Nov 02 '19 11:11 Macrew

The easiest way to integrate openCV for me was to add implementation 'com.quickbirdstudios:opencv:3.4.1' in my project build.gradle file and then export RNCustomCropPackage as native-modules.

SL-A-SH avatar Nov 07 '19 09:11 SL-A-SH

@SL-A-SH and @jackyleehong : Could you please explain more about the way you setup your project? Also if you have a repo, that would be helpful. I am struggling to set this up

valekar avatar Nov 11 '19 21:11 valekar

Hi, please send your project. or uninstall react-native-perspective-image-cropper, install "react-native-opencv3": "^1.0.4",after that create, Custom crop component separately . then pass the arguments through props to Custom crop component (where you want 😊 👍).if any clarification please let me know.

On Tue, Nov 12, 2019 at 2:58 AM srinivas valekar [email protected] wrote:

@SL-A-SH https://github.com/SL-A-SH and @jackyleehong https://github.com/jackyleehong : Could you please explain more about the way you setup your project? Also if you have a repo, that would be helpful. I am struggling to set this up

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Michaelvilleneuve/react-native-perspective-image-cropper/issues/26?email_source=notifications&email_token=AIJMT7J4G4SZZVM43DVLWT3QTHFARA5CNFSM4H2RF6PKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDYGBPA#issuecomment-552624316, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIJMT7OXPOBIAWWJYJFWEUTQTHFARANCNFSM4H2RF6PA .

-- Thanks and Regards, Elango.K

ElangoPrince avatar Nov 12 '19 07:11 ElangoPrince

@ElangoPrince : Thanks for the info! This react-native-opencv3 looks like really an amazing project. I would let you know once I update my code-base. :)

valekar avatar Nov 12 '19 10:11 valekar