Crop Image using four points
I am trying to crop an image then be able to display the image. I have four points in two arrays and it would make a rectangle shape. I have a code that i think would do the job but it is giving an error. Here is the code i hope you can help me out. I am working with android and only with Java. I have looked at http://answers.opencv.org/question/996/crop-image/ but i am unsure how to convert that info over to Java
int startX =locListX.get(0);
int startY =locListY.get(0);
Collections.sort(locListX);
Collections.sort(locListY);
int width=locListX.get(3)-locListX.get(0);
int height=locListY.get(3)-locListY.get(0);
Mat image = mFind;
Rect rectCrop = new Rect(startX, startY, width, height);
Mat imCrop= new Mat(image,rectCrop);
Utils.matToBitmap(imCrop, bmp5);
mGrayView.setImageBitmap(bmp5);
Basically can you also show us the code where you fill up the locListX and locListY data object? Because it is difficult to know how the points are defined and in what order. Can we expect something like (topleft, topright, bottomright, bottomleft)?
Yea it is basically topleft, topright, bottomright, bottomleft i just want to get a rough rectangle of what i want to see. I used template match to get the points so i would just use the top left point as the start point and then use the sort to get the longest width and height for the image
Error: Assertion failed (src.dims==2&&info.height == (uint32_t)src.rows&&info.width==(uint32_t)src.cols) in void Java_org_opencv_android_Utils)_nMatToBitmap2(JNIEnv*,jclass,jlong,jobject,jboolean,file /home/reports/ci/slave/opencv/modules/java/generator/src/cpp/util.cpp, line 107
nMatToBitmap catched cv::Exception: /home/report/ci/slave/opencv/modules/java/generator/src/utils.cpp:107: error: (-215) src.dims==2 && info.height ==(uint32_t)src.rows&&info.width==(uint32_t)src.cols in function void Java_org)opencv_android_Utils_nMatToBitmap2(KNIENV*,jclass,jlong,jobject,jboolean)
Thanks that helped get me a better approach at it and it now works thanks StevenPuttemans
I will add my solution as an answer, please accept it, so this question show solved :)
Hi andern, Can you please tell how you solved this error.