Recognize multi-part shapes in image - opencv

Is this possible in OpenCV or other image processing library?
It should find 3 Shape1 and 2 Shape2. (Meaning it has to process scaling and rotation) And give a position.
I am kind of new to opencv and do not know which algorithm or functions to use to do this. Any help would be very appreciated especially any code. Would the 2 unconnected parts in Shape1 cause problems in detection?

You could try the Chamfer algorithm.
OpenCV has a CPP example in opencv/samples/cpp/chamfer.cpp.
Below is an older version I found via google:
https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/cpp/chamfer.cpp?rev=4194

Related

Emgu Cv Motion Detection

I'm working on hand detection using EmguCv. I have successfully detected the skin color object in live video feed. With in that skin detected object I want to track the moving hand only. Please someone tell me how to achieve this without degrading the performance. A code or step by step procedure will be helpful.
Is there any best reference ebook on EmguCv for learning or any other material with code snipets?
you actually need to perform a number of steps to do it.
1) you need to find the hand , the best way to figure that out will be to use HarrCascades,
you can find more about it here: http://www.360doc.com/content/11/1220/16/5087210_173660914.shtml
2)Then you need to use absolute subtraction between the current frame and the previous frame to find out the moving part in the video.
for absolute subtraction you can check this link out.
After detecting the hand you can use Mean Shift Tracking Algorithm to track the hand.There is a good implementation in Accord.NET and an example that you can use for learning how to use it. About Viola-Jones algorithm m there is a HandCascade.xml file from a guy Nikolas Markou , but when I tried it , the performance wasn't good at all and there are similare complaints from other people using that Haar Cascade.
About the reference book of EmguCv, to my best knowledge, there is only one book so far:
Emgu CV Essentials
http://www.amazon.com/Emgu-CV-Essentials-Shin-Shi-ebook/dp/B00GOMTTHI

Face Expression Change

I have seen numerous examples and sample code for detecting emotions from a human face. I am in desperate need of some algorithm to change expressions. I am a new OpenCV learner. I am also confused if this image manipulation can be done using opencv ? Can functions such as warpaffine() be used for this ? If shall be grateful if someone can guide me in steps how to perform this eg. input a neutral face emotion and convert it to smile ?
Try using FaceAPI, it is free to use for non-commercial purposes and works brilliantly. It is well documented and easy to use.

3D template matching by opencv

I have a 3D matrix (very large, let call it L) and a 3D small one (very small, let call it S) and want to use OpenCV to find the closest pattern in L.
Does OpenCV do it for me? If yes, how I should use it?
Thanks.
What you need is the Point Cloud Library, which is an open source library to work with 3D data. I can tell you from my experience, that learning to use this library is very similar to learning OpenCV because many developers work for Willow Garage, the main sponsor of OpenCV.
If you go to the PCL tutorials you will find three useful sections to solve your problem:
1) finding features in your 3D point cloud, that you can later use for matching
2) 3D object recognition based on correspondence grouping
3) Point cloud registration using methods like iterative closest point, and feature matching
No, OpenCV doesn't have anything for this.
Do you have sparse pointcloud or just 3-dim matrix?
For 3-dim matrix you can use phase correlation using FFT. Good library is FFTW
OpenCV has added some neat tools to accomplish this kind of task
Surface Matching https://docs.opencv.org/master/d9/d25/group__surface__matching.html
Silhouette based 3D tracking https://docs.opencv.org/master/d4/dc4/group__rapid.html
Convolutional Neural Network https://docs.opencv.org/master/d9/d02/group__cnn__3dobj.html

OpenCV detect numbers

