1
我試圖提取矩形掃描圖像,像這樣:
我使用的OpenCV及以下this tutorial,我來到這個代碼選擇了霍夫變換參數
private static Mat detectLinesHough(Mat img) {
Mat lines = new Mat();
// Mat edges = new Mat();
// Imgproc.Canny(img, edges, 20, 60);
int threshold = 80;
int minLineLength = 10;
int maxLineGap = 5;
double rho = 0.4;
Imgproc.HoughLinesP(img, lines, rho, Math.PI/180, threshold, minLineLength, maxLineGap);
Imgproc.cvtColor(img, img, Imgproc.COLOR_GRAY2RGB);
System.out.println(lines.cols());
for (int x = 0; x < lines.cols(); x++) {
double[] vec = lines.get(0, x);
double x1 = vec[0], y1 = vec[1], x2 = vec[2], y2 = vec[3];
Point start = new Point(x1, y1);
Point end = new Point(x2, y2);
Core.line(lines, start, end, new Scalar(0, 255, 0), 3);
}
return img;
}
例如,如上面的代碼中的參數,我得到以下結果:
結果不令人滿意,所以問題是 - 我應該如何選擇參數來選擇所有矩形而不是許多字母?