2017-03-05 6 views
1

私は画像の顔検出のための検出器を構築しようとしています。私はOpenCVライブラリ、バージョン2.4.11を使用しています。FaceDetectorはタイプに解決できません

import org.opencv.core.Core; 
import org.opencv.core.Mat; 
import org.opencv.core.MatOfRect; 
import org.opencv.core.Point; 
import org.opencv.core.Rect; 
import org.opencv.core.Scalar; 
import org.opencv.highgui.Highgui; 
import org.opencv.objdetect.CascadeClassifier; 

public class DetectFaces { 

    public static void main(String[] args) { 

     System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 
     System.out.println("\nRunning FaceDetector"); 

     CascadeClassifier faceDetector = new CascadeClassifier(FaceDetector.class.getResource("haarcascade_frontalface_alt.xml").getPath()); 
     Mat image = Highgui 
       .imread(FaceDetector.class.getResource("pic.JPG").getPath()); 

     MatOfRect faceDetections = new MatOfRect(); 
     faceDetector.detectMultiScale(image, faceDetections); 

     // System.out.println(String.format("Detected %s faces", faceDetections.toArray().length)); 

     for (Rect rect : faceDetections.toArray()) { 
      Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), 
        new Scalar(0, 255, 0)); 
     } 

     String filename = "ouput.png"; 
     // System.out.println(String.format("Writing %s", filename)); 
     Highgui.imwrite(filename, image); 
    } 
} 

は今、私はFaceDetector.classが呼び出されるたびにFaceDetector cannot be resolved to a type例外を取得:

今私のソースコードは次のようになります。

私はtutorial

任意の提案は歓迎されている次のです。この実装に取り​​組んでいますが。 ありがとう

+1

「DetectFaces」クラスと同じパッケージにありますか? – jlordo

+0

チュートリアルを正しく読み込んでコピー・ペーストしませんでした。あなたが書いているクラスは、 'DetectFaces'ではなく' FaceDetector'という名前です...! – Tunaki

+0

@俊明。あなたは正しいです、ありがとうございます。しかし、これはあなたがリンクしているトピックにどのように貢献していますか? –

答えて

0

クラスをインポートするのを忘れましたか? 同じフォルダにありますか?

関連する問題