Ask Your Question

StevenBell's profile - activity

2019-09-02 18:59:02 -0600 received badge  Famous Question (source)
2019-05-25 05:02:33 -0600 received badge  Taxonomist
2016-10-16 20:14:59 -0600 received badge  Notable Question (source)
2016-08-15 04:07:15 -0600 received badge  Famous Question (source)
2015-08-30 10:10:32 -0600 received badge  Good Answer (source)
2015-07-09 11:18:28 -0600 received badge  Nice Question (source)
2015-05-24 09:58:34 -0600 received badge  Popular Question (source)
2015-05-08 03:49:17 -0600 received badge  Notable Question (source)
2014-11-19 13:28:52 -0600 received badge  Nice Answer (source)
2014-09-12 08:45:18 -0600 received badge  Popular Question (source)
2013-06-24 19:59:24 -0600 received badge  Teacher (source)
2013-01-04 18:22:48 -0600 received badge  Supporter (source)
2013-01-04 18:22:36 -0600 commented answer Save SVM in Python

Thanks, I was clearly thinking too hard to notice the save() and load() methods right in front of me!

2013-01-04 18:21:54 -0600 received badge  Scholar (source)
2013-01-04 16:39:38 -0600 asked a question Save SVM in Python

I'm using Python to train an SVM, and I'd like to save the resulting model for use later. However, I get an error:

TypeError: can't pickle SVM objects

Is there another persistence method I should use? Is there something that I could add to the Python SVM module to make it pickle-able?

Minimal working code is below:

import numpy as np
import cv2
import pickle

points = np.array([[1.0, 2.1], [1, -1], [2, 3], [2, 1]], dtype=np.float32)
labels = np.array([0, 1, 0, 1], dtype=np.float32)

model = cv2.SVM(points, labels)
pickle.dump(model, open("save.pkl", 'w'))
2013-01-04 16:27:14 -0600 commented question Many CvSVM vectors into one... how?

What do you mean by "n vectors from the SVM"? Training an SVM should give you a single model.

2012-10-31 07:23:46 -0600 received badge  Self-Learner (source)
2012-10-31 07:06:27 -0600 received badge  Student (source)
2012-07-11 11:58:00 -0600 answered a question cv2.perspectiveTransform() with Python

Found the solution in the find_obj.py sample. The catch is that the C++ code is expecting a "two-channel or three-channel floating-point array, where each element is a 2D/3D vector", which translates in Python/NumPy to a 3-dimensional array.

import cv2
import numpy as np

a = np.array([[1, 2], [4, 5], [7, 8]], dtype='float32')
h = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype='float32')
a = np.array([a])

pointsOut = cv2.perspectiveTransform(a, h)
2012-07-11 11:40:15 -0600 asked a question cv2.perspectiveTransform() with Python

I am attempting to use the perspectiveTransform() function in Python to warp a set of points:

import cv2
import numpy as np

a = np.array([[1, 2], [4, 5], [7, 8]], dtype='float32')
h = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype='float32')
pointsOut = cv2.perspectiveTransform(a, h)

However, all I get is an error:

cv2.error: /build/buildd/opencv-2.3.1/modules/core/src/matmul.cpp:1916:
error: (-215) scn + 1 == m.cols && (depth == CV_32F || depth == CV_64F)
in function perspectiveTransform

I assume I'm passing the arrays in the wrong format somehow, but I've tried quite a few different combinations of array shapes and data types with no success. What's the right way to do this?