OpenCV:在Python中从NumPy转换为IplImage [英] OpenCV: Converting from NumPy to IplImage in Python

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

问题描述

我有一个使用cv2.imread()加载的图像.这将返回一个NumPy数组.但是,我需要将其传递给需要IplImage格式数据的第三方API.

I have an image that I load using cv2.imread(). This returns an NumPy array. However, I need to pass this into a 3rd party API that requires the data in IplImage format.

我已经尽了一切可能,并找到了从IplImage转换为CvMat的实例,并且找到了一些有关C ++转换的参考,但没有找到从Python的NumPy转换为IplImage的参考.是否提供可以执行此转换的功能?

I've scoured everything I could and I've found instances of converting from IplImage to CvMat,and I've found some references to converting in C++, but not from NumPy to IplImage in Python. Is there a function that is provided that can do this conversion?

推荐答案

您可以这样做.

source = cv2.imread() # source is numpy array 
bitmap = cv.CreateImageHeader((source.shape[1], source.shape[0]), cv.IPL_DEPTH_8U, 3)
cv.SetData(bitmap, source.tostring(), 
           source.dtype.itemsize * 3 * source.shape[1])

bitmap这里是cv2.cv.iplimage

这篇关于OpenCV:在Python中从NumPy转换为IplImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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