[英]Java Opencv not detecting contours. imgproc.Drawcontours()
我正在嘗試在Xamarin上開發移動應用程序。 首先,我正在為android設備執行此操作。 我希望Oncamera功能自動檢測輪廓並測量對象的大小。 作為主要步驟,我試圖實時檢測輪廓。 閱讀了很多表格和文件,但沒有任何幫助
public Mat OnCameraFrame(CameraBridgeViewBase.ICvCameraViewFrame inputFrame)
{
Mat input = inputFrame.Rgba();
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat gray = new Mat();
//Mat hierarchy = new Mat();
Imgproc.CvtColor(p0: input, p1: gray, p2: Imgproc.ColorRgb2gray);
Mat blur = new Mat();
Imgproc.GaussianBlur(gray, blur, new Size(7, 7), -2);
Mat thresh = new Mat();
Imgproc.Threshold(blur, thresh, 127, 250, Imgproc.ThreshBinary);
Mat edged = new Mat();
Imgproc.Canny(thresh, thresh, 25, 50);
Imgproc.Dilate(thresh, thresh, new Mat(), new Point(-1, 1), 1);
Mat hierarchy = thresh.Clone();
Imgproc.FindContours(hierarchy, contours, new Mat(),
Imgproc.RetrExternal, Imgproc.ChainApproxNone);
Java.Lang.JavaSystem.Out.Println("contours" + contours);
if (contours != null)
{
Java.Lang.JavaSystem.Out.Println("found contours");
for (int i = 0; i < contours.Count(); i++)
{
Imgproc.DrawContours(input, contours, i, new Scalar(255, 0, 0), -1);
}
}
else
{
Java.Lang.JavaSystem.Out.Println("no contours");
}
return input;
我在代碼中使用了上述邏輯。 但是我在應用程序中的輸出顯示的是正常圖像,沒有在其上繪制任何輪廓。 如果我返回“脫粒”,則說明精巧邊緣檢測正常運行。 但是Drawcontours沒有顯示任何內容。 我使用Contours.count()是因為我的Xamarin ide顯示了Silhouettes.Size()錯誤。
我有一個類似的問題。 就我而言,我已經更換了
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
與
IList<MatOfPoint> contours = new JavaList<MatOfPoint>();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.