OpenCV Android แยกตรงกับ Mat หลังจากการตรวจจับคุณสมบัติ

ฉันต้องการแยกส่วนของรูปภาพที่ตรงกับรูปภาพอ้างอิงของฉัน ฉันพยายามแปลงภาพโดยใช้วิธี Calib3d.findHomography เมื่อฉันทำสิ่งนี้เสร็จแล้ว ฉันจะใช้ Imgproc.warpPerspective เพื่อทำการเปลี่ยนแปลงแต่กลับไม่มีผลลัพธ์ที่ดี ฉันพลาดอะไรบางอย่างที่นี่? ฉันจำเป็นต้องทำอะไรกับ PerspectiveTransform หรือไม่? ฉันได้ลองสิ่งนี้แล้วแต่ยังไม่มีโชคเลย

นี่คือวิธี findSceneCorners ของฉัน:

 private void findSceneCorners(Mat src) {
    mFeatureDetector.detect(src, mSceneKeypoints);
    mDescriptorExtractor.compute(src, mSceneKeypoints, mSceneDescriptors); 
    mDescriptorMatcher.match(mSceneDescriptors, mReferenceDescriptors, mMatches);

    List<DMatch> matchesList = mMatches.toList();
    if (matchesList.size() < 4) {
        // There are too few matches to find the homography.
        return;
    }

    List<KeyPoint> referenceKeypointsList =
            mReferenceKeypoints.toList();
    List<KeyPoint> sceneKeypointsList =
            mSceneKeypoints.toList();

    // Calculate the max and min distances between keypoints.
    double maxDist = 0.0;
    double minDist = Double.MAX_VALUE;
    for(DMatch match : matchesList) {
        double dist = match.distance;
        if (dist < minDist) {
            minDist = dist;
        }
        if (dist > maxDist) {
            maxDist = dist;
        }
    }

    // The thresholds for minDist are chosen subjectively
    // based on testing. The unit is not related to pixel
    // distances; it is related to the number of failed tests
    // for similarity between the matched descriptors.
    if (minDist > 50.0) {
        // The target is completely lost.
        // Discard any previously found corners.
        mSceneCorners.create(0, 0, mSceneCorners.type());
        return;
    } else if (minDist > 20.0) {
        // The target is lost but maybe it is still close.
        // Keep any previously found corners.
        return;
    }


    // Identify "good" keypoints based on match distance.
    ArrayList<Point> goodReferencePointsList =
            new ArrayList<Point>();
    ArrayList<Point> goodScenePointsList =
            new ArrayList<Point>();

    double maxGoodMatchDist = 1.75 * minDist;
    for(DMatch match : matchesList) {
        if (match.distance < maxGoodMatchDist) {
           goodReferencePointsList.add(
                   referenceKeypointsList.get(match.trainIdx).pt);
           goodScenePointsList.add(
                   sceneKeypointsList.get(match.queryIdx).pt);
        }
    }

    if (goodReferencePointsList.size() < 4 ||
            goodScenePointsList.size() < 4) {
        // There are too few good points to find the homography.
        return;
    }

    Log.i(TAG, "Match found");

    MatOfPoint2f goodReferencePoints = new MatOfPoint2f();
    goodReferencePoints.fromList(goodReferencePointsList);

    MatOfPoint2f goodScenePoints = new MatOfPoint2f();
    goodScenePoints.fromList(goodScenePointsList);

    homography = Calib3d.findHomography(goodReferencePoints, goodScenePoints);

    Mat quad = new Mat(mReferenceImage.size(), CvType.CV_32F);
    Imgproc.warpPerspective(src, quad, homography, quad.size());
    objectDetectedListener.objectDetected(quad);

}

person Smek    schedule 13.01.2014    source แหล่งที่มา
comment
นี่คือเป็นบทช่วยสอนที่ OpenCV แนะนำ คุณเคยลองแล้วหรือยัง ? มันก็ช่วยได้   -  person thedarkside ofthemoon    schedule 13.01.2014
comment
ฉันมีรหัสที่ใช้งานได้อยู่แล้ว อะไรที่ทำอย่างนั้น ลากเส้นรอบวัตถุที่พบ แต่สิ่งที่ฉันพยายามทำให้สำเร็จคือการแยกส่วนของภาพที่ตรงกับวัตถุ Mat ใหม่   -  person Smek    schedule 13.01.2014
comment
ฉันไม่ได้ติดตั้ง OpenCV บนคอมพิวเตอร์เครื่องนี้ ฉันขอแนะนำให้คุณแสดงรูปภาพ บางทีคุณอาจจะรู้ว่าเกิดอะไรขึ้น ฉันจะให้คำตอบแก่คุณสำหรับวันพรุ่งนี้หากไม่มีใครตอบในขณะเดียวกัน   -  person thedarkside ofthemoon    schedule 13.01.2014
comment
นี่คือคือสิ่งที่ฉันต้องการทำให้สำเร็จยกเว้น i ไม่ได้ใช้ canny แต่เป็นการตรวจจับคุณสมบัติ และรูปสี่เหลี่ยมจะขึ้นอยู่กับรูปภาพเทมเพลต   -  person Smek    schedule 13.01.2014
comment
ดูอันนี้ อาจจะช่วยได้   -  person thedarkside ofthemoon    schedule 13.01.2014


คำตอบ (1)


ฉันคิดว่าคุณควรใช้ WARP_INVERSE_MAP เป็นธงของ warpPerspective เป็น: Imgproc.warpPerspective(src, quad, homography, quad.size(),WARP_INVERSE_MAP);

ฉันไม่ได้ใช้โค้ดของคุณทุกประการ แต่เป็นเพียงส่วนหลังจากโฮโมกราฟี และฉันเห็นว่าภาพบิดเบี้ยวในกระจก ไม่ใช่อย่างที่เราต้องการ (ใช้รูปภาพที่แสดงขนาดใหญ่ขึ้นเพื่อดูว่ามีอะไรอยู่บ้าง) จริงๆแล้วในเพจที่คุณโพสต์ด้วยไพ่ 10 ใบนั้นมีการใช้แฟล็กนั้น ขออภัยที่ฉันไม่ได้คิดจะพูดถึงเรื่องนี้ก่อนหน้านี้

person thedarkside ofthemoon    schedule 13.01.2014
comment
ขอบคุณ thedarkside ofthemoon มันทำงานได้อย่างสมบูรณ์แบบ - person Smek; 14.01.2014