OpenCV文档扫描算法

时间:2019-06-08 10:42:38

标签: android opencv4android

我正在开发Office镜头之类的文档扫描仪应用程序。实时边缘检测,但无法准确检测。我在android studio中使用带有ndk的opencv开发应用程序

我的算法

  extern "C"
 JNIEXPORT jobject JNICALL
   Java_com_example_lenovo_cricledection_MainActivitysca_doWithMat(JNIEnv 
  *env, 
  jobject instance,
                                                  jlong matAddrGr, jlong 
 matAddrRgba) {

 Mat &image = *(Mat *) matAddrRgba;
  Rect bounding_rect;

 Mat thr(image.rows, image.cols, CV_8UC1);
 cvtColor(image, thr, CV_BGR2GRAY); //Convert to gray
threshold(thr, thr, 150, 255, THRESH_BINARY + THRESH_OTSU); //Threshold 
  the gray

vector<vector<Point> > contours; // Vector for storing contour
vector<Vec4i> hierarchy;
findContours(thr, contours, hierarchy, CV_RETR_CCOMP,
         CV_CHAIN_APPROX_SIMPLE); // Find the contours in the image
 sort(contours.begin(), contours.end(),
 compareContourAreas);            //Store the index of largest contour
 bounding_rect = boundingRect((const _InputArray &) contours[0]);

 rectangle(image, bounding_rect, Scalar(250, 250, 250) , 3);
  jclass rectClass = env->FindClass("org/opencv/core/Rect");
  jmethodID rectCtorID = env->GetMethodID(rectClass, "<init>", "(IIII)V");
  return env->NewObject(rectClass, rectCtorID, bounding_rect.x, 
  bounding_rect.y, 
  bounding_rect.width, bounding_rect.height);

}

我的输出

Image Output

我的问题:

1。如何查找文档轮廓

2。如何在android中裁剪检测文档

0 个答案:

没有答案