i want to detect the skew level from an image. I've the following code:
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;
}
}
My test image is
I think the skew level is by -16 degree but my code says, that is by 25...
The for prints out a avg angle by 25,too. Thats wrong with my hough parameters?
//EDIT here is a drawing from the houghLines
greetings