简体   繁体   English

python中opencv2的矩阵转换

[英]Matrix conversions for opencv2 in python

The lack of documentation on the opencv 2 is a bit hard to work with. 缺少有关opencv 2的文档有点难以使用。 I am trying to use kalman filter to track moving objects. 我正在尝试使用卡尔曼过滤器来跟踪移动的对象。 I looked here for an example, but it uses a version before 2.x: 我在这里看了一个示例,但是它使用的是2.x之前的版本:

https://projects.developer.nokia.com/opencv/browser/opencv/opencv-2.3.1/samples/python/kalman.py https://projects.developer.nokia.com/opencv/browser/opencv/opencv-2.3.1/samples/python/kalman.py

I know that the python bindings for opencv 2 uses numpy matrix. 我知道opencv 2的python绑定使用numpy矩阵。 How does this translate from the old implementation? 这与旧的实现有何不同? For example, in the link, a matrix is created this way: 例如,在链接中,以这种方式创建矩阵:

state = cv.CreateMat(2, 1, cv.CV_32FC1)

But in numpy this doesn't seem correct: 但是在numpy中,这似乎不正确:

state = numpy.zeros(shape=(2,1))

There are examples where one could create a cv Matrix by converting it from numpy, but I wish to use only functions provided by cv2. 在某些示例中,可以通过将其从numpy转换而创建cv Matrix,但我希望仅使用cv2提供的功能。

Also, I cannot find the equivalent of some functions in opencv 2: 另外,我在opencv 2中找不到某些功能的等效项:

cv.RandArr(...)

Is there an equivalent function for RandArr in cv2? 在cv2中, RandArr是否具有等效功能? I don't quite understand how it works, so implementing it myself would take some time. 我不太了解它是如何工作的,所以我自己实施它会花费一些时间。

I am also facing the same problem. 我也面临着同样的问题。 I am unable to use cv2.Kalman() properly. 我无法正确使用cv2.Kalman() But as cv2 and cv are quite compatible, I worked my way around using cv.CreateKalman() . 但是由于cv2和cv完全兼容,因此我使用cv.CreateKalman() I think this might be useful. 我认为这可能有用。 http://jayrambhia.wordpress.com/2012/07/26/kalman-filter/ http://jayrambhia.wordpress.com/2012/07/26/kalman-filter/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM