2017-08-03 10 views
0

私は画像を処理し、バイナリ画像を返すAndroidのコードを持っています。opencvを使ってAndroidで輪郭を描く

Imgproc.cvtColor(source, middle, Imgproc.COLOR_RGB2GRAY); 
    Mat element = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(15, 15), new Point(0, 0)); 
    Imgproc.morphologyEx(middle, middle, MORPH_TOPHAT, element, new Point(0, 0)); 
    Imgproc.threshold(middle, middle, 20, 255, Imgproc.THRESH_BINARY); 

enter image description here

[enter image description here] [2

は今、私の要件ではなく、二値画像の私は、元の画像の上にくぼみを強調表示する必要があること、です。このように:

私は何を考え出したことはへこみの座標を取得し、元のimage.Thisにdrawcontoursを使用する

Core.findnonzero() 

を使用することですちょうど考えです。

私の質問は次のとおりです: 1.それを行う最善の方法は何ですか? 2. matofpointとは何ですか?

答えて

0

あなたはbinnary画像(あなたのコードのようにmiddle)上のOpenCVのfindContours()機能を使用して、すべてのリストのトップレベルの輪郭上に反復し、元(ソース)画像上に描画し、このようなだけで何かすることができます:

List<MatOfPoint> contours = new ArrayList<>(); 
Mat hierarchy = new Mat(); 
Imgproc.findContours(middle, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); 

// now iterate over all top level contours 
for(int idx = 0; idx >= 0; idx = (int) hierarchy.get(0, idx)[0]) { 
    MatOfPoint matOfPoint = contours.get(idx); 
    Rect rect = Imgproc.boundingRect(matOfPoint); 
    Imgproc.rectangle(originalImage, rect.tl(), rect.br(), new Scalar(0, 0, 255)); 
} 
関連する問題