在 python 的 opencv 中为 fromarray() 设置类型 [英] Set type for fromarray() in opencv for python

查看:81
本文介绍了在 python 的 opencv 中为 fromarray() 设置类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Python 2.7 和 opencv 2.1.

I am using Python 2.7 and opencv 2.1.

我有一个 numpy 数组,我想将其转换为cv.CV_32FC1"类型的 opencv 矩阵.如何设置类型?

I have a numpy array and I want to convert it to an opencv matrix of type "cv.CV_32FC1". How can I set the type ?

CreateMat()"允许显式类型设置,但fromarray()"不允许.如果我只是在浮点数组上应用 fromarray 类型检查失败(下一个模块之一对 CV_32FC1 执行特定类型检查)

"CreateMat()" allows for explicit type setting but "fromarray()" doesnt. If I just apply fromarray on a float array the type check fails (one of the next modules performs a specific type check for CV_32FC1)

谢谢!

推荐答案

您可以尝试以下操作:

dest = cv.createMat(r, c, cv.CV_32FC1)
src = cv.fromarray(your_np_array)
cv.Convert(src, dest)

你的 numpy 数组有 r 行和 c 列.

where your numpy array has r rows and c columns.

这篇关于在 python 的 opencv 中为 fromarray() 设置类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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