Ask Your Question

Angle correction of each line in an article

asked 2013-07-21 22:50:54 -0500

Salmaria gravatar image

updated 2013-07-22 23:39:46 -0500

image description

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 <math.h>
#include <stdlib.h>

int main(int argc, char** argv)
    IplImage* src = cvLoadImage("110.jpg");     
    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 );
    return 0;
edit retag flag offensive close merge delete



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.

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

1 answer

Sort by ยป oldest newest most voted

answered 2013-07-22 23:57:25 -0500

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.

edit flag offensive delete link 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 :)

StevenPuttemans gravatar imageStevenPuttemans ( 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...

Salmaria gravatar imageSalmaria ( 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

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

Question Tools


Asked: 2013-07-21 22:50:54 -0500

Seen: 677 times

Last updated: Jul 22 '13