i want to find closest match of image . for example there is image of car and bike . If given image is of bike .then it should compare given image to stored car and bike and give result according to which ever is closed base on shape .
I wanted to know is it possible to find contour and match with closest one .
I tried doing using haar cascade in open cv .By training car images and bike .
but results were not correct may be bez of less no of training data.(i dont want to use this )
You're going to have an uphill struggle using standard techniques like contours for this.
Edit >> So, using your bike example, what will happen here:
?
Neural Networks and other machine learning algorithms are your best bet instead:
Specifically of the 'Multiclass Classification' variety. With training (time), they stand a better chance of sorting your cats from your bicycles.
As for code examples have a look here. Not an image based example, but you need to start somewhere :)
Also helpful (and tested working by myself) is the DLIB library:
With only 8 training images of a stop sign, its internal structure formed this representation:
Pretty nifty.
There is no reason you cant use your contours results as inputs to a ML classifier, as long as they increase the signal to noise ratio somehow... (i.e. they're somehow more 'bikey' than not)
In my opinion the following methods can be applied and tested ->
GF-HOG
Deformable Parts Model
Neural Networks
A combination would be an awesome idea but will GFHOG will add to overheads.
Study about it its pretty cool tech I think this will answer your query.
http://personal.ee.surrey.ac.uk/Personal/R.Hu/ICIP.html
Related
I am trying to detect electrical symbol in electrical scheme.
Here I think 2 ways could be use:
classical way with OpenCV, I tried re to recognise shape with opencv and python but some symbole are too complexe
deep learning way: I tried with Mask-RCNN using a handmade dataset of symbol but nothing get really successful
Here is a really simple example of what I would like to do:
I think it could be easy to make a dataset of symbol but all symbol would be the same form and context of the image would not be represented.
How do you think I could handle this problem ?
QATM:Quality-Aware Template Matching For Deep Learning might be what you are looking for.
Original paper : https://arxiv.org/abs/1903.07254
And the following github contain an example with electric scheme:
https://github.com/kamata1729/QATM_pytorch
Since the components of electrical scheme are always the same, I would try first Template Matching with OpenCV. I guess you will have to cut the components and make rotated copies to find all of them. It would be also nice to have better resolution of the images.
Next idea, I would say is making convolution with kernel which would be basicly the component you are expecting to be in the image.
Lastly, idea, which will give you definitely more certain results, but its pretty much overkill, is to use google image recognition, which you can use with python and train it on your images
https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_template_matching/py_template_matching.html
I want to identify three different objects from a satellite wind image. The problem is three of them are somewhat similar. I tried to identify using templete matching but it didn't work. Three objects are as follows.
Here the direction of the object is not important but the type of the head in the line is important. Can you suggest a way to proceed?
Assuming your image consists of only pure black and pure white pixels,
You can find contours and its bounding rectangle or minAreaRect for each of them.
https://docs.opencv.org/2.4/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=minarearect#minarearect
Then iterate over the contours considering there rectangles as separate images. Now you do classification of these images. You may use template matching too.
Good luck!
Have you thought about machine learning?
for example a small cnn that is used for digits recognition could be "retrained" using a small set of your images, Keras also has an data augmentation feature to help ensure a robust classifier is trained.
There is a very good blog post by
Yash Katariya found # https://yashk2810.github.io/Applying-Convolutional-Neural-Network-on-the-MNIST-dataset/, in which the MNIST data set is loaded in and the network is trained, it goes through all of the stages you'd need to in order to use ML for your problem.
You mention you've tried template matching, however you also mention that the rotation is not important, which to me implies that an object could be rotated, that would cause failures for TM.
You could look into LBP (Local Binary Patterns), or maybe OpenCV's Haar Classifier (however it's sensitive to rotation).
Other than the items I have suggested there is a great tutorial found # https://gogul09.github.io/software/image-classification-python which uses features and machine learning you may benefit from looking at to apply to this problem.
I hope while not actually giving you an answer to your question directly, I have given you a set of tools you can use that will solve it with some time invested and some reading.
I am currently working on vehicle platooning for which I need to design a code in python opencv for counting the number of vehicles based on the classification.The input is a real time traffic video.
The aim is finding an average size "x" for the bounding box and say that for cars its "x", for buses its "3x" and so on.Based on size of "x" or multiples of "x", determine the classification.Is there any possible way I can approach this problem statement?
Haar-cascades are a good method, however training them takes a lot of time as well as effort.
You can get a lot of trained cascades file online.
Second approach could be of getting the contours from the image and then proceeding forward.
- Original image
- Smooth the image so that you will get an image without edges.
- (Original image- Smooth image) to get the edges
- Get Contours from image
I have worked on almost similar problem.
Easiest way is to train a Haar-cascade on the vehicles of similar size.
You will have to train multiple cascades based on the number of categories.
Data for the cascade can be downloaded from any used car selling site using some browser plugin.
The negative sets pretty much depend on the context in which this solution will be used.
This also brings the issue that, if you plan to do this on a busy street, there are going to be many unforeseen scenarios. For example, pedestrian walking in the FoV. Also, FoV needs to be fixed, especially the distance from which objects are observed. Trail and error is the only way to achieve sweet-spot for the thresholds, if any.
Now I am going to suggest something outside the scope of the question you asked.
Though this is purely image processing based approach, you can turn the problem on its face, and ask a question 'Why' classification is needed? Depending on the use-case, more often than not, it will be possible to train a deep reinforcement learning agent. It will solve the problem without getting into lot of manual work.
Let me know in case of a specific issues.
I would like to segment this image
(I want only the bees, I have 100 images like that not labelled). I think that the best way to do that is to use frenquency domain because the bees seems to have specific frequencies. But I'm not sure how to do that. How to find the right frequencies ?
Or maybe you think of a better way to do that ?
Thanks in advance !
I would strongly suggest against using frequency domain methods for segmentation:
The nice thing about frequency domain is that it captures non-local properties like textures. However, the price you pay for this global information is the lack of location information: it is very non-trivial to say "where in the picture this frequency comes from". Alas, this location information is crucial for segmentation: you must know which pixel belongs to what "frequency"/texture/region...
There are frequency based descriptors that are designed to maintain some locality information (e.g., Gabor filters etc.). However, these techniques are not easy to implement "out-of-the-box".
Have you considered using deep semantic segmentation methods? If you do not have a lot of labeled images, I would suggest you look at something semi-supervised like Ning Xu, Brian Price, Scott Cohen, Jimei Yang, Thomas Huang, Deep GrabCut for Object Selection (arXiv 2017).
Thanks shai for your answer !
I ended up solving this task by using CNN (unet architecture ). I annotated 3 full images and it was enough because there is a lot of bees in one image. The training was done using small patches (big enough to contain one bee ) and not the entire image.
Also I use CRF to improve the segmentation !
I tested the method in 50 images, and it ended up working very well :)
Suppose I have an image of a car taken from my mobile camera and I have another image of the same car taken downloaded from the internet.
(For simplicity please assume that both the images contain the same side view projection of the same car.)
How can I detect that both the images are representing the same object i.e. the car, in this case, using OpenCV?
I've tried template matching, feature matching (ORB) etc but those are not working and are not providing satisfactory results.
SIFT feature matching might produce better results than ORB. However, the main problem here is that you have only one image of each type (from the mobile camera and from the Internet. If you have a large number of images of this car model, then you can train a machine learning system using those images. Later you can submit one image of the car to the machine learning system and there is a much higher chance of the machine learning system recognizing it.
From a machine learning point of view, using only one image as the master and matching another with it is analogous to teaching a child the letter "A" using only one handwritten letter "A", and expecting him/her to recognize any handwritten letter "A" written by anyone.
Think about how you can mathematically describe the car's features so that every car is different. Maybe every car has a different size of wheels? Maybe the distance from the door handle to bottom of the side window is a unique characteristic for every car? Maybe every car's proportion of front side window's to rear side window's width is an individual feature of that car?
You probably can't answer yes with 100% confidence to any of these quesitons. But, what you can do, is combine those into a multidimensional feature vector and perform classification.
Now, what will be the crucial part here is that since you're doing manual feature description, you need to take care of doing an excellent work and testing every step of the way. For example, you need to design features that will be scale and perspective invariant. Here, I'd recommend reading on how face detection was designed to fulfill that requirement.
Will Machine Learning be a better solution? Depends greatly on two things. Firstly, what kind of data are you planning to throw at the algorithm. Secondly, how well can you control the process.
What most people don't realize today, is that Machine Learning is not some magical solution to every problem. It is a tool and as every tool it needs proper handling to provide results. If I were to give you advice, I'd say you will not handle it very well yet.
My suggestion: get acquainted with basic feature extraction and general image processing algorithms. Edge detection (Canny, Sobel), contour finding, shape description, hough transform, morphological operations, masking, etc. Without those at your fingertips, I'd say in that particular case, even Machine Learning will not save you.
I'm sorry: there is no shortcut here. You need to do your homework in order to make that one work. But don't let that scare you. It's a great project. Good luck!