import numpy as np
import cv
foo_np = np.array(255 * np.random.rand(200, 300, 3), dtype='uint8')
foo_np_view = foo_np[50:150:2, 10:290:5, :]
h, w, d = foo_np_view.shape
foo_cv = cv.CreateMat(h, w, cv.CV_8UC3)
How to convert a numpy array view to opencv matrix?