Ask Your Question

Taseer's profile - activity

2020-08-16 15:42:30 -0500 received badge  Popular Question (source)
2017-05-12 06:15:47 -0500 received badge  Student (source)
2016-05-19 10:49:03 -0500 asked a question Get Support Vectors from SVM XML file

I am using Python to train a SVM on features extracted using the HoG.

I have extracted all the HoG features, trained the SVM and saved the results in an XML file.

Now I need to get the Support Vectors, but I am not able to do so.

How do I parse the XML to get the desired Support Vectors ?

2016-05-18 15:10:29 -0500 asked a question Object Localization Using HoG (sklearn)

I am trying to localize number plate in an image. I am using HoG to extract the features and Linear SVM for the training purposes.

I am using the sklearn library for the above purpose, however I can not find any function to detect or localize the number plate.

Is there anyway I can do it ?

Below is the code for prediction, etc:

import cv2 
from sklearn.externals import joblib 
from skimage.feature import hog 
import numpy as np 

clf = joblib.load('trained.pkl')
img = cv2.imread('/home/taseer/Python/Image_Processing/Project/test/2.jpg',0)

features = hog(img,orientations=9, pixels_per_cell=(14, 14), cells_per_block=(1, 1), visualise=False)
pred = clf.predict(np.array(features))
print pred

cv2.imshow("img", img) 
 cv2.waitKey(0)
cv2.destroyAllWindows()
2016-05-14 05:35:14 -0500 asked a question Python Function Similiar to Matlab's rangefilt()

Hi, I am working on machine learning where I have to extract certain features. One of these is to find the mean and standard deviation of the image range. The above task can be easily done in MatLab using the rangefilt() function, which returns the range of a 3x3 neighborhood.

Is there any thing similar in Python or OpenCV to help me do the above mentioned task ?

2016-03-30 12:00:59 -0500 commented question HoG Detect MultiScale Detect

Just changed the dimensions, such as winstride, padding and scaling. Code still the same as above.

2016-03-30 11:07:19 -0500 commented question HoG Detect MultiScale Detect

I changed the dimensions. But still no difference.

2016-03-30 05:52:44 -0500 received badge  Editor (source)
2016-03-30 05:49:56 -0500 asked a question HoG Detect MultiScale Detect

I am working on License Plate Detection using HoG. I am now in the testing phase. When I use

hog.detectmultiscale()

to localize the number plate, I get just a single rectangle false positive localization. Below is the code:

hog = cv2.HOGDescriptor((64,64), (16,16), (8,8), (8,8), 9)
svm = cv2.SVM()
svm.load('trained.xml')
img = cv2.imread('6.png', cv2.IMREAD_COLOR)
h = hog.compute(img) 
p = svm.predict(h)
print p
model = pickle.load(open("svm.pickle"))
hog.setSVMDetector(np.array(model)) 
rects, weights= hog.detectMultiScale(img, 1.5, (7,7),(10,10), 1,1)  

for (x, y, w, h) in rects:
   cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
   print x,y,w,h

cv2.imshow('person', img)
cv2.waitKey(0) 
cv2.destroyAllWindows()

image description

Also I get the same points for every image I test.

2016-03-30 05:13:15 -0500 received badge  Enthusiast
2016-03-29 10:21:48 -0500 commented question SVMDetector

OK thanks :-)

2016-03-29 04:36:48 -0500 received badge  Self-Learner (source)
2016-03-27 12:56:08 -0500 asked a question SVMDetector

I am facing problem in the hog.setSVMDetector(). I get the following error:

OpenCV Error: Assertion failed (checkDetectorSize()) in setSVMDetector

I have searched for this problem, and found out the winsize in the input arguments must be the same. I have used the same parameters for both training and testing. However I still get the same error.

Here is the code below:

TESTING

hog = cv2.HOGDescriptor((64,64), (16,16), (8,8), (8,8), 9)
svm = cv2.SVM()
svm.load('trained.xml')

