OpenCV: Converting from NumPy to IplImage in Python

后端 未结 2 1992
甜味超标
甜味超标 2020-12-30 12:33

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.

相关标签:
2条回答
  • 2020-12-30 12:51

    2-way to apply:

    1. img = cv2.imread(img_path) img_buf = cv2.imencode('.jpg', img)[1].tostring()

    2. just read the image file: img_buf = open(img_path, 'rb').read()

    0 讨论(0)
  • 2020-12-30 13:09

    You can do like this.

    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 here is cv2.cv.iplimage

    0 讨论(0)
提交回复
热议问题