usernan
usernan

Reputation: 592

OpenCV to recognize image using python

I am new to OpenCV. I am using OpenCV 3.1 and python 2.7.

I have 5 images of bikes and 5 images of cars. I want to find out given any image is it a car or a bike .

On the internet I found out that using haar cascade we can train, but most of the examples contain only one trained data means, the user will train only car images and with query image and they will try to find it it is a car or not, but I want to check if it is a car or a bike or nothing.

I want to match images based on shape of objects. Another option I was thinking that take query image and compare with stored images and depending upon similarity give the result. But I know this would take longer time which would be not good.

Are there any better option? There is also template matching but I dont know which would be better options to go for this kind of solution since I dont have knowledge about OpenCV.

Upvotes: 4

Views: 1353

Answers (3)

sj7
sj7

Reputation: 1321

You can try building a model by uploading your training data (images of cars and bikes) to demo.nanonets.ai (free to use)

1) Upload your training data here:

demo.nanonets.ai

2) Then query the API using the following (Python Code):

import requests
import json
import urllib
model_name = "Enter-Your-Model-Name-Here"
url = "http://blog.caranddriver.com/wp-content/uploads/2015/11/BMW-2-series.jpg"
files = {'uploadfile': urllib.urlopen(url).read()}
url = "http://demo.nanonets.ai/classify/?appId="+model_name
r = requests.post(url, files=files)
print json.loads(r.content)

3) the response looks like:

{
  "message": "Model trained",
  "result": [
    {
      "label": "Car",
      "probability": 0.97
    },
    {
      "label": "Bike",
      "probability": 0.03
    }
  ]
}

Upvotes: 1

sietschie
sietschie

Reputation: 7543

Regarding your question about the haar cascades. You can use them to classify the images the way you want:

Train two haar cascades, one for cars and one for bikes. Both cascades will return a value of how certain they are, that the image contains the object they were trained for. If both are uncertain, the image probably contains nothing. Otherwise you take the class with the higher certainty for the content of the image.

Upvotes: 1

Related Questions