I'm using OpenCV on the iPhone and need to detect numbers in an image. I split the image into smaller images so each image has only one number (1-9). All numbers are printed, NOT handwritten.
What would be the best approach to figure out the numbers with OpenCV?
UPDATE:
I have successfully found the numbers and extracted them. They look like this:
http://img198.imageshack.us/img198/5671/101ht.jpg
http://img824.imageshack.us/img824/539/606yu.jpg
When they are extracted they are in the same size and so on. I have saved a bunch of images and put them in a OCR dir where they are categorized into numbers. Like: ocr/1/100.jpg 101.jpg.... and ocr/2/200.jpg 201.jpg....
Then I was going to use the same approach as in the Basic OCR tutorial:http://blog.damiles.com/?p=93
However, I'm programming for iPhone and can't use C++ code (error on compiling and so on) and I don't have access to highgui.
I tried using cvMatchTemplate() and match a bunch of images but it seems to work pretty bad...
Any other ideas I can try?
You could start by reading about Principal Component Analysis (PCA), Fisher's Linear Discriminant Analysis (LDA), and Support Vector Machines (SVMs). These are classification methods that are extremely useful for OCR, and there are libraries in any language including C++, Python, C# etc.
It turns out that OpenCV already includes excellent implementations on PCAs and SVMs[dead link]. I haven't seen any OpenCV code examples for OCR, but you can use some modified version of face classification to perform character classification. An excellent resource for face recognition code for OpenCV is this website[dead link].
If the numbers are printed, the job is quite simple, you just need to figure out a nice set of features to match. If the numbers are one font, you can get away with this approach:
Extract the number
Find the bounding box
Scale the image down to something like 10x8, try to match the aspect ratio
Do this for a small training set, take the 'average' image for each number
For new images, follow the steps above, but the last is just a absolute image difference with each of the number-templates. Then take the sum of the differences (pixels in the difference image). The one with the minimum is your number.
All above are basic OpenCV operations.
Basically your problem is just to classify a feature vector, which is the set of pixel intensities after some preprocessing steps. You can use any classifier for this task, like eg. neural networks, which should have a C implementation inside OpenCV. You might also try a C libsvm library for Support Vector Machines.
There is a good site related to this problem with a lot of papers and a training database.
Maybe the most simple and convinient way is to use svm as ml algorithm
http://opencv.willowgarage.com/documentation/cpp/support_vector_machines.html
and gray images as feature vectors.
Objective C++?
Try renaming your .m files to .mm and you can then use c++ in your iPhone project.
Convolution Neural Networks are by far the best algorithms for hand written digits. The are implemented in most systems like USPS etc. Here are few papers explaining the algorithms.
http://yann.lecun.com/exdb/lenet/
This is a nice open source ,It is a ORCDemo on iPhone.Hope it is useful to you
Simple Digit Recognition OCR in OpenCV-Python
This might help you out. Converting the code from Python to C++ is not a difficult task, since OpenCV API's are same for the both.
Tesseract is also a nice free OCR engine that is readily available for iPhone and allows you to use your own sets of training images:
http://tinsuke.wordpress.com/2011/11/01/how-to-compile-and-use-tesseract-3-01-on-ios-sdk-5/
HOG + SVM (Try to play with kernels)

Can I get the OpenCV source code snippet for k-means clustering algorithm?

I was going the K-means algorithm as a technique for clustering images, as part of my project in the area of Image Processing. In the process, I decided to code using OpenCV libraries. So, can somebody help me in coding the algorithm in C++ using OpenCV. I can manage well, if some code snippet is provided. I just started learning about the OpenCV environment. Thank you for reading this. I ll be grateful for your help. waiting for a reply!
Before you implement clustering (k-means or otherwise), you need to figure out how to compare one image vs the other. This is usually dependent on the type of images you have, what features you can extract (colors, edges, shapes etc.).
A simple way of comparing 2 images would be to use the SURF features and compare to other images' SURF features. The OpenCV samples should get you started on how to extract SURF.
Other approaches would be to extract edges, shapes, color histograms and compare to others. Once you have done so, clustering should be fairly straightforward.
Check mlem.cpp and cxmatrix.cpp.
If you're new to OpenCV, have a look at my website.. http://aishack.in/ I've put up some tutorials/articles on vision and vision algorithms. Hopefully they'll help!

Resources