PIL和Numpy格式互转
image = Image.open("xxx.jpg")
array = numpy.array(image)
image2 = Image.fromarray(array)
PIL和OpenCV格式互转
image = Image.open("xxx.jpg")
# mat is a PyOpenCV matrix
mat = pyopencv.Mat.from_pil_image(image)
image2 = mat.to_pil_image()
OpenCV和Numpy格式互转
# cimg is a OpenCV image
cimg = cv.LoadImage("ponzo.jpg", cv.CV_LOAD_IMAGE_COLOR)
# pimg is a PIL image
pimg = Image.fromstring("RGB", cv.GetSize(cimg), cimg.tostring())
# array is a numpy array
array = numpy.array(pimg)
# pimg2 is a OpenCV image
pimg2 = cv.fromarray(array)