img = cv2.imread('t_.png', cv2.IMREAD_GRAYSCALE)
h = hog.compute(img)
p = svm.predict(h)
print p

model = pickle.load(open("svm.pickle"))
hog.setSVMDetector(np.array(model))

HOG FEATURES COMPUTING METHOD

train_list = []
response_list = []

hog = cv2.HOGDescriptor((64,64), (16,16), (8,8), (8,8), 9)
hog = cv2.HOGDescriptor()
for i in range(2,23):
    img = cv2.imread('/home/taseer/Python/Image_Processing/Project/resized/' + str(i) + "_.png", cv2.IMREAD_COLOR)
    h = hog.compute(img)
    h = h.ravel()
    train_list.append(h)

    if i > 7:
        response_list.append(1)
    else:
        response_list.append(-1)

model = cv2.SVM()
model.train(np.array(train_list), np.array(response_list))
model.save('trained.xml')

I also found that the winsize must be equal to the size of images. I have resized all my images to (150,150).

for i in range(1,17):
    img = Image.open('/home/taseer/Python/Image_Processing/Project/positive/pos/' + str(i) + ".jpg")
    r = img.resize((150,150))
    r.save('/home/taseer/Python/Image_Processing/Project/resized/' + str(i+7) + '_.png')
2016-03-26 23:35:43 -0500 commented question HoG Training Using SVM

I got the answer from the following link:

http://answers.opencv.org/question/56...

2016-03-26 23:05:35 -0500 received badge  Critic (source)
2016-03-26 22:57:51 -0500 asked a question HoG Training Using SVM

I have successfully trained my positive and negative samples of my dataset. However, when I try to use the hog.setSVMDetector(), I get the following error :

_svmdetector data type = 17 is not supported

Here is the code:

hog = cv2.HOGDescriptor()
svm = cv2.SVM()
svm.load('trained.xml')
img = cv2.imread('t_.png', cv2.IMREAD_COLOR)
h = hog.compute(img)
p = svm.predict(h)
print p
hog.setSVMDetector(np.array(svm))
2016-03-26 09:49:55 -0500 asked a question HoG Training using SVM

I have successfully saved the hog features of my positive and negative samples of my data set. However, when I try to get the support vector for setSVMDetector(), get the following error:

'cv2.SVM' object has no attribute 'getSupportVectors'

Here is my code:

hog = cv2.HOGDescriptor() svm = cv2.SVM() svm.load('trained.xml')

img = cv2.imread('t_.png') h = hog.compute(img) p = svm.predict(h) print p

v = svm.getSupportVectors() hog.setSVMDetector(v)

2016-03-26 09:13:44 -0500 received badge  Supporter (source)
2016-03-26 09:13:33 -0500 received badge  Scholar (source)
2016-03-26 02:46:30 -0500 commented answer SVM TRAINING FOR LICENSE PLATE DETECTION

Thank you so very much. It helped a lot !

2016-03-26 01:32:38 -0500 asked a question SVM TRAINING FOR LICENSE PLATE DETECTION

I am currently working on License Plate recognition using custom HoG and SVM. I have the features of my image data set extracted and saved in an xml file. Here is the code:

train_list = []
response_list = []

hog = cv2.HOGDescriptor()

for i in range(2,7):
    img = cv2.imread(str(i) + "_.png")
    h = hog.compute(img)
    train_list.append(h)
    response_list.append(i)

model = cv2.SVM()
x = model.train(np.array(train_list), np.array(response_list))
model.save('trained.xml')

However, when I use SVM predict to classify if a certain image is positive or negative, I get the following error:

Input sample must have 32fC1 type in function cvPreparePredictData

Here is my code for using svm predict method:

img = cv2.imread('2.jpg',cv2.IMREAD_COLOR)
img2 = img.ravel() #conversion to a 1D matrix

svm = cv2.SVM()
svm.load('trained.xml')

svm.predict(img2)

Kindly help me resolve the above error.