How do I recognize squares in this image? - opencv

So I'm using openCV to do square recognition on this image. I compiled the squares.c file on an image that I took and here are the results:
http://www.learntobe.org/urs/index1.php
The image on the left is the original and on the right is the image that is a result of running the square detection.
The results aren't bad, but I really need this to detect ALL of the squares and I'm really new to this openCV and image processing stuff. Does anyone know of how I can edit the squares.c file to possibly get the detection to be more inclusive so that all of the squares are highlighted?
Thanks a lot ahead of time.

All the whitish colors are tough to detect. Nothing separates it from the page itself. Try doing some kind of edge detection (check cvCanny or cvSobel).
You should also "pre-process" the image. That is, increase the contrast, make the colors more saturated, etc.
Also check this article http://www.aishack.in/2010/01/an-introduction-to-contours/ It talks about how the squares.c sample works. Then you'll understand a bit about how to improves the detection in your case.
Hope this helps!

Related

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

Opencv Haarlike eye-detection

I have run this Opencv Haarlike eye-detection from this link with C++ visual studio 2010
http://docs.opencv.org/doc/tutorials/objdetect/cascade_classifier/cascade_classifier.html
And my camera isn't running smooth. So I delete for-loop(of this code) out and running only camera. The camera running smooth.
The question is if I want to modified this code to detect eye and face.
How can I modified this code to running in smooth?
please show the example to modified this code.
Best thank and sorry for bad language
Chairat(Thailand)
Generally it's not a trivial question, but a basic idea (which i used for my BSc thesis) is quite simple. It's not the entire solution i've used, but this should be enough right now, if not - let me know i will write more about it.
For first frame:
Find face (i've used haarcascade_frontalface_default.xml cascade, but you may try with different) and remember its position.
Within face rectangle find eyes (use Haar cascade for eye pair (haarcascade_mcs_eyepair_big.xml), not for one eye - it's much faster and simpler solution) and remember position.
For other frames:
Expand (for about 20-50%) rectangle in which you have found face recently.
Find face in expanded rectangle.
Find eyes within face. If you haven't found face in previous step, you may try to search for eyes in expanded rectangle of previous eyes position.
Few important things:
while searching use CV_HAAR_FIND_BIGGEST_OBJECT flag.
convert frame to grayscale before searching - during searching opencv uses only grayscale images so it will be faster to convert whole image once than converting whole image (for first search - face) and than converting only rectangle containing face (for second search - eyes)
some people say that equalizing histogram before searching may improve results, i'm not sure about that, but if you want you may try this - use equalizeHist function. Note that it works only on grayscale images.

How to write a simple image recognition

I have a problem very similar but very much simple than this.
To begin with I have a small image:
Then I take a screenshot and I want to detect if my small house is in the screenshot.
The problem is that my house can be different in size and slightly different in color.
I've found so far the OpenCV library but it seem quite oversized for my need.
Do you know any simpler library to achieve this task?
Tx
Edit: I've found this about SURF algorithm
Judging by your question, there will be no sheer or skew to your image as it will be on screen, whereas the problem you referenced is a much more difficult situation. Your image will not experience any distortion, but only an increase/decrease in size.
To match regardless of color, I recommend computing the gradient image (using sobel kernels) for both your template image and your screen shot. Now you're matching based on visible edges and take color out of the mix.
To match regardless of size, create multiple versions of your template (the more versions you make the more precise, but the longer the processing) and slide your template across the image until you find an acceptable match.
OpenCV is a beast that has a steep learning curve. If my assumptions are correct, then you are correctly stating that OpenCV is oversized when simple image processing techniques can be applied :).

Auto-Detecting blurry regions of an image

I am working on images that are partially blur on some sections. These are noises that should be taken care of, but here is the problem:
Are there methods to detect whether an image is blur or partially blur at some sections of an image? For instance, take a look at sample image below:
You can see in the image that there are 3 sections that are visually blur: bottom-left, near center region and top-right. Now, is it possible to detect that any portion of an image is blur programming-wise or mathematically?
As lain_b pointed out, with an image like this you can use an edge detector and look for an absence of edges. I tried it on your image and it seems to work pretty well. First I used the kernel
[0,1,0,
1,-4,1,
0,1,0]
Which is a simple edge detector. Its result was
Then I used a threshold to get
Then I closed the image and opened it to get
This is obviously not a finished version, the top right portion did not recognize well at all. Perhaps you could improve it by blurring before performing thresholding, or by choosing better values for the threshold and the radii of the opening and closing operations. A lot of the decisions you will need to make depend on the constraints you can put on your problem. I think this technique will work for you though.
Edit
If you are looking for blur detection of arbitrary images you are going to have to investigate a wide variety of techniques. Things are much easier if you can make assumptions about your set of input images. Without any assumptions I don't know what will work best for you. Here is some reading on the topic
Image Blur Metrics
Reserach paper on using the Harr wavelet transform
Similar SO Question and look at the question that question links to
Blur detection is a very active research field, there is no one answer. You will just need to try all the methods you can find (these were found by googling detect blur in image).
This paper may be of some help. It does blur estimation (mostly for out of focus, but I think it also does blur) to recreate a similarly blurred object in the image.
I think you should be able to use it to detect the blurred areas, and how blurred they are. It should be especially relevent to your problem as it is designed to work with real-world images.

algorithm for detecting a circle in an image

I'm looking for an algorithm to detect circles in an image. The image is black and white. The background is white, and the circles don't overlap each other, or any other element in the image.
The image includes some other shapes and some text.
If there is some open source .NET library to do this, I would also like to know about it.
Maybe the "Hough Transform" is useful for you. You have to know the circle's size in advance to make it efficient though.
http://www.cis.rit.edu/class/simg782/lectures/lecture_10/lec782_05_10.pdf
http://en.wikipedia.org/wiki/Hough_Transform
There was a similar question yesterday, where the "Hough Transform", and some image processing libraries (though not for .NET) were proposed:
Image Processing Programming
I was looking for the same thing and what I have found to work best for now is using Mathlab (Image Processing Toolbox). It has good amount of options that lets you try different processing algorithms, threshold level and range of circle's radius.

Resources