2016-08-18 2 views
0

질문 1 : 무엇을 시도 했습니까? 저는 문서 인식 및 원근 보정 기능을 갖춘 문서 스캐너 응용 프로그램을 만들고 있습니다. 이를 위해 저는 OpenCV를 사용하고 있습니다. 다음 단계는 다음과 같습니다OpenCV로 최대 윤곽 검출

  1. 는 크기 조정 이미지

    Bitmap bitmap = CameraImageUtils.decodeSampledBitmapFromResource(data[0], CameraConfigurationUtils.MIN_FRAME_WIDTH, CameraConfigurationUtils.MIN_FRAME_HEIGHT); 
    
  2. 캐니 에지 검출

    Mat srcMat = new Mat(height, width, CvType.CV_8UC3); 
        Utils.bitmapToMat(sourceBitmap, srcMat); 
        Mat imgSource = new Mat(srcMat.size(), CvType.CV_8UC1); 
        Imgproc.cvtColor(srcMat, imgSource, Imgproc.COLOR_RGB2GRAY, 4); 
        Imgproc.GaussianBlur(imgSource, imgSource, new org.opencv.core.Size(5, 5), 5); 
    
        Imgproc.Canny(imgSource, imgSource, 50, 50); 
    
        //find the contours 
        List<MatOfPoint> contours = new ArrayList<>(); 
        Imgproc.findContours(imgSource, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE); 
    
        double maxArea = -1; 
        int maxAreaIdx = -1; 
        Log.d("size", Integer.toString(contours.size())); 
        MatOfPoint temp_contour = contours.get(0); //the largest is at the index 0 for starting point 
        MatOfPoint2f approxCurve = new MatOfPoint2f(); 
        MatOfPoint largest_contour = contours.get(0); 
    
        for (int idx = 0; idx < contours.size(); idx++) { 
         temp_contour = contours.get(idx); 
         double contourarea = Imgproc.contourArea(temp_contour); 
         //compare this contour to the previous largest contour found 
         if (contourarea > maxArea) { 
          //check if this contour is a square 
          MatOfPoint2f new_mat = new MatOfPoint2f(temp_contour.toArray()); 
          int contourSize = (int) temp_contour.total(); 
          MatOfPoint2f approxCurve_temp = new MatOfPoint2f(); 
          Imgproc.approxPolyDP(new_mat, approxCurve_temp, contourSize * 0.05, true); 
          if (approxCurve_temp.total() == 4) { 
           maxArea = contourarea; 
           maxAreaIdx = idx; 
           approxCurve = approxCurve_temp; 
           largest_contour = temp_contour; 
          } 
         } 
        } 
    

    문제는 무엇인가 신청을 문서

  3. 의 사진을 찍을? 모든 윤곽선을 그리려고하지만 문서 자체가 윤곽선으로 인식되지 않습니다. Document Correction

여기서 내가 뭘 잘못하고 있니? 이 응용 프로그램의 주요 목표는 라이브 카메라 미리보기에서 문서를 감지하고 사용자가 사진을 찍을 때 크기가 줄어든 (< 160kb) 문서 만 표시하고 그림을 업로드합니다.

질문 2 : OpenCv 용 정적 초기화 프로그램을 사용하여 응용 프로그램 크기를 늘리고 싶지 않습니다. OpenCV를위한 대안이 있습니까?

답변

1

내가 말할 수는 없지만 귀하의 질문 1에 대한 답변을 드리겠습니다. 질문 1.

원본 이미지는 어디에 있습니까?

당신은 (그래서 당신은 단지 한 채널이) 0 & 255 컬러 픽셀로 구성되어 있으며 회색 이미지입니다 바이너리 이미지 같은이 필요합니다. OpenCV findContour() 기능을 사용하려면 전체 이미지 블록이 있어야합니다.

그러면 윤곽을 찾을 수있을 것입니다. 코드에는 아무런 문제가 없습니다.

추신. 윤곽 검출을 위해 Canny를 사용할 필요조차 없습니다. 정말로 이미지의 가장자리를 얻으려는 경우에만 사용하십시오.

희망이 있습니다.