OpenCV - Detect rough, hand-drawn circles with obstructions - opencv

I've been trying to extract hand-drawn circles from a document for a while now but every attempt I make doesn't have the level of consistency I need.
Process Album
The problem I keep coming up against is when 2 "circles" are too close they become a single contour, ruining my attempt to detect if a contour is curved. I'm sure there must be a better way to extract these circles, but their imperfection and inconsistency are really stumping me.
I've tried many other ways to single out the curves, the most accurate of which being:
Rather than use dilation to bridge the gap between the segmented contours, find the endpoints and attempt to continue the curve until it hits another contour.
Problem: I can't effectively find the turning points of the contour, otherwise this would be my preferable method
I apologize if this question is deemed "too specific", but I feel like Computer Vision stuff like this can always be applied elsewhere.
Thanks ahead of time for any and all help, I'm about at the end of my rope here.
EDIT: I've just realized the album wasn't working correctly, I think it should be fixed now though.

It looks like a very challenging problem so it is very likely that the things I am going to write wouldn't work very well in practice.
In order to ease the problem, I would probably try to remove as much of other stuff from the image as possible.
If the template of the document is always the same, it might be worth trying to remove horizontal and vertical lines along with grayed areas. For example, given the empty template, substract it from the document that you are processing. Probably, it might be possible to get rid of the text also. This would result in an image with only parts of hand drawn circles.
On such image, detecting circles or ellipses with hough transform might give some results (although shapes might be far from circles or ellipses).

Related

Most 'fitting' placement of shape in silhouette

I apologize in advance for the lack of code, but I have been looking at this problem for some days now and couldn't proceed much.
I am trying to find a method that, given a template shape and a figure, finds the most fitting (edges-wise) placement of such shape in the (binarized) figure.
For example, in the picture above, I've highlighted 2 placement for the triangle on the right (I show 2, but there are probably 5). The blue one covers more "perimeter" and thus should be preferred.
The rotations are limited to steps of 45 degrees and no scaling is involved, so I don't think I need some particularly rotation/size invariant methods.
For now, I have obtained some results using opencv template matching, by first extracting the edges with canny and matching the resulting contour, but it is far from precise and I am afraid this would not work for more complex figures. Also by using canny I lose information about the binarized foreground and background, while the placement must be only inside the figure.
Any idea would be appreciated because I really could not find much in the literature (also I am quite inexpert in the field and probably lacking the proper terminology for effective searches), thank you in advance

Area of interest and Hough Line Detection for distorted lines accuracy

I am trying to do segmentation of book spines stacked both horizontal and vertically. I have came across a problem when the picture is too big.
Only part of the image can be seen in the whole window, meaning it does not process the original image it is suppose to process:
The image it processed
The image it should process instead
I cannot even view the whole image which is suppose to be processed. Hence, I tried to minimise the window just for this picture using=>
cv::resize(image, image, cv::Size2i(image.cols/6, image.rows/6) ); // resize to 1/6 of the image
which lead to another problem, when the picture is small, it become too small that the straight lines cannot even be detected.
Hence, I tried =>
cv::resize(image, image, cv::Size2i(750, 400) );
this lead to another problem. While the image above is above to display the whole window, for smaller pictures, my houghline detection becomes more unstable.
Do anybody have an idea on how to solve this sizing problem? And also how to improve my Hough Line detection which is pretty unstable now to separate the books? I wish to draw a line in between the stack of books.
Hope to hear from you guys soon. Thanks!!!
It looks like you're resizing the image before you perform the Hough Transform, I think what you want to do it afterwards. This allows you to get enough resolution in your picture to get decent lines detected, and you can still view it on your monitor.
Secondly you want to improve detecting the separation between the books. My advice would be to perform a bit of pre-processing to the image. There are plenty of methods to do this. Mean Shift Segmentation to separate the picture by colours is one for example.
Filtering the results of the transform is another approach. Only keeping lines passing through dark areas - since it is more likely to be dark between the books - is one such way. There are plenty more methods.
Also don't forget to tweak the parameters of the Hough Transform to see what works best with your test set. It may reveal some interesting results!
Good luck!
IMO first you have to improve edge detected output.It consists of very less edges.You can use cvCanny or cvSobel for the same.Also use Probabilistic Hough lines, that will give better results.You can tweak into the parameters of cvHoughLines such as threshold, minLinLength, maxLineGap as in the fig the lines are coming too close.
Please check the details here:
http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html

Canvas Deburring Algorithm

I've got an little canvas tool I've built that cut up images into little pieces to move around, and it's working great except the resulting pieces often have little spikes left on them that I would like to remove, but I can't figure out a good algorithm for detecting and removing them. I'm not sure if an edge smoothing algorithm would work, the ones I've checked out seem like they would interpret the spikes as part of the shape. Here's an example of what one of these image pieces might look like.
Can anyone recommend anything that might get rid of the spikes?
You can try morphology filter opening, if the structure of main figure is rather simple.
Opening is erosion + dilation, so it removes small and thin elements, then restores (of course, with some artefacts) initial form of big objects.

Line detection with OpenCV

I'm trying to detect the presence of lines from a picture of a geometrical drawing. For example, there is a triangle, and I'm looking for the bisector of one of its angles. So I know exactly where and how long the line should be.
My approach so far is to detect all the lines with the Hough transform function and look for my line among those. However, this is rather slow and conceptually not very nice. Indeed, since I know the two extremities of the segment I'm looking for, it seems more natural to directly look for at this very place.
To do this, my first intuition was to use the result of Canny and loop through each pixel that should contain a line. Before I implement this, I was wondering if something similar already existed or if someone more expert in CV would recommend another approach. I've seen this but I'm looking for lines, not contour, so not sure this would work...
The Canny idea might work quite well. Since you were looking for other ideas, you might also consider trying corner detection. Assuming the geomerical shape is segmented you might try either the classic Harris corners or you might try some of the newer feature detectors like SURF, SIFT, FAST, etc. You may have to adjust the parameter sensitivities of these detectors in order to isolate the corners, but that might allow you to compute the lines based on a set of points. Also, a combination of Canny edge detection and feature detection might be more robust as well.
Just a thought :) Hope it helps!

Object Recognition from Templates

I was hoping someone could point me in the right direction here. With a picture of a die (from above) I want to recognize which side is up.
I understand the basics in play here, but I'm having trouble grasping the power of OpenCV. I imagine I want a picture of each side of the die. Then I can somehow compare them all to the current image to be classified. How can I use OpenCV to do this?
Thanks,
Jonathan
While that would work and OpenCV has template matching functions, it would probably be harder than necessary. Good results would require that the lighting is more or less unchanged between all images, and that the camera is fixed and no projective distorsions occur.
Instead, I would do something like this:
In the image, locate the die. The difficulty here will vary with regard to how the die looks and the background. If you have a white die on a lpain black (or some other color) background then finding the die will be easy.
When the die has been located, find the eyes. This can be done by simply finding all black blobs.
If necessary, make sure that the found eyes form a coherent pattern. E.g. if the side up is four you expect to find the eyes as the corners in a square, not on a straight line.
Count valid eyes. There's your side up.
This outline is quite vague as there are lots of ways of performing each step. I do however believe that everything you need is available in OpenCV.
Good luck!

Resources