我想製作一個橢圓蒙版來裁剪圖像,以便只顯示橢圓內的內容。OpenCV - 根本不顯示橢圓
你可以檢查我的代碼嗎?
public static Mat cropImage(Mat imageOrig, MatOfPoint contour){
Rect rect = Imgproc.boundingRect(contour);
MatOfPoint2f contour2f = new MatOfPoint2f(contour.toArray());
RotatedRect boundElps = Imgproc.fitEllipse(contour2f);
Mat out = imageOrig.submat(rect);
// the line function is working
Imgproc.line(out, new Point(0,0), new Point(out.width(), out.height()), new Scalar(0,0,255), 5);
// but not this one
Imgproc.ellipse(out, boundElps, new Scalar(255, 0, 0), 99);
return out;
}//cropImage
看起來好像根本不起作用。雖然你可以看到我所做的線函數來測試它是否在正確的圖像上工作,我可以看到一條線但沒有橢圓。
下面是我的cropImage函數的示例輸出。
TIA
唐不要裁剪圖像。您正在'imageOrig'座標系中檢索橢圓座標。如果你想在裁剪上顯示橢圓,你需要翻譯橢圓中心,例如:'boundElps.center()。x - = rect.x; boundElps.center()。y - = rect.y;' – Miki
嘿@Miki你應該讓這個答案!這解決了我的問題!謝謝! –
很高興幫助。作爲回答發佈 – Miki