Python OpenCV Box2D [英] Python OpenCV Box2D

查看:92
本文介绍了Python OpenCV Box2D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从python中调用OpenCV函数MinAreaRect2.我将OpenCV 2.4.2与python 2.7和numpy 1.6一起使用.我走了这么远:

I am trying to call OpenCV function MinAreaRect2 from within python. I use OpenCV 2.4.2 with python 2.7 and numpy 1.6. I went this far :

import cv

def nda2ipl(arr, dtype=None):
    return cv.fromarray(np.ascontiguousarray(arr, dtype=dtype))

def min_area_rect2(points):
    storage = cv.CreateMemStorage()
    cv_points = nda2ipl(points.reshape((-1, 1, 2)))
    out = cv.MinAreaRect2(cv_points, storage)
return out

我可以使用形状为(N x 2)的ndarray调用此函数.我得到了这样的结果:

I can call this function with a ndarray of shape (N x 2). I get this kind of results :

((476.5, 604.5), (951.0, 1207.0), -0.0)

我假设第一个元组是盒子的中心,第二个元组是宽度和高度,最后一个是角度.

I assume that the first tuple is the center of the box, the second gives the width and the height and the last is the angle.

问题是我无法获得清晰的参考说明.实际上,opencv文档告诉我这些函数在Python中返回什么.

The problem is I could not get a clear reference stating this. Actually, the opencv documentation tells me what the functions returns in Python.

我找到了关于此功能的官方文档,但这不是很有帮助.

I found the official documentation about this function but this is not very helpful.

MinAreaRect2在python中的确切输出是什么?更一般而言,您在哪里可以获得有关OpenCV python包装器的精确文档?

What are exactly the output of MinAreaRect2 in python ? More generally, where do you get precise documentation about the OpenCV python wrapper ?

推荐答案

OpenCV Python包装器文档与常规文档一起保存在同一站点中, www.docs.opencv.org

OpenCV Python wrapper documentation is kept along with the normal documentation in same site, www.docs.opencv.org

使用的早期Python模块是 cv 接口,该接口使用了来自原始C ++接口的本机数据类型,例如cvMat,cvSeq等.

Earlier Python module used was cv interface, which used native data types from original C++ interface like cvMat, cvSeq etc.

后来,它被转移到了更好,更高级,更简单的模块 cv2 接口.在其中,所有内容均以Numpy数组或本机python数据类型返回.

Later it was shifted to more better, advanced and simpler module cv2 interface. In it, everything is returned as either Numpy arrays or native python data types.

此处,返回的元组与 cvBox2D .您可以在此处找到更多详细信息,以了解不同python包装器之间的区别:

Here, tuple returned has the same arguments as that of cvBox2D. You can find more details the differences between different python wrappers here : What is different between all these OpenCV Python interfaces?

在这里,您的假设是正确的.这些值正好说明了您提到的内容.

Here, your assumption is correct. Those values specified exactly what you mentioned.

如果要绘制旋转的矩形,则需要矩形的4个顶点.为此,您需要一个文档中从未见过的函数,即 cv2.cv.BoxPoints()(但请放心,当OpenCV 2.4.3发行时,它将存在于文档中.)

If you want to draw rotated rect, you need 4 vertices of the rectangle. For that, you need a function which is never seen in documentation, ie cv2.cv.BoxPoints() (but don't worry, it will be there in documentation when OpenCV 2.4.3 is released. )

这篇关于Python OpenCV Box2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