Import SVM in cv2 [python]

asked 2018-07-10 12:48:06 -0500

gabes gravatar image

Trying to simply run this project: https://github.com/mjk188/ASL-Translator

Anyone know how to set up SVM stuff inside cv2? I installed openCV 3.1.0 via these instructions: https://www.pyimagesearch.com/2015/06...

Getting this error:

 File "/ASL-Translator/svm_train.py", line 4, in <module>
 svm_params = dict( kernel_type = cv2.SVM_RBF,
 AttributeError: 'module' object has no attribute 'SVM_RBF'

Code giving error from svm_train.py:

import cv2
import numpy as np
from numpy.linalg import norm

svm_params = dict( kernel_type = cv2.SVM_RBF, svm_type = cv2.SVM_C_SVC, C=2.67, gamma=5.383 )

class StatModel(object):
    def load(self, fn):
        self.model.load(fn)  #python rapper bug
    def save(self, fn):
        self.model.save(fn)

class SVM(StatModel):
    def __init__(self, C = 1, gamma = 0.5):
        self.model = cv2.SVM()
        # self.model.setGamma(gamma)
        # self.model.setC(C)
        # self.model.setKernel(cv2.SVM_RBF)
        # self.model.setType(cv2.SVM_C_SVC)

    def train(self, samples, responses):
        self.model.train(samples,  responses,params=svm_params) # inbuilt training function 

    def predict(self, samples):
        return self.model.predict_all(samples).ravel()
edit retag flag offensive close merge delete

Comments

"I installed openCV 3.1.0" -- that's from Dec 21, 2015

berak gravatar imageberak ( 2018-07-10 13:09:02 -0500 )edit

the github repo you're trying with NEVER had a solved issue or a merged pr.

consider this DEAD. (waste of time)

berak gravatar imageberak ( 2018-07-10 13:14:10 -0500 )edit

i did not completely parse it, but what about the letter M and J ?

(did you do even any reasearch about ASL ?)

berak gravatar imageberak ( 2018-07-10 13:16:04 -0500 )edit

Yes I'm aware that not all ASL letters are represented in this project, this is experimental. I'm asking about this error, if you have any idea:

  File "/ASL-Translator/svm_train.py", line 4, in <module>
  svm_params = dict( kernel_type = cv2.SVM_RBF,
  AttributeError: 'module' object has no attribute 'SVM_RBF'
gabes gravatar imagegabes ( 2018-07-10 13:25:52 -0500 )edit

api changed a lot in the meantime. forget about 3.1.0 (outdated, noone sane will help you with that)

try to gasp the idea there, and recode it, using latest 3.4.2. then we can help you. (cv2.ml.something)

please understand, that noone is interested in fixing bugs from the past (or poorly maintained 3rd party repos)

berak gravatar imageberak ( 2018-07-10 13:29:06 -0500 )edit