2016-08-18 9 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()機能が動作するためには、完全なイメージブロックを持つ必要があります。

あなたの輪郭が見つかるはずです。あなたのコードに問題はありません。

PS。輪郭検出にCannyを使用する必要はありません。本当にイメージの端を取得したい場合にのみ使用します。

希望します。