Ask Your Question

rasterdetect's profile - activity

2016-01-29 18:54:22 -0600 commented answer Detect If area above line is empty

This worked thanks!

2016-01-29 17:18:51 -0600 asked a question Detect If area above line is empty

I am starting with the following image

image description

and I am identifying the horizontal lines in order to find the form fields. I am using the following code

Mat src=imread(filename);

    cerr<<"problem loading image"<<endl;

Mat rsz;

Size size(800,900);

resize(src, rsz, size);

Mat gray;


Mat bw;
adaptiveThreshold(~gray, bw, 255,CV_ADAPTIVE_THRESH_MEAN_C,THRESH_BINARY, 15,-2);

Mat horizontal = bw.clone();
Mat vertical =bw.clone();

int scale = 25;

int horizontalsize = horizontal.cols/scale;

Mat horizontalStructure = getStructuringElement(MORPH_RECT,Size(horizontalsize,1));

erode(horizontal, horizontal, horizontalStructure, Point(-1, -1));
dilate(horizontal, horizontal, horizontalStructure, Point(-1, -1));

vector<Vec4i> hierarchy;
vector<vector<Point> > contours;

findContours(horizontal, contours, hierarchy, CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE, Point(0, 0));

vector<vector<Point> > contours_poly( contours.size() );
vector<Rect> boundRect( contours.size() );
vector<Mat> rois;

for (size_t i = 0; i < contours.size(); i++)

    approxPolyDP( Mat(contours[i]), contours_poly[i], 3,true );
    boundRect[i] = boundingRect( Mat(contours_poly[i]) );

    rectangle( rsz, boundRect[i].tl(), boundRect[i].br(),Scalar(0, 255, 0), 1, 8, 0 );

which gives me

image description

which seems to work almost perfectly except it finds the line in the link in the top right. I don't want this line to be found. So somehow I have to filter the bounding rectangles based on whether they have empty space above them (the link obviously would not pass this filter). Does anyone know how I can implement this filter? From the code you can see that I have the bounding rectangle objects which contain their position, so I think I just need to check if some small bounding rectangle above it is empty.

2016-01-29 17:15:24 -0600 received badge  Student (source)
2016-01-29 16:30:43 -0600 commented question Draw Extracted Lines over Original Image

Ok I can add them now by transforming horizontal into rgb by using cvtColor. But the problem is that the horizontal lines are white, and I want to add them as green and I don't know how to do this.

2016-01-29 15:21:57 -0600 asked a question Draw Extracted Lines over Original Image

I am extracting horizontal lines from an image in the exact same way as this opencv tutorial

Which allows you to extract the the horizontal lines and display them. But what I want to do is draw the extracted horizontal lines over the original image in a different colour (say green). I haven't been able to figure out how to do this. I tried simply adding the horizontal matrix to the original src matrix but this creates a runtime error.

2015-11-05 19:46:36 -0600 received badge  Scholar (source)
2015-11-05 16:26:08 -0600 asked a question Detect Images in an image of a text document

I have the following image of a document

image description

And I want to be able to detect the images at the top of the page. I tried using line detection using erosion and dilation to get bounding boxes around the images but that did not work because the edge of the images contain many different colors, so the detected lines do not form a box.

Can anyone think of a better approach to detecting these images. Perhaps exploiting the fact that the images have color and the rest of the document is black and white. However, a this approach would not be ideal for the case when the images themselves are black and white.

2015-11-04 17:06:24 -0600 received badge  Supporter (source)
2015-11-04 15:23:30 -0600 commented answer How to extract tables from an image?

It looks like you find contours in the matrix of joints (inside the loop). I'm wondering what this means intuitively?

2015-11-04 12:12:20 -0600 received badge  Enthusiast
2015-11-01 11:07:56 -0600 commented question Will Object Detection Work with Binary Images?

Its actually rasterized images of a pdfs that I am working with, not the pdfs themselves

2015-10-31 21:39:33 -0600 received badge  Editor (source)
2015-10-31 21:32:34 -0600 commented question Will Object Detection Work with Binary Images?

I see your point. But my precise goal is not to identify "images" in general, rather to identify all rectangular shapes within a pdf document which could possibly contain an image or table. So perhaps a rectangle detector would be the way to go. I agree that training a haarcascade on images in general would not work because there is way too much variability for that problem. However training it on tables might work since all tables have a somewhat common structure (i.e. rows and columns).

2015-10-31 00:10:02 -0600 asked a question Will Object Detection Work with Binary Images?

I am completely new to opencv and machine vision in general. My problem involves detecting objects in rasterized images of pdf documents. So these are essentially binary images. My question is will the object detection algorithms in opencv still work with binary images? I assume that image gradients play an important role in object detection algorithms, so if they do not exist in binary images then these algorithms might not work well. To be specific I am trying to be able to detect the following kinds objects from pdf raster images.

  • Tables
  • Images
  • Textblocks
  • Form fields, etc.

To do this my plan is to use the opencv cascade classifier for supervised object detection. If that fails I thought that another option would be to use opencv's line, rectangle, and text block detection along with some heuristics to identify some of these objects in an unsupervised way.

So in summary, I wish to know if this is a worthwhile direction to go in given that the images I am working with are binary.

Update:So it looks like this question has more or less been asked and answered before here