# Angle correction of each line in an article

I want to correct each line in an article. if you have any idea please help me. i have used hough transformation to detect lines. but it doesn't work for all articles. so if you have any idea please help me...

#include "stdafx.h"
#include<opencv\cv.h>
#include<opencv\cxcore.h>
#include<opencv\highgui.h>
#include <math.h>
#include <stdlib.h>

int main(int argc, char** argv)
{
IplImage* dst;
IplImage* color_dst;
IplImage* tempx = cvCreateImage(cvGetSize(src),IPL_DEPTH_16S,1);

CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* lines = 0;
int i;

if( !src )
return -1;

dst = cvCreateImage( cvGetSize(src), 8, 1 );
color_dst = cvCreateImage( cvGetSize(src), 8, 3 );
cvCanny( src, dst, 50, 200, 3 );

cvCvtColor( dst, color_dst, CV_GRAY2BGR );
CvSize size = cvGetSize(dst);

lines = cvHoughLines2( dst, storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/45, 50, 50, 10 );

for( i = 0; i < lines->total; i++ )
{
CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
cvLine( color_dst, line[0], line[1], /*CV_RGB(255,0,0)*/cvScalar(255, 0 ,0), 4, CV_AA, 0 );
}

cvNamedWindow( "Source", 1 );
cvShowImage( "Source", dst );
cvNamedWindow( "Hough", 1 );
cvShowImage( "Hough", color_dst );
cvWaitKey(0);
return 0;
}

edit retag close merge delete

2

Please read FAQ. This forum is meant to help people with their implementation problems, not for supplying complete solutions to problems. Provide us some of the code and output you already have, improve the question, show us when it goes wrong, and then people will be more eagered to help. If you don't update your topic, it will get closed.

( 2013-07-22 04:47:00 -0500 )edit

Sort by » oldest newest most voted

What is the purpose of your code? It working, right? When @StevenPuttemans has you some code, he means not working code, not the one you have done that is working.

I assume "correction" mean find lines and rotate the scanned page? If you want to detect lines, I've read long time ago an article doing this very simply: compute histogram by row in your image. The row with "many" white pixels are the one with text, the other are the white line between two line of text.

After that, you could approximate the angle using the histogram distribution by line: as you goal is to have right line, apply an angle to a line of text. Compute the new histogram. See if it is closer to an "ideal" distribution, something that have an high peak in the center and high decrease to both side.

My solution is highly experimental, and many many many others solution should have been apply for text recognition! Google it, try some, and if you have some trouble to implement it with OpenCV, ask here.

more

Amen to that! Please again I must urge to point out that this is not a pure delivery service. We are here to help you fix stuff, but not to code your problem :)

( 2013-07-23 01:01:58 -0500 )edit

ya this code is perfectly ok.. but i have told that this doesn't work for all articles.Did you tried this for 2,3 articles? I need the solution for correction after line detection. I got an idea from your answer. i was stucked at that point. so Thank you very much...

( 2013-07-23 22:00:35 -0500 )edit

@StevenPuttemans i dont want the code.. i just want an idea for line correction.and i told that this code is not working for all articles. i think you didin't get what i have asked. so if you can fix my problem. thanks to you

( 2013-07-24 03:00:22 -0500 )edit

Official site

GitHub

Wiki

Documentation

## Stats

Seen: 632 times

Last updated: Jul 22 '13