I am using SVM to predict my ROI, I trained SVM and now in testing phases, it's giving me output with labels in the form of 1 and 0.
I am trying that if SVM predicts 1
mean image contains eyebrow, now I want that it should be rectangle around the eyebrow because the algorithm is predicting based on the eyebrow. How can I do this?
Below is the code I use for prediction.
h_og = cv2.HOGDescriptor()
histogram = h_og.compute(photo)
arr.append(histogram)
arr = np.float32(arr)
result = svm.predict(arr)
Now the result is in the form of number or label. How I can draw a rectangle on that ROI of testing image.
Positive data: image with eyebrows
Negative data: images not containing eyebrow
Testing data: Full face of the person
If I have to use detectMultiScale()
with it how I will use it with the above logic.
Code use for training purpose
sam = []
lab = []
# Get positive samples
for filename in glob.glob('D:\*.png'):
im = cv2.imread(filename, 1)
h_og = cv2.HOGDescriptor()
hist = h_og.compute(im)
sam.append(hist)
lab.append(1)
# Get negative samples
for file in glob.glob('D:\\*.png'):
im = cv2.imread(file, 1)
im = cv2.resize(img, (240, 160))
h_og = cv2.HOGDescriptor()
hist = h_og.compute(im)
sam.append(hist)
lab.append(0)
# Convert objects to Numpy Objects
sam = np.float32(sam)
lab = np.array(lab)
# Shuffle Samples
rand = np.random.RandomState(321)
shuffle = rand.permutation(len(sam))
sam = sam[shuffle]
lab = lab[shuffle]
svm = cv2.ml.SVM_create()
svm.setType(cv2.ml.SVM_C_SVC)
#svm.setKernel(cv2.ml.SVM_RBF)
cv2.ml.SVM_LINEAR
# svm.setDegree(0.0)
svm.setGamma(5.383)
# svm.setCoef0(0.0)
svm.setC(2.67)
# svm.setNu(0.0)
# svm.setP(0.0)
# svm.setClassWeights(None)
svm.train(sam, cv2.ml.ROW_SAMPLE, lab)
svm.save('file.xml')
More Explanation:
If my image contains eyebrow, my SVM prediction is successfully returning me 1
But after that I want it to display that image the below way, the rectangle should be on the coordinates based on which SVM predicts 1
Above image is just a sample image, I am doing it for eyebrow and after prediction, I want to achieve or trying to achieve the output in the above way.