我正在按照 openCV 的文档/教程来检测图像中的线条。但是,我只得到了图像中四个相似线条中的一个。这是结果
这是我的代码:
Mat im = Imgcodecs.imread("C:/Users/valer/eclipse-workspace/thesis-application/StartHere/resource/4 lines.JPG");
Mat gray = new Mat(im.rows(), im.cols(), CvType.CV_8SC1);
Imgproc.cvtColor(im, gray, Imgproc.COLOR_RGB2GRAY);
Imgproc.Canny(gray, gray, 50, 150);
Mat lines = new Mat();
Imgproc.HoughLines(gray, lines, 1, Math.PI/180, 200);
for (int i = 0; i < lines.cols(); i++){
double data[] = lines.get(0, i);
double rho = data[0];
double theta = data[1];
double cosTheta = Math.cos(theta);
double sinTheta = Math.sin(theta);
double x0 = cosTheta * rho;
double y0 = sinTheta * rho;
Point pt1 = new Point(x0 + 10000 * (-sinTheta), y0 + 10000 * cosTheta);
Point pt2 = new Point(x0 - 10000 * (-sinTheta), y0 - 10000 * cosTheta);
Imgproc.line(im, pt1, pt2, new Scalar(0, 0, 200), 3);
}
Imgcodecs.imwrite("C:/Users/valer/eclipse-workspace/thesis-application/StartHere/resource/process/line_output.jpg", im);
我尝试过使用阈值参数,但我一直得到相同(有时是最差)的结果。有人能指出我在哪里做错了吗?