【发布时间】:2012-08-31 11:37:06
【问题描述】:
我想检测图像的倾斜度。我有以下代码:
public void analyse(CvMat img) {
rows = img.rows();
cols = img.cols();
// create edge-map from rois
CvMat edgeMap = cvCreateMat(rows, cols, CV_8UC1);
cvCanny(img, edgeMap, 100, 400, 3);
// transform to hough
CvMemStorage storage = cvCreateMemStorage(0);
lines = cvHoughLines2(edgeMap, storage, CV_HOUGH_PROBABILISTIC, 1,
EuclideanDistance euclideanDistance = new EuclideanDistance();
double maxDistance = Double.MIN_VALUE;
for (int i = 0; i < lines.total(); ++i) {
Pointer line = cvGetSeqElem(lines, i);
CvPoint pt1 = new CvPoint(line).position(0);
CvPoint pt2 = new CvPoint(line).position(1);
double distance = euclideanDistance.getDistance(pt1, pt2);
double currentAngle = Math.atan2(pt2.y() - pt1.y(),
pt2.x() - pt1.x())
* 180 / Math.PI;
System.out.println(currentAngle);
if (distance > maxDistance) {
skewAngle = currentAngle;
}
}
我的测试图片是
我认为偏斜度是 -16 度,但我的代码说,是 25...
for 也打印出 25 的平均角度。我的霍夫参数有问题吗?
//编辑这里是来自 houghLines 的图
问候
【问题讨论】:
-
您似乎不小心缩放了图像 - 它是一个矩形,但现在适合正方形。问题出在外部代码上。
-
是的,谢谢...我看到了...我已将我的输入图像缩放到另一个比例....-.- thx
标签: image-processing opencv javacv skew